From 1df975e583eeded31fc67f1ed4312f2df3971636 Mon Sep 17 00:00:00 2001 From: tevador Date: Wed, 13 Feb 2019 22:46:32 +0100 Subject: [PATCH] Restored software AES support --- src/dataset.cpp | 7 ------- src/dataset.hpp | 1 - src/main.cpp | 33 +++++++++++++++------------------ 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/src/dataset.cpp b/src/dataset.cpp index 5b618f9..4a6a5e6 100644 --- a/src/dataset.cpp +++ b/src/dataset.cpp @@ -117,19 +117,12 @@ namespace RandomX { } } - template void datasetInit(Cache* cache, dataset_t ds, uint32_t startBlock, uint32_t blockCount) { for (uint32_t i = startBlock; i < startBlock + blockCount; ++i) { initBlock(cache->getCache(), ds.dataset + i * CacheLineSize, i, cache->getKeys()); } } - template - void datasetInit(Cache*, dataset_t, uint32_t, uint32_t); - - template - void datasetInit(Cache*, dataset_t, uint32_t, uint32_t); - template void datasetInitCache(const void* seed, dataset_t& ds, bool largePages) { ds.cache = new(Cache::alloc(largePages)) Cache(); diff --git a/src/dataset.hpp b/src/dataset.hpp index 77a477d..9438173 100644 --- a/src/dataset.hpp +++ b/src/dataset.hpp @@ -35,7 +35,6 @@ namespace RandomX { void datasetAlloc(dataset_t& ds, bool largePages); - template void datasetInit(Cache* cache, dataset_t ds, uint32_t startBlock, uint32_t blockCount); void datasetRead(addr_t addr, MemoryRegisters& memory, RegisterFile&); diff --git a/src/main.cpp b/src/main.cpp index 5ae9f8b..552675f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -153,6 +153,7 @@ void generateNative(int nonce) { std::cout << prog << std::endl; } +template void mine(RandomX::VirtualMachine* vm, std::atomic& atomicNonce, AtomicHash& result, int noncesCount, int thread, uint8_t* scratchpad) { alignas(16) uint64_t hash[8]; uint8_t blockTemplate[sizeof(blockTemplate__)]; @@ -164,19 +165,19 @@ void mine(RandomX::VirtualMachine* vm, std::atomic& atomicNonce, AtomicHash //std::cout << "Thread " << thread << " nonce " << nonce << std::endl; *noncePtr = nonce; blake2b(hash, sizeof(hash), blockTemplate, sizeof(blockTemplate), nullptr, 0); - fillAes1Rx4((void*)hash, RandomX::ScratchpadSize, scratchpad); + fillAes1Rx4((void*)hash, RandomX::ScratchpadSize, scratchpad); vm->setScratchpad(scratchpad); //dump((char*)((RandomX::CompiledVirtualMachine*)vm)->getProgram(), RandomX::CodeSize, "code-1337-jmp.txt"); for (int chain = 0; chain < RandomX::ChainLength - 1; ++chain) { - fillAes1Rx4((void*)hash, sizeof(RandomX::Program), vm->getProgramBuffer()); + fillAes1Rx4((void*)hash, sizeof(RandomX::Program), vm->getProgramBuffer()); vm->initialize(); vm->execute(); vm->getResult(nullptr, 0, hash); } - fillAes1Rx4((void*)hash, sizeof(RandomX::Program), vm->getProgramBuffer()); + fillAes1Rx4((void*)hash, sizeof(RandomX::Program), vm->getProgramBuffer()); vm->initialize(); vm->execute(); - vm->getResult(scratchpad, RandomX::ScratchpadSize, hash); + vm->getResult(scratchpad, RandomX::ScratchpadSize, hash); result.xorWith(hash); if (RandomX::trace) { std::cout << "Nonce: " << nonce << " "; @@ -257,24 +258,14 @@ int main(int argc, char** argv) { auto remainder = RandomX::DatasetBlockCount % threadCount; for (int i = 0; i < threadCount; ++i) { auto count = perThread + (i == threadCount - 1 ? remainder : 0); - if (softAes) { - threads.push_back(std::thread(&RandomX::datasetInit, cache, dataset, i * perThread, count)); - } - else { - threads.push_back(std::thread(&RandomX::datasetInit, cache, dataset, i * perThread, count)); - } + threads.push_back(std::thread(&RandomX::datasetInit, cache, dataset, i * perThread, count)); } for (unsigned i = 0; i < threads.size(); ++i) { threads[i].join(); } } else { - if (softAes) { - RandomX::datasetInit(cache, dataset, 0, RandomX::DatasetBlockCount); - } - else { - RandomX::datasetInit(cache, dataset, 0, RandomX::DatasetBlockCount); - } + RandomX::datasetInit(cache, dataset, 0, RandomX::DatasetBlockCount); } RandomX::Cache::dealloc(cache, largePages); threads.clear(); @@ -303,14 +294,20 @@ int main(int argc, char** argv) { sw.restart(); if (threadCount > 1) { for (unsigned i = 0; i < vms.size(); ++i) { - threads.push_back(std::thread(&mine, vms[i], std::ref(atomicNonce), std::ref(result), programCount, i, scratchpadMem + RandomX::ScratchpadSize * i)); + if (softAes) + threads.push_back(std::thread(&mine, vms[i], std::ref(atomicNonce), std::ref(result), programCount, i, scratchpadMem + RandomX::ScratchpadSize * i)); + else + threads.push_back(std::thread(&mine, vms[i], std::ref(atomicNonce), std::ref(result), programCount, i, scratchpadMem + RandomX::ScratchpadSize * i)); } for (unsigned i = 0; i < threads.size(); ++i) { threads[i].join(); } } else { - mine(vms[0], std::ref(atomicNonce), std::ref(result), programCount, 0, scratchpadMem); + if(softAes) + mine(vms[0], std::ref(atomicNonce), std::ref(result), programCount, 0, scratchpadMem); + else + mine(vms[0], std::ref(atomicNonce), std::ref(result), programCount, 0, scratchpadMem); if (miningMode) std::cout << "Average program size: " << ((RandomX::CompiledVirtualMachine*)vms[0])->getTotalSize() / programCount / RandomX::ChainLength << std::endl; }