From 3579ba6519690b3ac1c2c86dc81ed07c0edad34c Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Tue, 30 Oct 2018 02:55:22 +0000 Subject: [PATCH] down-convert floating-point 32-bit to fp 16-bit then return 16-bit uint this to be used just before MMU store --- riscv/sv_insn_redirect.cc | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/riscv/sv_insn_redirect.cc b/riscv/sv_insn_redirect.cc index 23faeb9..d80fb08 100644 --- a/riscv/sv_insn_redirect.cc +++ b/riscv/sv_insn_redirect.cc @@ -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()); } // ------ -- 2.30.2