down-convert floating-point 32-bit to fp 16-bit then return 16-bit uint
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 30 Oct 2018 02:55:22 +0000 (02:55 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 30 Oct 2018 02:55:22 +0000 (02:55 +0000)
this to be used just before MMU store

riscv/sv_insn_redirect.cc

index 23faeb9c730c61315e1e34e1f1ebd173518d9a6e..d80fb0890f82b0e1577b689356bb082e9c27954c 100644 (file)
@@ -918,12 +918,38 @@ sv_reg_t sv_proc_t::to_uint64(sv_freg_t const& reg)
 
 sv_reg_t sv_proc_t::to_uint32(sv_freg_t const& reg)
 {
-    return sv_reg_t(reg.to_uint32());
+    switch (reg.get_elwidth())
+    {
+        // 8-bit
+        case 1: throw trap_illegal_instruction(0); // XXX for now
+        // 16-bit data, up-convert to f32
+        case 2:
+        {
+            float32_t x32 = ::f32(reg.to_uint32());
+            return sv_reg_t(f32_to_f16(x32).v, xlen, reg.get_elwidth());
+        }
+        // 0 and 3 are 32-bit
+        default: break;
+    }
+    return sv_reg_t(reg.to_uint32(), xlen, reg.get_elwidth());
 }
 
 sv_reg_t sv_proc_t::to_uint32(sv_float32_t const& reg)
 {
-    return sv_reg_t(reg.to_uint32());
+    switch (reg.get_elwidth())
+    {
+        // 8-bit
+        case 1: throw trap_illegal_instruction(0); // XXX for now
+        // 16-bit data, up-convert to f32
+        case 2:
+        {
+            float32_t x32 = ::f32(reg.to_uint32());
+            return sv_reg_t(f32_to_f16(x32).v, xlen, reg.get_elwidth());
+        }
+        // 0 and 3 are 32-bit
+        default: break;
+    }
+    return sv_reg_t(reg.to_uint32(), xlen, reg.get_elwidth());
 }
 
 // ------