aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Waterman <andrew@sifive.com>2024-08-23 14:48:21 -0700
committerAndrew Waterman <andrew@sifive.com>2024-08-23 14:48:21 -0700
commitc72eca86877e43b7595a46219f7eb136154ce912 (patch)
tree266714cdee78a2d99a93a89d7ac1a18ea3edd02b
parenta8c9d9ccb17e012f4eee5a664ff296d2aaa79d53 (diff)
downloadriscv-isa-sim-c72eca86877e43b7595a46219f7eb136154ce912.zip
riscv-isa-sim-c72eca86877e43b7595a46219f7eb136154ce912.tar.gz
riscv-isa-sim-c72eca86877e43b7595a46219f7eb136154ce912.tar.bz2
Refactor insn_template to be more DRY
-rw-r--r--riscv/insn_template.cc47
1 files changed, 23 insertions, 24 deletions
diff --git a/riscv/insn_template.cc b/riscv/insn_template.cc
index 9194d19..168e2dc 100644
--- a/riscv/insn_template.cc
+++ b/riscv/insn_template.cc
@@ -5,24 +5,29 @@
#define DECODE_MACRO_USAGE_LOGGED 0
+#define PROLOGUE \
+ reg_t npc = sext_xlen(pc + insn_length(OPCODE))
+
+#define EPILOGUE \
+ trace_opcode(p, OPCODE, insn); \
+ return npc
+
reg_t fast_rv32i_NAME(processor_t* p, insn_t insn, reg_t pc)
{
#define xlen 32
- reg_t npc = sext_xlen(pc + insn_length(OPCODE));
+ PROLOGUE;
#include "insns/NAME.h"
- trace_opcode(p, OPCODE, insn);
+ EPILOGUE;
#undef xlen
- return npc;
}
reg_t fast_rv64i_NAME(processor_t* p, insn_t insn, reg_t pc)
{
#define xlen 64
- reg_t npc = sext_xlen(pc + insn_length(OPCODE));
+ PROLOGUE;
#include "insns/NAME.h"
- trace_opcode(p, OPCODE, insn);
+ EPILOGUE;
#undef xlen
- return npc;
}
#undef DECODE_MACRO_USAGE_LOGGED
@@ -31,21 +36,19 @@ reg_t fast_rv64i_NAME(processor_t* p, insn_t insn, reg_t pc)
reg_t logged_rv32i_NAME(processor_t* p, insn_t insn, reg_t pc)
{
#define xlen 32
- reg_t npc = sext_xlen(pc + insn_length(OPCODE));
+ PROLOGUE;
#include "insns/NAME.h"
- trace_opcode(p, OPCODE, insn);
+ EPILOGUE;
#undef xlen
- return npc;
}
reg_t logged_rv64i_NAME(processor_t* p, insn_t insn, reg_t pc)
{
#define xlen 64
- reg_t npc = sext_xlen(pc + insn_length(OPCODE));
+ PROLOGUE;
#include "insns/NAME.h"
- trace_opcode(p, OPCODE, insn);
+ EPILOGUE;
#undef xlen
- return npc;
}
#undef CHECK_REG
@@ -57,21 +60,19 @@ reg_t logged_rv64i_NAME(processor_t* p, insn_t insn, reg_t pc)
reg_t fast_rv32e_NAME(processor_t* p, insn_t insn, reg_t pc)
{
#define xlen 32
- reg_t npc = sext_xlen(pc + insn_length(OPCODE));
+ PROLOGUE;
#include "insns/NAME.h"
- trace_opcode(p, OPCODE, insn);
+ EPILOGUE;
#undef xlen
- return npc;
}
reg_t fast_rv64e_NAME(processor_t* p, insn_t insn, reg_t pc)
{
#define xlen 64
- reg_t npc = sext_xlen(pc + insn_length(OPCODE));
+ PROLOGUE;
#include "insns/NAME.h"
- trace_opcode(p, OPCODE, insn);
+ EPILOGUE;
#undef xlen
- return npc;
}
#undef DECODE_MACRO_USAGE_LOGGED
@@ -80,19 +81,17 @@ reg_t fast_rv64e_NAME(processor_t* p, insn_t insn, reg_t pc)
reg_t logged_rv32e_NAME(processor_t* p, insn_t insn, reg_t pc)
{
#define xlen 32
- reg_t npc = sext_xlen(pc + insn_length(OPCODE));
+ PROLOGUE;
#include "insns/NAME.h"
- trace_opcode(p, OPCODE, insn);
+ EPILOGUE;
#undef xlen
- return npc;
}
reg_t logged_rv64e_NAME(processor_t* p, insn_t insn, reg_t pc)
{
#define xlen 64
- reg_t npc = sext_xlen(pc + insn_length(OPCODE));
+ PROLOGUE;
#include "insns/NAME.h"
- trace_opcode(p, OPCODE, insn);
+ EPILOGUE;
#undef xlen
- return npc;
}