From: Max Chou <[email protected]> The floatx80_is_[quiet|signaling]_nan functions contain duplicated logic that should be shared. This commit introduces floatx80_nan_is_snan helper function that determine if a NaN is signaling and change the return type of floatx80_is_[signaling|quiet]_nan to bool.
Suggested-by: Richard Henderson <[email protected]> Signed-off-by: Max Chou <[email protected]> Reviewed-by: Richard Henderson <[email protected]> Reviewed-by: Chao Liu <[email protected]> Signed-off-by: Richard Henderson <[email protected]> Message-ID: <[email protected]> --- include/fpu/softfloat.h | 4 +-- fpu/softfloat-specialize.c.inc | 53 ++++++++++++---------------------- 2 files changed, 21 insertions(+), 36 deletions(-) diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h index c18ab2cb60..ac6a392375 100644 --- a/include/fpu/softfloat.h +++ b/include/fpu/softfloat.h @@ -978,8 +978,8 @@ floatx80 floatx80_rem(floatx80, floatx80, float_status *status); floatx80 floatx80_sqrt(floatx80, float_status *status); FloatRelation floatx80_compare(floatx80, floatx80, float_status *status); FloatRelation floatx80_compare_quiet(floatx80, floatx80, float_status *status); -int floatx80_is_quiet_nan(floatx80, float_status *status); -int floatx80_is_signaling_nan(floatx80, float_status *status); +bool floatx80_is_quiet_nan(floatx80, float_status *status); +bool floatx80_is_signaling_nan(floatx80, float_status *status); floatx80 floatx80_silence_nan(floatx80, float_status *status); floatx80 floatx80_scalbn(floatx80, int, float_status *status); diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc index 7d2515c1fa..9ed968c79b 100644 --- a/fpu/softfloat-specialize.c.inc +++ b/fpu/softfloat-specialize.c.inc @@ -357,53 +357,38 @@ bool float64_is_signaling_nan(float64 a_, float_status *status) } /*---------------------------------------------------------------------------- -| Returns 1 if the extended double-precision floating-point value `a' is a -| quiet NaN; otherwise returns 0. This slightly differs from the same -| function for other types as floatx80 has an explicit bit. +| Determine if a floatx80 NaN is signaling NaN. +| The MSB of frac differs from the same function for other types as floatx80 +| has an explicit bit. *----------------------------------------------------------------------------*/ -int floatx80_is_quiet_nan(floatx80 a, float_status *status) +static bool floatx80_nan_is_snan(floatx80 a, float_status *status) { if (no_signaling_nans(status)) { - return floatx80_is_any_nan(a); - } else { - if (snan_bit_is_one(status)) { - uint64_t aLow; - - aLow = a.low & ~0x4000000000000000ULL; - return ((a.high & 0x7FFF) == 0x7FFF) - && (aLow << 1) - && (a.low == aLow); - } else { - return ((a.high & 0x7FFF) == 0x7FFF) - && (UINT64_C(0x8000000000000000) <= ((uint64_t)(a.low << 1))); - } + return false; } + bool frac_msb_is_one = (a.low >> 62) & 1; + return frac_msb_is_one == snan_bit_is_one(status); } /*---------------------------------------------------------------------------- | Returns 1 if the extended double-precision floating-point value `a' is a -| signaling NaN; otherwise returns 0. This slightly differs from the same -| function for other types as floatx80 has an explicit bit. +| quiet NaN; otherwise returns 0. *----------------------------------------------------------------------------*/ -int floatx80_is_signaling_nan(floatx80 a, float_status *status) +bool floatx80_is_quiet_nan(floatx80 a, float_status *status) { - if (no_signaling_nans(status)) { - return 0; - } else { - if (snan_bit_is_one(status)) { - return ((a.high & 0x7FFF) == 0x7FFF) - && ((a.low << 1) >= 0x8000000000000000ULL); - } else { - uint64_t aLow; + return floatx80_is_any_nan(a) && !floatx80_nan_is_snan(a, status); +} - aLow = a.low & ~UINT64_C(0x4000000000000000); - return ((a.high & 0x7FFF) == 0x7FFF) - && (uint64_t)(aLow << 1) - && (a.low == aLow); - } - } +/*---------------------------------------------------------------------------- +| Returns 1 if the extended double-precision floating-point value `a' is a +| signaling NaN; otherwise returns 0. +*----------------------------------------------------------------------------*/ + +bool floatx80_is_signaling_nan(floatx80 a, float_status *status) +{ + return floatx80_is_any_nan(a) && floatx80_nan_is_snan(a, status); } /*---------------------------------------------------------------------------- -- 2.43.0
