From 8b98dbd409379e9efa6a58da4b8bf3d7d252f1a8 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Tue, 30 Oct 2018 01:14:06 +0000 Subject: [PATCH] add sv_proc_t f32 conversions when elwidth=16bit --- riscv/decode.h | 4 ++++ riscv/sv_insn_redirect.cc | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/riscv/decode.h b/riscv/decode.h index 6e11c46..bc0bd79 100644 --- a/riscv/decode.h +++ b/riscv/decode.h @@ -234,13 +234,17 @@ private: #define invalid_pc(pc) ((pc) & 1) /* Convenience wrappers to simplify softfloat code sequences */ +#define unboxF16(r) (isBoxedF16(r) ? (uint16_t)r.v[0] : defaultNaNF16UI) +#define isBoxedF16(r) (isBoxedF32(r) && ((uint16_t)((r.v[0] >> 16) + 1) == 0)) #define isBoxedF32(r) (isBoxedF64(r) && ((uint32_t)((r.v[0] >> 32) + 1) == 0)) #define unboxF32(r) (isBoxedF32(r) ? (uint32_t)r.v[0] : defaultNaNF32UI) #define isBoxedF64(r) ((r.v[1] + 1) == 0) #define unboxF64(r) (isBoxedF64(r) ? r.v[0] : defaultNaNF64UI) typedef float128_t freg_t; +inline float16_t f16(uint16_t v) { return { v }; } inline float32_t f32(uint32_t v) { return { v }; } inline float64_t f64(uint64_t v) { return { v }; } +inline float16_t f16(freg_t r) { return f16(unboxF16(r)); } inline float32_t f32(freg_t r) { return f32(unboxF32(r)); } inline float64_t f64(freg_t r) { return f64(unboxF64(r)); } inline float128_t f128(freg_t r) { return r; } diff --git a/riscv/sv_insn_redirect.cc b/riscv/sv_insn_redirect.cc index a6dba3a..23faeb9 100644 --- a/riscv/sv_insn_redirect.cc +++ b/riscv/sv_insn_redirect.cc @@ -399,12 +399,32 @@ sv_reg_t sv_proc_t::sv_reg_uint32(sv_reg_t const& v) sv_float32_t (sv_proc_t::f32)(sv_freg_t x) { + switch (x.get_elwidth()) + { + // 8-bit + case 1: throw trap_illegal_instruction(0); // XXX for now + // 16-bit data, up-convert to f32 + case 2: + return f16_to_f32(f16(x.to_uint32())); + // 0 and 3 are 32-bit + default: break; + } return ::f32(x); } sv_float32_t (sv_proc_t::f32)(sv_reg_t const& v) { uint64_t x = v; + switch (v.get_elwidth()) + { + // 8-bit + case 1: throw trap_illegal_instruction(0); // XXX for now + // 16-bit data, up-convert to f32 + case 2: + return f16_to_f32(f16(x)); + // 0 and 3 are 32-bit + default: break; + } return ::f32(x); } -- 2.30.2