2018-12-13 22:11:55 +00: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 "Pcg32.hpp"
|
|
|
|
#include "common.hpp"
|
|
|
|
#include "instructions.hpp"
|
2018-12-18 21:00:58 +00:00
|
|
|
#include <stdexcept>
|
2018-12-13 22:11:55 +00:00
|
|
|
|
|
|
|
namespace RandomX {
|
|
|
|
|
2018-12-18 21:00:58 +00:00
|
|
|
CompiledVirtualMachine::CompiledVirtualMachine(bool softAes) : VirtualMachine(softAes) {
|
2019-01-12 15:05:09 +00:00
|
|
|
totalSize = 0;
|
2018-12-18 21:00:58 +00:00
|
|
|
}
|
|
|
|
|
2018-12-19 20:54:44 +00:00
|
|
|
void CompiledVirtualMachine::setDataset(dataset_t ds, bool lightClient) {
|
2018-12-18 21:00:58 +00:00
|
|
|
if (lightClient) {
|
|
|
|
throw std::runtime_error("Compiled VM does not support light-client mode");
|
|
|
|
}
|
2018-12-19 20:54:44 +00:00
|
|
|
VirtualMachine::setDataset(ds, lightClient);
|
2018-12-18 21:00:58 +00:00
|
|
|
}
|
|
|
|
|
2018-12-13 22:11:55 +00:00
|
|
|
void CompiledVirtualMachine::initializeProgram(const void* seed) {
|
|
|
|
Pcg32 gen(seed);
|
|
|
|
for (unsigned i = 0; i < sizeof(reg) / sizeof(Pcg32::result_type); ++i) {
|
|
|
|
*(((uint32_t*)®) + i) = gen();
|
|
|
|
}
|
2018-12-18 21:00:58 +00:00
|
|
|
compiler.generateProgram(gen);
|
2018-12-13 22:11:55 +00:00
|
|
|
mem.ma = (gen() ^ *(((uint32_t*)seed) + 4)) & ~7;
|
|
|
|
mem.mx = *(((uint32_t*)seed) + 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompiledVirtualMachine::execute() {
|
2019-01-10 21:04:55 +00:00
|
|
|
//executeProgram(reg, mem, scratchpad, readDataset);
|
2019-01-12 15:05:09 +00:00
|
|
|
totalSize += compiler.getCodeSize();
|
2019-01-10 21:04:55 +00:00
|
|
|
compiler.getProgramFunc()(reg, mem, scratchpad);
|
2018-12-31 18:06:45 +00:00
|
|
|
#ifdef TRACEVM
|
2018-12-15 22:13:17 +00:00
|
|
|
for (int32_t i = InstructionCount - 1; i >= 0; --i) {
|
|
|
|
std::cout << std::hex << tracepad[i].u64 << std::endl;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
}
|