From 7e814de445b6a304955d3f4cf24f578b907f18f3 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 9 Mar 2019 01:18:43 -0500 Subject: [PATCH] common/fp/unpacked: Handle half-precision unpacking in FPUnpackBase --- src/common/fp/unpacked.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/common/fp/unpacked.cpp b/src/common/fp/unpacked.cpp index 45d2b584..9afe4b1b 100644 --- a/src/common/fp/unpacked.cpp +++ b/src/common/fp/unpacked.cpp @@ -23,11 +23,17 @@ std::tuple FPUnpackBase(FPT op, FPCR fpcr, FPSR& fpsr) constexpr size_t mantissa_low_bit = 0; constexpr int denormal_exponent = FPInfo::exponent_min - int(FPInfo::explicit_mantissa_width); + constexpr bool is_half_precision = std::is_same_v; const bool sign = Common::Bit(op); const FPT exp_raw = Common::Bits(op); const FPT frac_raw = Common::Bits(op); if (exp_raw == 0) { + if constexpr (is_half_precision) { + if (frac_raw == 0 || fpcr.FZ16()) { + return {FPType::Zero, sign, {sign, 0, 0}}; + } + } if (frac_raw == 0 || fpcr.FZ()) { if (frac_raw != 0) { FPProcessException(FPExc::InputDenorm, fpcr, fpsr); @@ -38,7 +44,9 @@ std::tuple FPUnpackBase(FPT op, FPCR fpcr, FPSR& fpsr) return {FPType::Nonzero, sign, ToNormalized(sign, denormal_exponent, frac_raw)}; } - if (exp_raw == Common::Ones(FPInfo::exponent_width)) { + const bool exp_all_ones = exp_raw == Common::Ones(FPInfo::exponent_width); + const bool ahp_disabled = is_half_precision && !fpcr.AHP(); + if (exp_all_ones || ahp_disabled) { if (frac_raw == 0) { return {FPType::Infinity, sign, ToNormalized(sign, 1000000, 1)}; } @@ -52,6 +60,7 @@ std::tuple FPUnpackBase(FPT op, FPCR fpcr, FPSR& fpsr) return {FPType::Nonzero, sign, {sign, exp, frac}}; } +template std::tuple FPUnpackBase(u16 op, FPCR fpcr, FPSR& fpsr); template std::tuple FPUnpackBase(u32 op, FPCR fpcr, FPSR& fpsr); template std::tuple FPUnpackBase(u64 op, FPCR fpcr, FPSR& fpsr);