softfloat: Correctly handle NaNs in float16_to_float32()
Correctly handle NaNs in float16_to_float32(), by defining and using a float16ToCommonNaN() function, as we do with the other formats. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
This commit is contained in:
parent
600e30d2b2
commit
f591e1bedf
|
@ -119,6 +119,23 @@ float16 float16_maybe_silence_nan(float16 a_)
|
||||||
return a_;
|
return a_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
| Returns the result of converting the half-precision floating-point NaN
|
||||||
|
| `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid
|
||||||
|
| exception is raised.
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
static commonNaNT float16ToCommonNaN( float16 a STATUS_PARAM )
|
||||||
|
{
|
||||||
|
commonNaNT z;
|
||||||
|
|
||||||
|
if ( float16_is_signaling_nan( a ) ) float_raise( float_flag_invalid STATUS_VAR );
|
||||||
|
z.sign = float16_val(a) >> 15;
|
||||||
|
z.low = 0;
|
||||||
|
z.high = ((bits64) float16_val(a))<<54;
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
| Returns the result of converting the canonical NaN `a' to the half-
|
| Returns the result of converting the canonical NaN `a' to the half-
|
||||||
| precision floating-point format.
|
| precision floating-point format.
|
||||||
|
|
|
@ -2761,9 +2761,7 @@ float32 float16_to_float32(float16 a, flag ieee STATUS_PARAM)
|
||||||
|
|
||||||
if (aExp == 0x1f && ieee) {
|
if (aExp == 0x1f && ieee) {
|
||||||
if (aSig) {
|
if (aSig) {
|
||||||
/* Make sure correct exceptions are raised. */
|
return commonNaNToFloat32(float16ToCommonNaN(a STATUS_VAR) STATUS_VAR);
|
||||||
float32ToCommonNaN(a STATUS_VAR);
|
|
||||||
aSig |= 0x200;
|
|
||||||
}
|
}
|
||||||
return packFloat32(aSign, 0xff, aSig << 13);
|
return packFloat32(aSign, 0xff, aSig << 13);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue