Interpreter + async mode

This commit is contained in:
tevador
2019-01-15 00:01:11 +01:00
parent a7ffe8c19a
commit 8b1102ee05
18 changed files with 702 additions and 215 deletions
+1 -55
View File
@@ -19,8 +19,6 @@ along with RandomX. If not, see<http://www.gnu.org/licenses/>.
#include "VirtualMachine.hpp"
#include "common.hpp"
#include "dataset.hpp"
#include "Cache.hpp"
#include "t1ha/t1ha.h"
#include "blake2/blake2.h"
#include <cstring>
@@ -37,62 +35,10 @@ std::ostream& operator<<(std::ostream& os, const RandomX::RegisterFile& rf) {
namespace RandomX {
VirtualMachine::VirtualMachine(bool softAes) : softAes(softAes), lightClient(false) {
VirtualMachine::VirtualMachine() {
mem.ds.dataset = nullptr;
}
VirtualMachine::~VirtualMachine() {
if (lightClient) {
delete mem.ds.lightDataset->block;
delete mem.ds.lightDataset;
}
}
void VirtualMachine::setDataset(dataset_t ds, bool light) {
if (mem.ds.dataset != nullptr) {
throw std::runtime_error("Dataset is already initialized");
}
lightClient = light;
if (light) {
auto lds = mem.ds.lightDataset = new LightClientDataset();
lds->cache = ds.cache;
//lds->block = (uint8_t*)_mm_malloc(DatasetBlockSize, sizeof(__m128i));
lds->blockNumber = -1;
if (lds->block == nullptr) {
throw std::bad_alloc();
}
if (softAes) {
readDataset = &datasetReadLight<true>;
}
else {
readDataset = &datasetReadLight<false>;
}
}
else {
mem.ds = ds;
readDataset = &datasetRead;
}
}
void VirtualMachine::initializeScratchpad(uint32_t index) {
if (lightClient) {
auto cache = mem.ds.lightDataset->cache;
if (softAes) {
for (int i = 0; i < ScratchpadSize / CacheLineSize; ++i) {
initBlock<true>(cache->getCache(), ((uint8_t*)scratchpad) + CacheLineSize * i, (ScratchpadSize / CacheLineSize) * index + i, cache->getKeys());
}
}
else {
for (int i = 0; i < ScratchpadSize / CacheLineSize; ++i) {
initBlock<false>(cache->getCache(), ((uint8_t*)scratchpad) + CacheLineSize * i, (ScratchpadSize / CacheLineSize) * index + i, cache->getKeys());
}
}
}
else {
memcpy(scratchpad, mem.ds.dataset + ScratchpadSize * index, ScratchpadSize);
}
}
void VirtualMachine::getResult(void* out) {
constexpr size_t smallStateLength = sizeof(RegisterFile) / sizeof(uint64_t) + 2;
uint64_t smallState[smallStateLength];