From 52aa36249e679e787ffe8b3abbb7edc7dcb899ea Mon Sep 17 00:00:00 2001 From: tevador <37503146+tevador@users.noreply.github.com> Date: Mon, 10 Jun 2019 16:00:04 +0200 Subject: [PATCH] Add Dataset prefetch in interpreted VM (#52) - to formally match the specification - a small increase in interpreted mining speed (~4%) --- src/vm_interpreted.cpp | 6 ++++++ src/vm_interpreted.hpp | 1 + src/vm_interpreted_light.hpp | 1 + 3 files changed, 8 insertions(+) diff --git a/src/vm_interpreted.cpp b/src/vm_interpreted.cpp index 25dc466..dd5f217 100644 --- a/src/vm_interpreted.cpp +++ b/src/vm_interpreted.cpp @@ -246,6 +246,7 @@ namespace randomx { mem.mx ^= r[config.readReg2] ^ r[config.readReg3]; mem.mx &= CacheLineAlignMask; + datasetPrefetch(datasetOffset + mem.mx); datasetRead(datasetOffset + mem.ma, r); std::swap(mem.mx, mem.ma); @@ -279,6 +280,11 @@ namespace randomx { r[i] ^= datasetLine[i]; } + template + void InterpretedVm::datasetPrefetch(uint64_t address) { + rx_prefetch_nta(mem.memory + address); + } + #include "instruction_weights.hpp" template diff --git a/src/vm_interpreted.hpp b/src/vm_interpreted.hpp index 9fb137c..dfa1ba7 100644 --- a/src/vm_interpreted.hpp +++ b/src/vm_interpreted.hpp @@ -81,6 +81,7 @@ namespace randomx { void setDataset(randomx_dataset* dataset) override; protected: virtual void datasetRead(uint64_t blockNumber, int_reg_t(&r)[RegistersCount]); + virtual void datasetPrefetch(uint64_t blockNumber); private: void execute(); void precompileProgram(int_reg_t(&r)[RegistersCount], rx_vec_f128(&f)[RegisterCountFlt], rx_vec_f128(&e)[RegisterCountFlt], rx_vec_f128(&a)[RegisterCountFlt]); diff --git a/src/vm_interpreted_light.hpp b/src/vm_interpreted_light.hpp index f3cc2c6..02d678f 100644 --- a/src/vm_interpreted_light.hpp +++ b/src/vm_interpreted_light.hpp @@ -51,6 +51,7 @@ namespace randomx { void setCache(randomx_cache* cache) override; protected: void datasetRead(uint64_t address, int_reg_t(&r)[8]) override; + void datasetPrefetch(uint64_t address) override { } }; using InterpretedLightVmDefault = InterpretedLightVm, true>;