From: Luke Kenneth Casson Leighton Date: Fri, 9 Nov 2018 10:21:43 +0000 (+0000) Subject: got fed up with repeated code on s/u-ops, use macros X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c54eb4b9cfb7549d7b498b9d902074a510a66ce8;p=riscv-isa-sim.git got fed up with repeated code on s/u-ops, use macros --- diff --git a/riscv/sv_insn_redirect.cc b/riscv/sv_insn_redirect.cc index 66f0350..5703251 100644 --- a/riscv/sv_insn_redirect.cc +++ b/riscv/sv_insn_redirect.cc @@ -482,136 +482,40 @@ OP_PREP_FINISH(sv_reg_t, sv_reg_t, sv_reg_t, uint64_t, uint64_t, uint64_t) OP_PREP_FINISH(sv_sreg_t, sv_reg_t, sv_sreg_t, int64_t, uint64_t, int64_t) OP_PREP_FINISH(sv_sreg_t, sv_sreg_t, sv_sreg_t, int64_t, int64_t, int64_t) -sv_reg_t sv_proc_t::rv_add(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)) { - fprintf(stderr, "add result %lx %lx %lx\n", - (uint64_t)lhs, (uint64_t)rhs, (uint64_t)(lhs + rhs)); - return lhs + rhs; - } - uint64_t result = vlhs + vrhs; - return rv_int_op_finish(lhs, rhs, result, bitwidth); -} - -sv_reg_t sv_proc_t::rv_sub(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)) { - return lhs - rhs; - } - uint64_t result = vlhs - vrhs; - return rv_int_op_finish(lhs, rhs, result, bitwidth); -} - -sv_sreg_t sv_proc_t::rv_div(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)) { - sv_sreg_t result = lhs / rhs; - fprintf(stderr, "div result %lx %lx %lx\n", - (uint64_t)lhs, (uint64_t)rhs, (int64_t)result); - return result; - } - int64_t result = vlhs / vrhs; - return rv_int_op_finish(lhs, rhs, result, bitwidth); -} - -sv_reg_t sv_proc_t::rv_div(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)) { - sv_reg_t result = lhs / rhs; - fprintf(stderr, "div result %lx %lx %lx\n", - (uint64_t)lhs, (uint64_t)rhs, (uint64_t)result); - return result; - } - uint64_t result = vlhs / vrhs; - return rv_int_op_finish(lhs, rhs, result, bitwidth); -} - -sv_sreg_t sv_proc_t::rv_rem(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)) { - sv_sreg_t result = lhs % rhs; - fprintf(stderr, "rem result %lx %lx %lx\n", - (uint64_t)lhs, (uint64_t)rhs, (int64_t)result); - return result; - } - int64_t result = vlhs % vrhs; - return rv_int_op_finish(lhs, rhs, result, bitwidth); -} - -sv_reg_t sv_proc_t::rv_rem(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)) { - sv_reg_t result = lhs % rhs; - fprintf(stderr, "rem result %lx %lx %lx\n", - (uint64_t)lhs, (uint64_t)rhs, (uint64_t)result); - return result; - } - uint64_t result = vlhs % vrhs; - return rv_int_op_finish(lhs, rhs, result, bitwidth); -} - -sv_reg_t sv_proc_t::rv_mul(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)) { - sv_reg_t result = lhs * rhs; - fprintf(stderr, "mul result %lx %lx %lx\n", - (uint64_t)lhs, (uint64_t)rhs, (uint64_t)result); - return result; - } - uint64_t result = vlhs * vrhs; - return rv_int_op_finish(lhs, rhs, result, bitwidth); -} - -sv_sreg_t sv_proc_t::rv_mul(sv_sreg_t const & lhs, sv_reg_t const & rhs) -{ - uint8_t bitwidth = _insn->src_bitwidth; - int64_t vlhs = 0; - uint64_t vrhs = 0; - if (rv_int_op_prepare(lhs, rhs, vlhs, vrhs, bitwidth)) { - sv_sreg_t result = lhs * rhs; - fprintf(stderr, "mul result %lx %lx %lx\n", - (int64_t)lhs, (uint64_t)rhs, (int64_t)result); - return result; - } - int64_t result = vlhs * vrhs; - return rv_int_op_finish(lhs, rhs, result, bitwidth); -} - -sv_sreg_t sv_proc_t::rv_mul(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)) { - sv_sreg_t result = lhs * rhs; - fprintf(stderr, "mul result %lx %lx %lx\n", - (int64_t)lhs, (int64_t)rhs, (int64_t)result); - return result; - } - int64_t result = vlhs * vrhs; - return rv_int_op_finish(lhs, rhs, result, bitwidth); -} +#define OP_RES_FN( fname, SLHSTYPE, SRHSTYPE, SRESTYPE, \ + LHSTYPE, RHSTYPE, RESTYPE ) \ +SRESTYPE 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)) { \ + RESTYPE result = lhs fname rhs; \ + fprintf(stderr, "%s result %lx %lx %lx\n", \ + xstr(fname), (LHSTYPE)lhs, (RHSTYPE)rhs, (RESTYPE)result); \ + return SRESTYPE(result); \ + } \ + RESTYPE result = vlhs fname vrhs; \ + fprintf(stderr, "%s result %lx %lx %d bw %d\n", \ + xstr(fname), (LHSTYPE)lhs, (RHSTYPE)rhs, (RESTYPE)result, bitwidth); \ + return rv_int_op_finish(lhs, rhs, result, bitwidth); \ +} + +#define add + +#define sub - +#define div / +#define rem % +#define mul * + +OP_RES_FN ( add, sv_reg_t, sv_reg_t, sv_reg_t, uint64_t, uint64_t, uint64_t ) +OP_RES_FN ( sub, sv_reg_t, sv_reg_t, sv_reg_t, uint64_t, uint64_t, uint64_t ) +OP_RES_FN ( div, sv_reg_t, sv_reg_t, sv_reg_t, uint64_t, uint64_t, uint64_t ) +OP_RES_FN ( div, sv_sreg_t, sv_sreg_t, sv_sreg_t, int64_t, int64_t, int64_t ) +OP_RES_FN ( rem, sv_reg_t, sv_reg_t, sv_reg_t, uint64_t, uint64_t, uint64_t ) +OP_RES_FN ( rem, sv_sreg_t, sv_sreg_t, sv_sreg_t, int64_t, int64_t, int64_t ) +OP_RES_FN ( mul, sv_reg_t, sv_reg_t, sv_reg_t, uint64_t, uint64_t, uint64_t ) +OP_RES_FN ( mul, sv_sreg_t, sv_reg_t, sv_sreg_t, int64_t, uint64_t, int64_t ) +OP_RES_FN ( mul, sv_sreg_t, sv_sreg_t, sv_sreg_t, int64_t, int64_t, int64_t ) /* 32-bit mulh/mulhu/mulhsu */ sv_reg_t sv_proc_t::rv_mulhu(sv_reg_t const & lhs, sv_reg_t const & rhs) @@ -745,25 +649,6 @@ sv_reg_t sv_proc_t::rv_sr(sv_reg_t const & lhs, sv_reg_t const & rhs, #define eq == #define ne != -#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) \ @@ -777,9 +662,9 @@ bool sv_proc_t::rv_##fname (SLHSTYPE const & lhs, SRHSTYPE const & rhs) \ 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); \ + bool result = vlhs fname vrhs; \ + fprintf(stderr, "%s result %lx %lx %d bw %d\n", \ + xstr(fname), (LHSTYPE)lhs, (RHSTYPE)rhs, result, bitwidth); \ return result; \ }