From 6dfdf856aba8a7de210f1c8e64f5dd5802b96585 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Fri, 9 Nov 2018 10:06:15 +0000 Subject: [PATCH] got fed up with repeated code, using macros --- riscv/sv_insn_redirect.cc | 77 +++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 32 deletions(-) diff --git a/riscv/sv_insn_redirect.cc b/riscv/sv_insn_redirect.cc index 261adb8..aa4cb33 100644 --- a/riscv/sv_insn_redirect.cc +++ b/riscv/sv_insn_redirect.cc @@ -4,6 +4,9 @@ #include "sv_reg.h" #include "sv_mmu.h" +#define xstr(x) str(x) +#define str(x) #x + void (sv_proc_t::WRITE_FRD)(sv_float32_t value) { reg_t reg = _insn->rd().reg; @@ -735,39 +738,49 @@ sv_reg_t sv_proc_t::rv_sr(sv_reg_t const & lhs, sv_reg_t const & rhs, return sresult; } -bool sv_proc_t::rv_lt(sv_reg_t const & lhs, sv_reg_t const & rhs) -{ - uint8_t bitwidth = _insn->src_bitwidth; - uint64_t vlhs = 0; - uint64_t vrhs = 0; - if (rv_int_op_prepare(lhs, rhs, vlhs, vrhs, bitwidth)) { - bool result = lhs < rhs; - fprintf(stderr, "lt result %lx %lx %x\n", - (uint64_t)lhs, (uint64_t)rhs, result); - return result; - } - bool result = vlhs < vrhs; - fprintf(stderr, "lt result %lx %lx %d bw %d\n", - (uint64_t)lhs, (uint64_t)rhs, result, bitwidth); - return result; -} +#define lt < +#define gt > -bool sv_proc_t::rv_lt(sv_sreg_t const & lhs, sv_sreg_t const & rhs) -{ - uint8_t bitwidth = _insn->src_bitwidth; - int64_t vlhs = 0; - int64_t vrhs = 0; - if (rv_int_op_prepare(lhs, rhs, vlhs, vrhs, bitwidth)) { - bool result = lhs < rhs; - fprintf(stderr, "lt result %lx %lx %x\n", - (int64_t)lhs, (int64_t)rhs, result); - return result; - } - bool result = vlhs < vrhs; - fprintf(stderr, "lt result %lx %lx %d bw %d\n", - (int64_t)lhs, (int64_t)rhs, result, bitwidth); - return result; -} +#define OP_RES_FN( fname, SLHSTYPE, SRHSTYPE, SRESTYPE, \ + LHSTYPE, RHSTYPE, RESTYPE ) \ +bool sv_proc_t::rv_##fname (SLHSTYPE const & lhs, SRHSTYPE const & rhs) \ +{ \ + uint8_t bitwidth = _insn->src_bitwidth; \ + LHSTYPE vlhs = 0; \ + RHSTYPE vrhs = 0; \ + if (rv_int_op_prepare(lhs, rhs, vlhs, vrhs, bitwidth)) { \ + RESTYLE result = lhs op rhs; \ + fprintf(stderr, "%s result %lx %lx %lx\n", \ + xstr(op), (LHSTYPE)lhs, (RHSTYPE)rhs, (uint64_t)result); \ + return result; \ + } \ + RESTYPE result = vlhs < vrhs; \ + fprintf(stderr, "lt result %lx %lx %d bw %d\n", \ + (LHSTYPE)lhs, (RHSTYPE)rhs, result, bitwidth); \ + return result; \ +} + +#define OP_BOOL_FN( fname, SLHSTYPE, SRHSTYPE, \ + LHSTYPE, RHSTYPE ) \ +bool sv_proc_t::rv_##fname (SLHSTYPE const & lhs, SRHSTYPE const & rhs) \ +{ \ + uint8_t bitwidth = _insn->src_bitwidth; \ + LHSTYPE vlhs = 0; \ + RHSTYPE vrhs = 0; \ + if (rv_int_op_prepare(lhs, rhs, vlhs, vrhs, bitwidth)) { \ + bool result = lhs fname rhs; \ + fprintf(stderr, "%s result %lx %lx %x\n", \ + xstr(fname), (LHSTYPE)lhs, (RHSTYPE)rhs, result); \ + return result; \ + } \ + bool result = vlhs < vrhs; \ + fprintf(stderr, "lt result %lx %lx %d bw %d\n", \ + (LHSTYPE)lhs, (RHSTYPE)rhs, result, bitwidth); \ + return result; \ +} + +OP_BOOL_FN( lt, sv_reg_t, sv_reg_t, uint64_t, uint64_t ) +OP_BOOL_FN( lt, sv_sreg_t, sv_sreg_t, int64_t, int64_t ) bool sv_proc_t::rv_gt(sv_reg_t const & lhs, sv_reg_t const & rhs) { -- 2.30.2