softfloat: Inline float32 compare specializations

Replace the float32 compare specializations with inline functions
that call the standard float32_compare{,_quiet} functions.
Use bool as the return type.

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Richard Henderson 2020-05-05 10:33:18 -07:00
parent 71bfd65c5f
commit 5da2d2d8e5
2 changed files with 41 additions and 224 deletions

View File

@ -4733,222 +4733,6 @@ float32 float32_log2(float32 a, float_status *status)
return normalizeRoundAndPackFloat32(zSign, 0x85, zSig, status);
}
/*----------------------------------------------------------------------------
| Returns 1 if the single-precision floating-point value `a' is equal to
| the corresponding value `b', and 0 otherwise. The invalid exception is
| raised if either operand is a NaN. Otherwise, the comparison is performed
| according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
int float32_eq(float32 a, float32 b, float_status *status)
{
uint32_t av, bv;
a = float32_squash_input_denormal(a, status);
b = float32_squash_input_denormal(b, status);
if ( ( ( extractFloat32Exp( a ) == 0xFF ) && extractFloat32Frac( a ) )
|| ( ( extractFloat32Exp( b ) == 0xFF ) && extractFloat32Frac( b ) )
) {
float_raise(float_flag_invalid, status);
return 0;
}
av = float32_val(a);
bv = float32_val(b);
return ( av == bv ) || ( (uint32_t) ( ( av | bv )<<1 ) == 0 );
}
/*----------------------------------------------------------------------------
| Returns 1 if the single-precision floating-point value `a' is less than
| or equal to the corresponding value `b', and 0 otherwise. The invalid
| exception is raised if either operand is a NaN. The comparison is performed
| according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
int float32_le(float32 a, float32 b, float_status *status)
{
bool aSign, bSign;
uint32_t av, bv;
a = float32_squash_input_denormal(a, status);
b = float32_squash_input_denormal(b, status);
if ( ( ( extractFloat32Exp( a ) == 0xFF ) && extractFloat32Frac( a ) )
|| ( ( extractFloat32Exp( b ) == 0xFF ) && extractFloat32Frac( b ) )
) {
float_raise(float_flag_invalid, status);
return 0;
}
aSign = extractFloat32Sign( a );
bSign = extractFloat32Sign( b );
av = float32_val(a);
bv = float32_val(b);
if ( aSign != bSign ) return aSign || ( (uint32_t) ( ( av | bv )<<1 ) == 0 );
return ( av == bv ) || ( aSign ^ ( av < bv ) );
}
/*----------------------------------------------------------------------------
| Returns 1 if the single-precision floating-point value `a' is less than
| the corresponding value `b', and 0 otherwise. The invalid exception is
| raised if either operand is a NaN. The comparison is performed according
| to the IEC/IEEE Standard for Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
int float32_lt(float32 a, float32 b, float_status *status)
{
bool aSign, bSign;
uint32_t av, bv;
a = float32_squash_input_denormal(a, status);
b = float32_squash_input_denormal(b, status);
if ( ( ( extractFloat32Exp( a ) == 0xFF ) && extractFloat32Frac( a ) )
|| ( ( extractFloat32Exp( b ) == 0xFF ) && extractFloat32Frac( b ) )
) {
float_raise(float_flag_invalid, status);
return 0;
}
aSign = extractFloat32Sign( a );
bSign = extractFloat32Sign( b );
av = float32_val(a);
bv = float32_val(b);
if ( aSign != bSign ) return aSign && ( (uint32_t) ( ( av | bv )<<1 ) != 0 );
return ( av != bv ) && ( aSign ^ ( av < bv ) );
}
/*----------------------------------------------------------------------------
| Returns 1 if the single-precision floating-point values `a' and `b' cannot
| be compared, and 0 otherwise. The invalid exception is raised if either
| operand is a NaN. The comparison is performed according to the IEC/IEEE
| Standard for Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
int float32_unordered(float32 a, float32 b, float_status *status)
{
a = float32_squash_input_denormal(a, status);
b = float32_squash_input_denormal(b, status);
if ( ( ( extractFloat32Exp( a ) == 0xFF ) && extractFloat32Frac( a ) )
|| ( ( extractFloat32Exp( b ) == 0xFF ) && extractFloat32Frac( b ) )
) {
float_raise(float_flag_invalid, status);
return 1;
}
return 0;
}
/*----------------------------------------------------------------------------
| Returns 1 if the single-precision floating-point value `a' is equal to
| the corresponding value `b', and 0 otherwise. Quiet NaNs do not cause an
| exception. The comparison is performed according to the IEC/IEEE Standard
| for Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
int float32_eq_quiet(float32 a, float32 b, float_status *status)
{
a = float32_squash_input_denormal(a, status);
b = float32_squash_input_denormal(b, status);
if ( ( ( extractFloat32Exp( a ) == 0xFF ) && extractFloat32Frac( a ) )
|| ( ( extractFloat32Exp( b ) == 0xFF ) && extractFloat32Frac( b ) )
) {
if (float32_is_signaling_nan(a, status)
|| float32_is_signaling_nan(b, status)) {
float_raise(float_flag_invalid, status);
}
return 0;
}
return ( float32_val(a) == float32_val(b) ) ||
( (uint32_t) ( ( float32_val(a) | float32_val(b) )<<1 ) == 0 );
}
/*----------------------------------------------------------------------------
| Returns 1 if the single-precision floating-point value `a' is less than or
| equal to the corresponding value `b', and 0 otherwise. Quiet NaNs do not
| cause an exception. Otherwise, the comparison is performed according to the
| IEC/IEEE Standard for Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
int float32_le_quiet(float32 a, float32 b, float_status *status)
{
bool aSign, bSign;
uint32_t av, bv;
a = float32_squash_input_denormal(a, status);
b = float32_squash_input_denormal(b, status);
if ( ( ( extractFloat32Exp( a ) == 0xFF ) && extractFloat32Frac( a ) )
|| ( ( extractFloat32Exp( b ) == 0xFF ) && extractFloat32Frac( b ) )
) {
if (float32_is_signaling_nan(a, status)
|| float32_is_signaling_nan(b, status)) {
float_raise(float_flag_invalid, status);
}
return 0;
}
aSign = extractFloat32Sign( a );
bSign = extractFloat32Sign( b );
av = float32_val(a);
bv = float32_val(b);
if ( aSign != bSign ) return aSign || ( (uint32_t) ( ( av | bv )<<1 ) == 0 );
return ( av == bv ) || ( aSign ^ ( av < bv ) );
}
/*----------------------------------------------------------------------------
| Returns 1 if the single-precision floating-point value `a' is less than
| the corresponding value `b', and 0 otherwise. Quiet NaNs do not cause an
| exception. Otherwise, the comparison is performed according to the IEC/IEEE
| Standard for Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
int float32_lt_quiet(float32 a, float32 b, float_status *status)
{
bool aSign, bSign;
uint32_t av, bv;
a = float32_squash_input_denormal(a, status);
b = float32_squash_input_denormal(b, status);
if ( ( ( extractFloat32Exp( a ) == 0xFF ) && extractFloat32Frac( a ) )
|| ( ( extractFloat32Exp( b ) == 0xFF ) && extractFloat32Frac( b ) )
) {
if (float32_is_signaling_nan(a, status)
|| float32_is_signaling_nan(b, status)) {
float_raise(float_flag_invalid, status);
}
return 0;
}
aSign = extractFloat32Sign( a );
bSign = extractFloat32Sign( b );
av = float32_val(a);
bv = float32_val(b);
if ( aSign != bSign ) return aSign && ( (uint32_t) ( ( av | bv )<<1 ) != 0 );
return ( av != bv ) && ( aSign ^ ( av < bv ) );
}
/*----------------------------------------------------------------------------
| Returns 1 if the single-precision floating-point values `a' and `b' cannot
| be compared, and 0 otherwise. Quiet NaNs do not cause an exception. The
| comparison is performed according to the IEC/IEEE Standard for Binary
| Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
int float32_unordered_quiet(float32 a, float32 b, float_status *status)
{
a = float32_squash_input_denormal(a, status);
b = float32_squash_input_denormal(b, status);
if ( ( ( extractFloat32Exp( a ) == 0xFF ) && extractFloat32Frac( a ) )
|| ( ( extractFloat32Exp( b ) == 0xFF ) && extractFloat32Frac( b ) )
) {
if (float32_is_signaling_nan(a, status)
|| float32_is_signaling_nan(b, status)) {
float_raise(float_flag_invalid, status);
}
return 1;
}
return 0;
}
/*----------------------------------------------------------------------------
| Returns the result of converting the double-precision floating-point value
| `a' to the extended double-precision floating-point format. The conversion

View File

@ -343,14 +343,6 @@ float32 float32_muladd(float32, float32, float32, int, float_status *status);
float32 float32_sqrt(float32, float_status *status);
float32 float32_exp2(float32, float_status *status);
float32 float32_log2(float32, float_status *status);
int float32_eq(float32, float32, float_status *status);
int float32_le(float32, float32, float_status *status);
int float32_lt(float32, float32, float_status *status);
int float32_unordered(float32, float32, float_status *status);
int float32_eq_quiet(float32, float32, float_status *status);
int float32_le_quiet(float32, float32, float_status *status);
int float32_lt_quiet(float32, float32, float_status *status);
int float32_unordered_quiet(float32, float32, float_status *status);
FloatRelation float32_compare(float32, float32, float_status *status);
FloatRelation float32_compare_quiet(float32, float32, float_status *status);
float32 float32_min(float32, float32, float_status *status);
@ -425,6 +417,47 @@ static inline float32 float32_set_sign(float32 a, int sign)
return make_float32((float32_val(a) & 0x7fffffff) | (sign << 31));
}
static inline bool float32_eq(float32 a, float32 b, float_status *s)
{
return float32_compare(a, b, s) == float_relation_equal;
}
static inline bool float32_le(float32 a, float32 b, float_status *s)
{
return float32_compare(a, b, s) <= float_relation_equal;
}
static inline bool float32_lt(float32 a, float32 b, float_status *s)
{
return float32_compare(a, b, s) < float_relation_equal;
}
static inline bool float32_unordered(float32 a, float32 b, float_status *s)
{
return float32_compare(a, b, s) == float_relation_unordered;
}
static inline bool float32_eq_quiet(float32 a, float32 b, float_status *s)
{
return float32_compare_quiet(a, b, s) == float_relation_equal;
}
static inline bool float32_le_quiet(float32 a, float32 b, float_status *s)
{
return float32_compare_quiet(a, b, s) <= float_relation_equal;
}
static inline bool float32_lt_quiet(float32 a, float32 b, float_status *s)
{
return float32_compare_quiet(a, b, s) < float_relation_equal;
}
static inline bool float32_unordered_quiet(float32 a, float32 b,
float_status *s)
{
return float32_compare_quiet(a, b, s) == float_relation_unordered;
}
#define float32_zero make_float32(0)
#define float32_half make_float32(0x3f000000)
#define float32_one make_float32(0x3f800000)