From 88aa0fc486779f35628c28d01552ab07c0428fb4 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Thu, 1 Nov 2018 06:14:40 +0000 Subject: [PATCH] WRITE_FRD convert 64-bit to elwidth --- 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 9a67a73..fee135c 100644 --- a/riscv/sv_insn_redirect.cc +++ b/riscv/sv_insn_redirect.cc @@ -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) -- 2.30.2