From 600e30d2b293bd19b0d0cdb7e8a517cecf482d12 Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Thu, 10 Feb 2011 11:28:58 +0000 Subject: softfloat: Fix single-to-half precision float conversions Fix various bugs in the single-to-half-precision conversion code: * input NaNs not correctly converted in IEEE mode (fixed by defining and using a commonNaNToFloat16()) * wrong values returned when converting NaN/Inf into non-IEEE half precision value * wrong values returned for conversion of values which are on the boundary between denormal and zero for the half precision format * zeroes not correctly identified * excessively large results in non-IEEE mode should generate InvalidOp, not Overflow Signed-off-by: Peter Maydell Signed-off-by: Aurelien Jarno --- fpu/softfloat-specialize.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'fpu/softfloat-specialize.h') diff --git a/fpu/softfloat-specialize.h b/fpu/softfloat-specialize.h index 1b7521f8e6..1c0b12b573 100644 --- a/fpu/softfloat-specialize.h +++ b/fpu/softfloat-specialize.h @@ -119,6 +119,27 @@ float16 float16_maybe_silence_nan(float16 a_) return a_; } +/*---------------------------------------------------------------------------- +| Returns the result of converting the canonical NaN `a' to the half- +| precision floating-point format. +*----------------------------------------------------------------------------*/ + +static float16 commonNaNToFloat16(commonNaNT a STATUS_PARAM) +{ + uint16_t mantissa = a.high>>54; + + if (STATUS(default_nan_mode)) { + return float16_default_nan; + } + + if (mantissa) { + return make_float16(((((uint16_t) a.sign) << 15) + | (0x1F << 10) | mantissa)); + } else { + return float16_default_nan; + } +} + /*---------------------------------------------------------------------------- | The pattern for a default generated single-precision NaN. *----------------------------------------------------------------------------*/ -- cgit v1.2.1