From a829c93406668b3c6caaf086f8638ae4fc29163e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 9 Mar 2019 19:15:51 -0500 Subject: [PATCH] common/fp/unpacked: Correct edge-cases within FPUnpack for half-precision floating point This corrects one case where floating-point exceptions could be set when they're not supposed to be. This also corrects a case where values were being treated as NaNs when they weren't supposed to be. --- src/common/fp/unpacked.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/common/fp/unpacked.cpp b/src/common/fp/unpacked.cpp index ad6374a1..96251779 100644 --- a/src/common/fp/unpacked.cpp +++ b/src/common/fp/unpacked.cpp @@ -33,7 +33,9 @@ std::tuple FPUnpackBase(FPT op, FPCR fpcr, FPSR& fpsr) if (frac_raw == 0 || fpcr.FZ16()) { return {FPType::Zero, sign, {sign, 0, 0}}; } + return {FPType::Nonzero, sign, ToNormalized(sign, denormal_exponent, frac_raw)}; } + if (frac_raw == 0 || fpcr.FZ()) { if (frac_raw != 0) { FPProcessException(FPExc::InputDenorm, fpcr, fpsr); @@ -46,7 +48,7 @@ std::tuple FPUnpackBase(FPT op, FPCR fpcr, FPSR& fpsr) 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 ((exp_all_ones && !is_half_precision) || (exp_all_ones && ahp_disabled)) { if (frac_raw == 0) { return {FPType::Infinity, sign, ToNormalized(sign, 1000000, 1)}; }