WRITE_FRD convert 64-bit to elwidth
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 1 Nov 2018 06:14:40 +0000 (06:14 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 1 Nov 2018 06:14:40 +0000 (06:14 +0000)
riscv/sv_insn_redirect.cc

index 9a67a739c6e1602e636c8010c2f4ad6fb96238b9..fee135cbdd5fb2e3a06ad1e02c7141632eaa0ff3 100644 (file)
@@ -41,10 +41,36 @@ void (sv_proc_t::WRITE_FRD)(sv_float32_t value)
 
 void (sv_proc_t::WRITE_FRD)(sv_float64_t value)
 {
+    reg_t reg = _insn->rd().reg;
     fprintf(stderr, "WRITE_FRD sv_float64_t %g\n",
             (double)((float64_t)value).v);
-    sv_freg_t v = sv_freg_t(freg(value), xlen, value.get_elwidth());
-    DO_WRITE_FREG( _insn->rd(), v );
+    uint8_t dest_elwidth = _insn->reg_elwidth(reg, false);
+    freg_t v;
+    switch (dest_elwidth)
+    {
+        // 8-bit
+        case 1: throw trap_illegal_instruction(0); // XXX for now
+        // 16-bit data, up-convert to f32
+        case 2:
+        {
+            float16_t x16 = ::f64_to_f16((float64_t)value);
+            v = freg(x16);
+            break;
+        }
+        case 3:
+        {
+            float32_t x32 = ::f64_to_f32((float64_t)value);
+            v = freg(x32);
+            break;
+        }
+        default:
+        {
+            v = freg(value);
+            break;
+        }
+    }
+    sv_freg_t vf = sv_freg_t(v, xlen, value.get_elwidth());
+    DO_WRITE_FREG( _insn->rd(), vf );
 }
 
 void (sv_proc_t::WRITE_FRD)(sv_float128_t value)