softfloat: make NO_SIGNALING_NANS runtime property

target/xtensa, the only user of NO_SIGNALING_NANS macro has FPU
implementations with and without the corresponding property. With
NO_SIGNALING_NANS being a macro they cannot be a part of the same QEMU
executable.
Replace macro with new property in float_status to allow cores with
different FPU implementations coexist.

Backports cc43c6925113c5bc8f1a0205375931d2e4807c99
This commit is contained in:
Max Filippov 2021-02-26 12:11:32 -05:00 committed by Lioncash
parent 3e5aa58139
commit db780eff66
3 changed files with 129 additions and 113 deletions

View file

@ -79,12 +79,18 @@ this code that are retained.
* version 2 or later. See the COPYING file in the top-level directory.
*/
/* Define for architectures which deviate from IEEE in not supporting
/*
* Define whether architecture deviates from IEEE in not supporting
* signaling NaNs (so all NaNs are treated as quiet).
*/
static inline bool no_signaling_nans(float_status *status)
{
#if defined(TARGET_XTENSA)
#define NO_SIGNALING_NANS 1
return status->no_signaling_nans;
#else
return false;
#endif
}
/* Define how the architecture discriminates signaling NaNs.
* This done with the most significant bit of the fraction.
@ -111,12 +117,12 @@ static inline bool snan_bit_is_one(float_status *status)
static bool parts_is_snan_frac(uint64_t frac, float_status *status)
{
#ifdef NO_SIGNALING_NANS
if (no_signaling_nans(status)) {
return false;
#else
} else {
bool msb = extract64(frac, DECOMPOSED_BINARY_POINT - 1, 1);
return msb == snan_bit_is_one(status);
#endif
}
}
/*----------------------------------------------------------------------------
@ -170,9 +176,8 @@ static FloatParts parts_default_nan(float_status *status)
static FloatParts parts_silence_nan(FloatParts a, float_status *status)
{
#ifdef NO_SIGNALING_NANS
g_assert_not_reached();
#elif defined(TARGET_HPPA)
g_assert(!no_signaling_nans(status));
#if defined(TARGET_HPPA)
a.frac &= ~(1ULL << (DECOMPOSED_BINARY_POINT - 1));
a.frac |= 1ULL << (DECOMPOSED_BINARY_POINT - 2);
#else
@ -247,16 +252,17 @@ typedef struct {
bool float16_is_quiet_nan(float16 a_, float_status *status)
{
#ifdef NO_SIGNALING_NANS
if (no_signaling_nans(status)) {
return float16_is_any_nan(a_);
#else
} else {
uint16_t a = float16_val(a_);
if (snan_bit_is_one(status)) {
return (((a >> 9) & 0x3F) == 0x3E) && (a & 0x1FF);
} else {
return ((a & ~0x8000) >= 0x7C80);
return ((a >> 9) & 0x3F) == 0x3F;
}
}
#endif
}
/*----------------------------------------------------------------------------
@ -266,16 +272,16 @@ bool float16_is_quiet_nan(float16 a_, float_status *status)
bool float16_is_signaling_nan(float16 a_, float_status *status)
{
#ifdef NO_SIGNALING_NANS
if (no_signaling_nans(status)) {
return 0;
#else
} else {
uint16_t a = float16_val(a_);
if (snan_bit_is_one(status)) {
return ((a & ~0x8000) >= 0x7C80);
return ((a >> 9) & 0x3F) == 0x3F;
} else {
return (((a >> 9) & 0x3F) == 0x3E) && (a & 0x1FF);
}
#endif
}
}
/*----------------------------------------------------------------------------
@ -285,16 +291,16 @@ bool float16_is_signaling_nan(float16 a_, float_status *status)
bool float32_is_quiet_nan(float32 a_, float_status *status)
{
#ifdef NO_SIGNALING_NANS
if (no_signaling_nans(status)) {
return float32_is_any_nan(a_);
#else
} else {
uint32_t a = float32_val(a_);
if (snan_bit_is_one(status)) {
return (((a >> 22) & 0x1FF) == 0x1FE) && (a & 0x003FFFFF);
} else {
return ((uint32_t)(a << 1) >= 0xFF800000);
}
#endif
}
}
/*----------------------------------------------------------------------------
@ -304,16 +310,16 @@ bool float32_is_quiet_nan(float32 a_, float_status *status)
bool float32_is_signaling_nan(float32 a_, float_status *status)
{
#ifdef NO_SIGNALING_NANS
if (no_signaling_nans(status)) {
return 0;
#else
} else {
uint32_t a = float32_val(a_);
if (snan_bit_is_one(status)) {
return ((uint32_t)(a << 1) >= 0xFF800000);
} else {
return (((a >> 22) & 0x1FF) == 0x1FE) && (a & 0x003FFFFF);
}
#endif
}
}
/*----------------------------------------------------------------------------
@ -631,9 +637,9 @@ static float32 propagateFloat32NaN(float32 a, float32 b, float_status *status)
bool float64_is_quiet_nan(float64 a_, float_status *status)
{
#ifdef NO_SIGNALING_NANS
if (no_signaling_nans(status)) {
return float64_is_any_nan(a_);
#else
} else {
uint64_t a = float64_val(a_);
if (snan_bit_is_one(status)) {
return (((a >> 51) & 0xFFF) == 0xFFE)
@ -641,7 +647,7 @@ bool float64_is_quiet_nan(float64 a_, float_status *status)
} else {
return ((a << 1) >= 0xFFF0000000000000ULL);
}
#endif
}
}
/*----------------------------------------------------------------------------
@ -651,9 +657,9 @@ bool float64_is_quiet_nan(float64 a_, float_status *status)
bool float64_is_signaling_nan(float64 a_, float_status *status)
{
#ifdef NO_SIGNALING_NANS
if (no_signaling_nans(status)) {
return 0;
#else
} else {
uint64_t a = float64_val(a_);
if (snan_bit_is_one(status)) {
return ((a << 1) >= 0xFFF0000000000000ULL);
@ -661,7 +667,7 @@ bool float64_is_signaling_nan(float64 a_, float_status *status)
return (((a >> 51) & 0xFFF) == 0xFFE)
&& (a & UINT64_C(0x0007FFFFFFFFFFFF));
}
#endif
}
}
/*----------------------------------------------------------------------------
@ -770,9 +776,9 @@ static float64 propagateFloat64NaN(float64 a, float64 b, float_status *status)
bool floatx80_is_quiet_nan(floatx80 a, float_status *status)
{
#ifdef NO_SIGNALING_NANS
if (no_signaling_nans(status)) {
return floatx80_is_any_nan(a);
#else
} else {
if (snan_bit_is_one(status)) {
uint64_t aLow;
@ -784,7 +790,7 @@ bool floatx80_is_quiet_nan(floatx80 a, float_status *status)
return ((a.high & 0x7FFF) == 0x7FFF)
&& (UINT64_C(0x8000000000000000) <= ((uint64_t)(a.low << 1)));
}
#endif
}
}
/*----------------------------------------------------------------------------
@ -795,9 +801,9 @@ bool floatx80_is_quiet_nan(floatx80 a, float_status *status)
bool floatx80_is_signaling_nan(floatx80 a, float_status *status)
{
#ifdef NO_SIGNALING_NANS
if (no_signaling_nans(status)) {
return 0;
#else
} else {
if (snan_bit_is_one(status)) {
return ((a.high & 0x7FFF) == 0x7FFF)
&& ((a.low << 1) >= 0x8000000000000000ULL);
@ -809,7 +815,7 @@ bool floatx80_is_signaling_nan(floatx80 a, float_status *status)
&& (uint64_t)(aLow << 1)
&& (a.low == aLow);
}
#endif
}
}
/*----------------------------------------------------------------------------
@ -933,9 +939,9 @@ floatx80 propagateFloatx80NaN(floatx80 a, floatx80 b, float_status *status)
bool float128_is_quiet_nan(float128 a, float_status *status)
{
#ifdef NO_SIGNALING_NANS
if (no_signaling_nans(status)) {
return float128_is_any_nan(a);
#else
} else {
if (snan_bit_is_one(status)) {
return (((a.high >> 47) & 0xFFFF) == 0xFFFE)
&& (a.low || (a.high & 0x00007FFFFFFFFFFFULL));
@ -943,7 +949,7 @@ bool float128_is_quiet_nan(float128 a, float_status *status)
return ((a.high << 1) >= 0xFFFF000000000000ULL)
&& (a.low || (a.high & 0x0000FFFFFFFFFFFFULL));
}
#endif
}
}
/*----------------------------------------------------------------------------
@ -953,9 +959,9 @@ bool float128_is_quiet_nan(float128 a, float_status *status)
bool float128_is_signaling_nan(float128 a, float_status *status)
{
#ifdef NO_SIGNALING_NANS
if (no_signaling_nans(status)) {
return 0;
#else
} else {
if (snan_bit_is_one(status)) {
return ((a.high << 1) >= 0xFFFF000000000000ULL)
&& (a.low || (a.high & 0x0000FFFFFFFFFFFFULL));
@ -963,7 +969,7 @@ bool float128_is_signaling_nan(float128 a, float_status *status)
return (((a.high >> 47) & 0xFFFF) == 0xFFFE)
&& (a.low || (a.high & UINT64_C(0x00007FFFFFFFFFFF)));
}
#endif
}
}
/*----------------------------------------------------------------------------
@ -973,16 +979,16 @@ bool float128_is_signaling_nan(float128 a, float_status *status)
float128 float128_silence_nan(float128 a, float_status *status)
{
#ifdef NO_SIGNALING_NANS
if (no_signaling_nans(status)) {
g_assert_not_reached();
#else
} else {
if (snan_bit_is_one(status)) {
return float128_default_nan(status);
} else {
a.high |= UINT64_C(0x0000800000000000);
return a;
}
#endif
}
}
/*----------------------------------------------------------------------------

View file

@ -95,6 +95,11 @@ static inline void set_snan_bit_is_one(bool val, float_status *status)
status->snan_bit_is_one = val;
}
static inline void set_no_signaling_nans(bool val, float_status *status)
{
status->no_signaling_nans = val;
}
static inline bool get_float_detect_tininess(float_status *status)
{
return status->tininess_before_rounding;

View file

@ -165,8 +165,13 @@ typedef struct float_status {
/* should denormalised inputs go to zero and set the input_denormal flag? */
bool flush_inputs_to_zero;
bool default_nan_mode;
/* not always used -- see snan_bit_is_one() in softfloat-specialize.h */
/*
* The flags below are not used on all specializations and may
* constant fold away (see snan_bit_is_one()/no_signalling_nans() in
* softfloat-specialize.inc.c)
*/
bool snan_bit_is_one;
bool no_signaling_nans;
} float_status;
#endif /* SOFTFLOAT_TYPES_H */