Unconditional RET

This commit is contained in:
tevador 2018-12-28 12:09:37 +01:00
parent 39c569ae44
commit 76b6b05cf2
4 changed files with 55 additions and 44 deletions

View file

@ -499,9 +499,6 @@ namespace RandomX {
gena(instr);
asmCode << "\tcmp rsp, rbp" << std::endl;
asmCode << "\tje short not_taken_ret_" << i << std::endl;
asmCode << "\tcmp " << regR32[instr.regb % RegistersCount] << ", " << instr.imm32 << std::endl;
asmCode << "\t" << jumpCondition(instr, true);
asmCode << " short not_taken_ret_" << i << std::endl;
asmCode << "\txor rax, qword ptr [rsp + 8]" << std::endl;
gencr(instr);
asmCode << "\tret 8" << std::endl;

View file

@ -26,6 +26,9 @@ along with RandomX. If not, see<http://www.gnu.org/licenses/>.
#include <stdexcept>
#include <sstream>
#include <cmath>
#ifdef STATS
#include <algorithm>
#endif
#ifdef FPUCHECK
constexpr bool fpuCheck = true;
@ -54,6 +57,9 @@ namespace RandomX {
void InterpretedVirtualMachine::execute() {
while (ic > 0) {
#ifdef STATS
count_instructions[pc]++;
#endif
auto& inst = p(pc);
if(trace) std::cout << inst.getName() << " (" << std::dec << pc << ")" << std::endl;
pc = (pc + 1) % ProgramLength;
@ -61,6 +67,9 @@ namespace RandomX {
(this->*handler)(inst);
ic--;
}
#ifdef STATS
count_endstack += stack.size();
#endif
}
convertible_t InterpretedVirtualMachine::loada(Instruction& inst) {
@ -284,9 +293,13 @@ namespace RandomX {
#ifdef STATS
count_CALL_taken++;
count_jump_taken[inst.locb & 7]++;
count_retdepth = std::max(0, count_retdepth - 1);
#endif
stackPush(a);
stackPush(pc);
#ifdef STATS
count_max_stack = std::max(count_max_stack, (int)stack.size());
#endif
pc += (inst.imm8 & 127) + 1;
pc = pc % ProgramLength;
if (trace) std::cout << std::hex << a.u64 << std::endl;
@ -306,10 +319,11 @@ namespace RandomX {
convertible_t a = loada(inst);
convertible_t b = loadbr1(inst);
convertible_t& c = getcr(inst);
if (stack.size() > 0 && JMP_COND(inst.locb, reg.r[inst.regb % RegistersCount], inst.imm32)) {
if (stack.size() > 0) {
#ifdef STATS
count_RET_taken++;
count_jump_taken[inst.locb & 7]++;
count_retdepth++;
count_retdepth_max = std::max(count_retdepth_max, count_retdepth);
#endif
auto raddr = stackPopAddress();
auto retval = stackPopValue();

View file

@ -18,7 +18,7 @@ along with RandomX. If not, see<http://www.gnu.org/licenses/>.
*/
#pragma once
//#define STATS
#define STATS
#include "VirtualMachine.hpp"
#include "Program.hpp"
#include <vector>
@ -43,41 +43,46 @@ namespace RandomX {
std::vector<convertible_t> 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_taken;
int count_CALL_not_taken;
int count_RET_stack_empty;
int count_RET_taken;
int count_RET_not_taken;
int count_ADD_64 = 0;
int count_ADD_32 = 0;
int count_SUB_64 = 0;
int count_SUB_32 = 0;
int count_MUL_64 = 0;
int count_MULH_64 = 0;
int count_MUL_32 = 0;
int count_IMUL_32 = 0;
int count_IMULH_64 = 0;
int count_DIV_64 = 0;
int count_IDIV_64 = 0;
int count_AND_64 = 0;
int count_AND_32 = 0;
int count_OR_64 = 0;
int count_OR_32 = 0;
int count_XOR_64 = 0;
int count_XOR_32 = 0;
int count_SHL_64 = 0;
int count_SHR_64 = 0;
int count_SAR_64 = 0;
int count_ROL_64 = 0;
int count_ROR_64 = 0;
int count_FPADD = 0;
int count_FPSUB = 0;
int count_FPMUL = 0;
int count_FPDIV = 0;
int count_FPSQRT = 0;
int count_FPROUND = 0;
int count_CALL_taken = 0;
int count_CALL_not_taken = 0;
int count_RET_stack_empty = 0;
int count_RET_taken = 0;
int count_RET_not_taken = 0;
int count_jump_taken[8] = { 0 };
int count_jump_not_taken[8] = { 0 };
int count_max_stack = 0;
int count_retdepth = 0;
int count_retdepth_max = 0;
int count_endstack = 0;
int count_instructions[ProgramLength] = { 0 };
#endif
convertible_t loada(Instruction&);

View file

@ -712,11 +712,6 @@ namespace RandomX {
crlen = 17;
}
emit(0x74e53b48); //cmp rsp, rbp; je
emitByte(20 + crlen);
emit(uint16_t(0x8141)); //cmp regb, imm32
emitByte(0xf8 + (instr.regb % RegistersCount));
emit(instr.imm32);
emitByte(jumpCondition(instr, true));
emitByte(11 + crlen);
emitByte(0x48);
emit(0x08244433); //xor rax,QWORD PTR [rsp+0x8]