got fed up with repeated code, using macros
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 9 Nov 2018 10:06:15 +0000 (10:06 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 9 Nov 2018 10:06:15 +0000 (10:06 +0000)
riscv/sv_insn_redirect.cc

index 261adb8e93e6884545a053f0759e221879a845eb..aa4cb335eb47aba39ec7bfb9bbf966a0e7d44c91 100644 (file)
@@ -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)
 {