unsigned version of div
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 6 Nov 2018 17:49:45 +0000 (17:49 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 6 Nov 2018 17:49:45 +0000 (17:49 +0000)
riscv/sv_insn_redirect.cc

index 7df63fc3d4cd68642afde9facf41acb49362b556..d91c751ea7532552cdacf9cc3c79f86fe71b00e9 100644 (file)
@@ -541,7 +541,17 @@ sv_sreg_t sv_proc_t::rv_div(sv_sreg_t const & lhs, sv_sreg_t const & rhs)
 
 sv_reg_t sv_proc_t::rv_div(sv_reg_t const & lhs, sv_reg_t const & rhs)
 {
-    return lhs / 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)