From 26d699e18cdda76c3df7c848aa0d11c7e5fcd928 Mon Sep 17 00:00:00 2001 From: Luke Wren Date: Sat, 1 Apr 2023 06:02:45 +0100 Subject: [PATCH] rvcpp simulator: fix bad regnum decode for c.slli outside of x8..x15 --- test/sim/rvcpp/rv.cpp | 4 ++-- test/sim/rvcpp/rv_opcodes.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/sim/rvcpp/rv.cpp b/test/sim/rvcpp/rv.cpp index 823ebd3..41091cf 100644 --- a/test/sim/rvcpp/rv.cpp +++ b/test/sim/rvcpp/rv.cpp @@ -508,7 +508,7 @@ struct RVCore { } // RVC Quadrant 10: } else if (RVOPC_MATCH(instr, C_SLLI)) { - regnum_rd = c_rs1_s(instr); + regnum_rd = c_rs1_l(instr); rd_wdata = regs[regnum_rd] << GETBITS(instr, 6, 2); } else if (RVOPC_MATCH(instr, C_MV)) { if (c_rs2_l(instr) == 0) { @@ -587,7 +587,7 @@ struct RVCore { } else { printf(" %04x : ", instr & 0xffffu); } - if (regnum_rd != 0) { + if (regnum_rd != 0 && rd_wdata) { printf("%-3s <- %08x ", friendly_reg_names[regnum_rd], *rd_wdata); } else { printf(" "); diff --git a/test/sim/rvcpp/rv_opcodes.h b/test/sim/rvcpp/rv_opcodes.h index 83a345e..caf50cf 100644 --- a/test/sim/rvcpp/rv_opcodes.h +++ b/test/sim/rvcpp/rv_opcodes.h @@ -334,7 +334,7 @@ #define RVOPC_CM_MVA01S_BITS 0b1010110001100010 #define RVOPC_CM_MVA01S_MASK 0b1111110001100011 -#define _RVOPC_MATCH(x, instr_mask, instr_bits) ((x & instr_mask) == instr_bits) +#define _RVOPC_MATCH(x, instr_mask, instr_bits) (((x) & (instr_mask)) == (instr_bits)) #define RVOPC_MATCH(x, instr) _RVOPC_MATCH(x, RVOPC_ ## instr ## _MASK, RVOPC_ ## instr ## _BITS) static const char *friendly_reg_names[32] = {