From ffa67295c44b48892255192dcf8be5840babffa7 Mon Sep 17 00:00:00 2001 From: tevador Date: Thu, 20 Dec 2018 22:42:47 +0100 Subject: [PATCH] Instruction statistics --- src/InterpretedVirtualMachine.cpp | 33 +++++++++++++++++++++++++- src/InterpretedVirtualMachine.hpp | 39 ++++++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/src/InterpretedVirtualMachine.cpp b/src/InterpretedVirtualMachine.cpp index a0c285f..6a46f83 100644 --- a/src/InterpretedVirtualMachine.cpp +++ b/src/InterpretedVirtualMachine.cpp @@ -205,10 +205,17 @@ namespace RandomX { } \ } +#ifdef STATS +#define INC_COUNT(x) count_##x++; +#else +#define INC_COUNT(x) +#endif + #define FPU_RETIRE_NB(x) x(a, b, c); \ if(trace) std::cout << std::hex << /*a.u64 << " " <<*/ c.u64 << std::endl; #define ALU_INST(x) void InterpretedVirtualMachine::h_##x(Instruction& inst) { \ + INC_COUNT(x) \ convertible_t a = loada(inst); \ convertible_t b = loadbr1(inst); \ convertible_t& c = getcr(inst); \ @@ -216,6 +223,7 @@ namespace RandomX { } #define ALU_INST_SR(x) void InterpretedVirtualMachine::h_##x(Instruction& inst) { \ + INC_COUNT(x) \ convertible_t a = loada(inst); \ convertible_t b = loadbr0(inst); \ convertible_t& c = getcr(inst); \ @@ -223,6 +231,7 @@ namespace RandomX { } #define FPU_INST(x) void InterpretedVirtualMachine::h_##x(Instruction& inst) { \ + INC_COUNT(x) \ convertible_t a = loada(inst); \ double b = loadbf(inst); \ convertible_t& c = getcf(inst); \ @@ -230,6 +239,7 @@ namespace RandomX { } #define FPU_INST_NB(x) void InterpretedVirtualMachine::h_##x(Instruction& inst) { \ + INC_COUNT(x) \ convertible_t a = loada(inst); \ convertible_t b; \ convertible_t& c = getcf(inst); \ @@ -271,8 +281,13 @@ namespace RandomX { void InterpretedVirtualMachine::h_CALL(Instruction& inst) { convertible_t a = loada(inst); convertible_t b = loadbr1(inst); - convertible_t& c = getcr(inst); if (b.u32 <= (uint32_t)inst.imm32) { +#ifdef STATS + if ((inst.locb & 7) <= 5) + count_CALL_taken++; + else + count_CALL_uncond++; +#endif stackPush(a); stackPush(pc); pc += (inst.imm8 & 127) + 1; @@ -280,6 +295,10 @@ namespace RandomX { if (trace) std::cout << std::hex << a.u64 << std::endl; } else { + convertible_t& c = getcr(inst); +#ifdef STATS + count_CALL_not_taken++; +#endif c.u64 = a.u64; if (trace) std::cout << std::hex << /*a.u64 << " " <<*/ c.u64 << std::endl; } @@ -290,12 +309,24 @@ namespace RandomX { convertible_t b = loadbr1(inst); convertible_t& c = getcr(inst); if (stack.size() > 0 && b.u32 <= (uint32_t)inst.imm32) { +#ifdef STATS + if ((inst.locb & 7) <= 5) + count_RET_taken++; + else + count_RET_uncond++; +#endif auto raddr = stackPopAddress(); auto retval = stackPopValue(); c.u64 = a.u64 ^ retval.u64; pc = raddr; } else { +#ifdef STATS + if (stack.size() == 0) + count_RET_stack_empty++; + else + count_RET_not_taken++; +#endif c.u64 = a.u64; } if (trace) std::cout << std::hex << /*a.u64 << " " <<*/ c.u64 << std::endl; diff --git a/src/InterpretedVirtualMachine.hpp b/src/InterpretedVirtualMachine.hpp index 416c0e7..d853de0 100644 --- a/src/InterpretedVirtualMachine.hpp +++ b/src/InterpretedVirtualMachine.hpp @@ -18,7 +18,7 @@ along with RandomX. If not, see. */ #pragma once - +//#define STATS #include "VirtualMachine.hpp" #include "Program.hpp" #include @@ -42,6 +42,43 @@ namespace RandomX { Program p; std::vector stack; uint64_t pc, ic; +#ifdef STATS + int count_ADD_64; + int count_ADD_32; + int count_SUB_64; + int count_SUB_32; + int count_MUL_64; + int count_MULH_64; + int count_MUL_32; + int count_IMUL_32; + int count_IMULH_64; + int count_DIV_64; + int count_IDIV_64; + int count_AND_64; + int count_AND_32; + int count_OR_64; + int count_OR_32; + int count_XOR_64; + int count_XOR_32; + int count_SHL_64; + int count_SHR_64; + int count_SAR_64; + int count_ROL_64; + int count_ROR_64; + int count_FPADD; + int count_FPSUB; + int count_FPMUL; + int count_FPDIV; + int count_FPSQRT; + int count_FPROUND; + int count_CALL_uncond; + int count_CALL_taken; + int count_CALL_not_taken; + int count_RET_stack_empty; + int count_RET_uncond; + int count_RET_taken; + int count_RET_not_taken; +#endif convertible_t loada(Instruction&); convertible_t loadbr0(Instruction&);