Restored software AES support

This commit is contained in:
tevador 2019-02-13 22:46:32 +01:00
parent f76e8c2e20
commit 1df975e583
3 changed files with 15 additions and 26 deletions

View File

@ -117,19 +117,12 @@ namespace RandomX {
} }
} }
template<bool softAes>
void datasetInit(Cache* cache, dataset_t ds, uint32_t startBlock, uint32_t blockCount) { void datasetInit(Cache* cache, dataset_t ds, uint32_t startBlock, uint32_t blockCount) {
for (uint32_t i = startBlock; i < startBlock + blockCount; ++i) { for (uint32_t i = startBlock; i < startBlock + blockCount; ++i) {
initBlock(cache->getCache(), ds.dataset + i * CacheLineSize, i, cache->getKeys()); initBlock(cache->getCache(), ds.dataset + i * CacheLineSize, i, cache->getKeys());
} }
} }
template
void datasetInit<false>(Cache*, dataset_t, uint32_t, uint32_t);
template
void datasetInit<true>(Cache*, dataset_t, uint32_t, uint32_t);
template<bool softAes> template<bool softAes>
void datasetInitCache(const void* seed, dataset_t& ds, bool largePages) { void datasetInitCache(const void* seed, dataset_t& ds, bool largePages) {
ds.cache = new(Cache::alloc(largePages)) Cache(); ds.cache = new(Cache::alloc(largePages)) Cache();

View File

@ -35,7 +35,6 @@ namespace RandomX {
void datasetAlloc(dataset_t& ds, bool largePages); void datasetAlloc(dataset_t& ds, bool largePages);
template<bool softAes>
void datasetInit(Cache* cache, dataset_t ds, uint32_t startBlock, uint32_t blockCount); void datasetInit(Cache* cache, dataset_t ds, uint32_t startBlock, uint32_t blockCount);
void datasetRead(addr_t addr, MemoryRegisters& memory, RegisterFile&); void datasetRead(addr_t addr, MemoryRegisters& memory, RegisterFile&);

View File

@ -153,6 +153,7 @@ void generateNative(int nonce) {
std::cout << prog << std::endl; std::cout << prog << std::endl;
} }
template<bool softAes>
void mine(RandomX::VirtualMachine* vm, std::atomic<int>& atomicNonce, AtomicHash& result, int noncesCount, int thread, uint8_t* scratchpad) { void mine(RandomX::VirtualMachine* vm, std::atomic<int>& atomicNonce, AtomicHash& result, int noncesCount, int thread, uint8_t* scratchpad) {
alignas(16) uint64_t hash[8]; alignas(16) uint64_t hash[8];
uint8_t blockTemplate[sizeof(blockTemplate__)]; uint8_t blockTemplate[sizeof(blockTemplate__)];
@ -164,19 +165,19 @@ void mine(RandomX::VirtualMachine* vm, std::atomic<int>& atomicNonce, AtomicHash
//std::cout << "Thread " << thread << " nonce " << nonce << std::endl; //std::cout << "Thread " << thread << " nonce " << nonce << std::endl;
*noncePtr = nonce; *noncePtr = nonce;
blake2b(hash, sizeof(hash), blockTemplate, sizeof(blockTemplate), nullptr, 0); blake2b(hash, sizeof(hash), blockTemplate, sizeof(blockTemplate), nullptr, 0);
fillAes1Rx4<false>((void*)hash, RandomX::ScratchpadSize, scratchpad); fillAes1Rx4<softAes>((void*)hash, RandomX::ScratchpadSize, scratchpad);
vm->setScratchpad(scratchpad); vm->setScratchpad(scratchpad);
//dump((char*)((RandomX::CompiledVirtualMachine*)vm)->getProgram(), RandomX::CodeSize, "code-1337-jmp.txt"); //dump((char*)((RandomX::CompiledVirtualMachine*)vm)->getProgram(), RandomX::CodeSize, "code-1337-jmp.txt");
for (int chain = 0; chain < RandomX::ChainLength - 1; ++chain) { for (int chain = 0; chain < RandomX::ChainLength - 1; ++chain) {
fillAes1Rx4<false>((void*)hash, sizeof(RandomX::Program), vm->getProgramBuffer()); fillAes1Rx4<softAes>((void*)hash, sizeof(RandomX::Program), vm->getProgramBuffer());
vm->initialize(); vm->initialize();
vm->execute(); vm->execute();
vm->getResult<false>(nullptr, 0, hash); vm->getResult<false>(nullptr, 0, hash);
} }
fillAes1Rx4<false>((void*)hash, sizeof(RandomX::Program), vm->getProgramBuffer()); fillAes1Rx4<softAes>((void*)hash, sizeof(RandomX::Program), vm->getProgramBuffer());
vm->initialize(); vm->initialize();
vm->execute(); vm->execute();
vm->getResult<false>(scratchpad, RandomX::ScratchpadSize, hash); vm->getResult<softAes>(scratchpad, RandomX::ScratchpadSize, hash);
result.xorWith(hash); result.xorWith(hash);
if (RandomX::trace) { if (RandomX::trace) {
std::cout << "Nonce: " << nonce << " "; std::cout << "Nonce: " << nonce << " ";
@ -257,24 +258,14 @@ int main(int argc, char** argv) {
auto remainder = RandomX::DatasetBlockCount % threadCount; auto remainder = RandomX::DatasetBlockCount % threadCount;
for (int i = 0; i < threadCount; ++i) { for (int i = 0; i < threadCount; ++i) {
auto count = perThread + (i == threadCount - 1 ? remainder : 0); auto count = perThread + (i == threadCount - 1 ? remainder : 0);
if (softAes) { threads.push_back(std::thread(&RandomX::datasetInit, cache, dataset, i * perThread, count));
threads.push_back(std::thread(&RandomX::datasetInit<true>, cache, dataset, i * perThread, count));
}
else {
threads.push_back(std::thread(&RandomX::datasetInit<false>, cache, dataset, i * perThread, count));
}
} }
for (unsigned i = 0; i < threads.size(); ++i) { for (unsigned i = 0; i < threads.size(); ++i) {
threads[i].join(); threads[i].join();
} }
} }
else { else {
if (softAes) { RandomX::datasetInit(cache, dataset, 0, RandomX::DatasetBlockCount);
RandomX::datasetInit<true>(cache, dataset, 0, RandomX::DatasetBlockCount);
}
else {
RandomX::datasetInit<false>(cache, dataset, 0, RandomX::DatasetBlockCount);
}
} }
RandomX::Cache::dealloc(cache, largePages); RandomX::Cache::dealloc(cache, largePages);
threads.clear(); threads.clear();
@ -303,14 +294,20 @@ int main(int argc, char** argv) {
sw.restart(); sw.restart();
if (threadCount > 1) { if (threadCount > 1) {
for (unsigned i = 0; i < vms.size(); ++i) { 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<true>, vms[i], std::ref(atomicNonce), std::ref(result), programCount, i, scratchpadMem + RandomX::ScratchpadSize * i));
else
threads.push_back(std::thread(&mine<false>, vms[i], std::ref(atomicNonce), std::ref(result), programCount, i, scratchpadMem + RandomX::ScratchpadSize * i));
} }
for (unsigned i = 0; i < threads.size(); ++i) { for (unsigned i = 0; i < threads.size(); ++i) {
threads[i].join(); threads[i].join();
} }
} }
else { else {
mine(vms[0], std::ref(atomicNonce), std::ref(result), programCount, 0, scratchpadMem); if(softAes)
mine<true>(vms[0], std::ref(atomicNonce), std::ref(result), programCount, 0, scratchpadMem);
else
mine<false>(vms[0], std::ref(atomicNonce), std::ref(result), programCount, 0, scratchpadMem);
if (miningMode) if (miningMode)
std::cout << "Average program size: " << ((RandomX::CompiledVirtualMachine*)vms[0])->getTotalSize() / programCount / RandomX::ChainLength << std::endl; std::cout << "Average program size: " << ((RandomX::CompiledVirtualMachine*)vms[0])->getTotalSize() / programCount / RandomX::ChainLength << std::endl;
} }