From e22bab9baed2ae0d7cf132c7271af6dad86f5816 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Sat, 25 May 2019 15:54:32 +0800 Subject: [PATCH] asm x86 added --- src/page.h | 40 ++++++++++++++++++++++++++++---------- src/templates/randomx.html | 33 ++++++++++++++++++++++++------- 2 files changed, 56 insertions(+), 17 deletions(-) diff --git a/src/page.h b/src/page.h index 75485d5..a662cfb 100644 --- a/src/page.h +++ b/src/page.h @@ -16,6 +16,7 @@ #include "virtual_machine.hpp" #include "program.hpp" #include "aes_hash.hpp" +#include "assembly_generator_x86.hpp" #include "../gen/version.h" @@ -1440,7 +1441,7 @@ show_randomx(uint64_t _blk_height) string blk_hash_str = pod_to_hex(blk_hash); - vector rx_code = get_randomx_code(_blk_height, + auto rx_code = get_randomx_code(_blk_height, blk, blk_hash); mstch::array rx_code_str = mstch::array{}; @@ -1451,7 +1452,8 @@ show_randomx(uint64_t _blk_height) rx_code_str.push_back( mstch::map { {"rx_code_idx", code_idx++}, - {"rx_code", std::move(rxc)} + {"rx_code", std::move(rxc.first)}, + {"rx_code_asm", std::move(rxc.second)} }); } @@ -7179,12 +7181,12 @@ get_tx(string const& tx_hash_str, return true; } -vector +vector> get_randomx_code(uint64_t blk_height, block const& blk, crypto::hash const& blk_hash) { - vector rx_code; + vector> rx_code; uint64_t seed_height; @@ -7220,6 +7222,8 @@ get_randomx_code(uint64_t blk_height, rx_vm->initScratchpad(&tempHash); rx_vm->resetRoundingMode(); + randomx::Program prg; + for (int chain = 0; chain < RANDOMX_PROGRAM_COUNT - 1; ++chain) { rx_vm->run(&tempHash); @@ -7227,15 +7231,31 @@ get_randomx_code(uint64_t blk_height, rx_vm->getRegisterFile(), sizeof(randomx::RegisterFile), nullptr, 0); - stringstream ss; - ss << rx_vm->getProgram(); - rx_code.push_back(ss.str()); + prg = *(rx_vm->getProgram()); + + stringstream ss, ss2; + ss << prg; + + + randomx::AssemblyGeneratorX86 asmX86; + asmX86.generateProgram(prg); + asmX86.printCode(ss2); + + rx_code.emplace_back(ss.str(), ss2.str()); } rx_vm->run(&tempHash); - stringstream ss; - ss << rx_vm->getProgram(); - rx_code.push_back(ss.str()); + + prg = *(rx_vm->getProgram()); + + stringstream ss, ss2; + ss << prg; + + randomx::AssemblyGeneratorX86 asmX86; + asmX86.generateProgram(prg); + asmX86.printCode(ss2); + + rx_code.emplace_back(ss.str(), ss2.str()); crypto::hash res2; rx_vm->getFinalResult(res2.data, RANDOMX_HASH_SIZE); diff --git a/src/templates/randomx.html b/src/templates/randomx.html index 28fbb99..b21193c 100644 --- a/src/templates/randomx.html +++ b/src/templates/randomx.html @@ -2,14 +2,33 @@

Block hash (height): {{blk_hash}} ({{blk_height}})

-

Recalculated {{pow}}

+

+ Eight RandomX and correspoding assembly x86 programs used + to calcualte PoW hash of the block +

-

RandomX source code

-
- {{#rx_codes}} -

Source code #{{rx_code_idx}}

+ {{#rx_codes}} +

Program #{{rx_code_idx}}

+ + + + + + + + + + + + +
RandomX codeASM x86
{{rx_code}}
- {{/rx_codes}} - +
+
{{rx_code_asm}}
+
+ {{/rx_codes}} + + +