mirror of
https://github.com/qemu/qemu.git
synced 2026-04-05 22:00:58 +00:00
fpu/softfloat: Refactor floatx80 format NaN classification to share code
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 <richard.henderson@linaro.org> Signed-off-by: Max Chou <max.chou@sifive.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-ID: <20260204051756.667397-4-max.chou@sifive.com>
This commit is contained in:
committed by
Richard Henderson
parent
5146b68791
commit
dddee8e1ba
@@ -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);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user