2018-12-13 23:11:55 +01:00
|
|
|
/*
|
|
|
|
Copyright (c) 2018 tevador
|
|
|
|
|
|
|
|
This file is part of RandomX.
|
|
|
|
|
|
|
|
RandomX is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
RandomX is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with RandomX. If not, see<http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "CompiledVirtualMachine.hpp"
|
|
|
|
#include "common.hpp"
|
2018-12-18 22:00:58 +01:00
|
|
|
#include <stdexcept>
|
2018-12-13 23:11:55 +01:00
|
|
|
|
|
|
|
namespace RandomX {
|
|
|
|
|
2019-03-10 23:14:03 +01:00
|
|
|
//static_assert(sizeof(MemoryRegisters) == 2 * sizeof(addr_t) + sizeof(uintptr_t), "Invalid alignment of struct RandomX::MemoryRegisters");
|
2019-03-08 15:34:34 +01:00
|
|
|
static_assert(sizeof(RegisterFile) == 256, "Invalid alignment of struct RandomX::RegisterFile");
|
|
|
|
|
2019-01-15 00:01:11 +01:00
|
|
|
CompiledVirtualMachine::CompiledVirtualMachine() {
|
2018-12-18 22:00:58 +01:00
|
|
|
}
|
|
|
|
|
2019-04-07 15:38:51 +02:00
|
|
|
void CompiledVirtualMachine::setDataset(dataset_t ds, uint64_t size, LightProgram(&programs)[RANDOMX_CACHE_ACCESSES]) {
|
2019-01-15 00:01:11 +01:00
|
|
|
mem.ds = ds;
|
2019-03-10 23:14:03 +01:00
|
|
|
datasetRange = (size - RANDOMX_DATASET_SIZE + CacheLineSize) / CacheLineSize;
|
|
|
|
datasetBasePtr = ds.dataset.memory;
|
2019-01-15 00:01:11 +01:00
|
|
|
}
|
|
|
|
|
2019-02-09 15:45:26 +01:00
|
|
|
void CompiledVirtualMachine::initialize() {
|
|
|
|
VirtualMachine::initialize();
|
|
|
|
compiler.generateProgram(program);
|
2019-03-10 23:14:03 +01:00
|
|
|
mem.ds.dataset.memory = datasetBasePtr + (datasetBase * CacheLineSize);
|
2018-12-13 23:11:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CompiledVirtualMachine::execute() {
|
2019-01-27 10:52:30 +01:00
|
|
|
//executeProgram(reg, mem, scratchpad, InstructionCount);
|
2019-03-08 15:34:34 +01:00
|
|
|
compiler.getProgramFunc()(reg, mem, scratchpad, RANDOMX_PROGRAM_ITERATIONS);
|
2018-12-31 19:06:45 +01:00
|
|
|
#ifdef TRACEVM
|
2018-12-15 23:13:17 +01:00
|
|
|
for (int32_t i = InstructionCount - 1; i >= 0; --i) {
|
|
|
|
std::cout << std::hex << tracepad[i].u64 << std::endl;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-12-13 23:11:55 +01:00
|
|
|
}
|
|
|
|
}
|