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 <peter.maydell@linaro.org> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
This commit is contained in:
parent
bcd4d9afd4
commit
600e30d2b2
2 changed files with 38 additions and 11 deletions
|
|
@ -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.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue