softfloat: Convert modrem operations to FloatParts

Rename to parts$N_modrem.  This was the last use of a lot
of the legacy infrastructure, so remove it as required.

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 2021-05-07 18:40:28 -07:00
parent 2fa3546c8f
commit feaf2e9c06
4 changed files with 329 additions and 1243 deletions

View file

@ -626,6 +626,40 @@ static FloatPartsN *partsN(div)(FloatPartsN *a, FloatPartsN *b,
return a;
}
/*
* Floating point remainder, per IEC/IEEE, or modulus.
*/
static FloatPartsN *partsN(modrem)(FloatPartsN *a, FloatPartsN *b,
uint64_t *mod_quot, float_status *s)
{
int ab_mask = float_cmask(a->cls) | float_cmask(b->cls);
if (likely(ab_mask == float_cmask_normal)) {
frac_modrem(a, b, mod_quot);
return a;
}
if (mod_quot) {
*mod_quot = 0;
}
/* All the NaN cases */
if (unlikely(ab_mask & float_cmask_anynan)) {
return parts_pick_nan(a, b, s);
}
/* Inf % N; N % 0 */
if (a->cls == float_class_inf || b->cls == float_class_zero) {
float_raise(float_flag_invalid, s);
parts_default_nan(a, s);
return a;
}
/* N % Inf; 0 % N */
g_assert(b->cls == float_class_inf || a->cls == float_class_zero);
return a;
}
/*
* Square Root
*

View file

@ -641,62 +641,6 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls,
#endif
}
/*----------------------------------------------------------------------------
| Takes two single-precision floating-point values `a' and `b', one of which
| is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a
| signaling NaN, the invalid exception is raised.
*----------------------------------------------------------------------------*/
static float32 propagateFloat32NaN(float32 a, float32 b, float_status *status)
{
bool aIsLargerSignificand;
uint32_t av, bv;
FloatClass a_cls, b_cls;
/* This is not complete, but is good enough for pickNaN. */
a_cls = (!float32_is_any_nan(a)
? float_class_normal
: float32_is_signaling_nan(a, status)
? float_class_snan
: float_class_qnan);
b_cls = (!float32_is_any_nan(b)
? float_class_normal
: float32_is_signaling_nan(b, status)
? float_class_snan
: float_class_qnan);
av = float32_val(a);
bv = float32_val(b);
if (is_snan(a_cls) || is_snan(b_cls)) {
float_raise(float_flag_invalid, status);
}
if (status->default_nan_mode) {
return float32_default_nan(status);
}
if ((uint32_t)(av << 1) < (uint32_t)(bv << 1)) {
aIsLargerSignificand = 0;
} else if ((uint32_t)(bv << 1) < (uint32_t)(av << 1)) {
aIsLargerSignificand = 1;
} else {
aIsLargerSignificand = (av < bv) ? 1 : 0;
}
if (pickNaN(a_cls, b_cls, aIsLargerSignificand, status)) {
if (is_snan(b_cls)) {
return float32_silence_nan(b, status);
}
return b;
} else {
if (is_snan(a_cls)) {
return float32_silence_nan(a, status);
}
return a;
}
}
/*----------------------------------------------------------------------------
| Returns 1 if the double-precision floating-point value `a' is a quiet
| NaN; otherwise returns 0.
@ -737,62 +681,6 @@ bool float64_is_signaling_nan(float64 a_, float_status *status)
}
}
/*----------------------------------------------------------------------------
| Takes two double-precision floating-point values `a' and `b', one of which
| is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a
| signaling NaN, the invalid exception is raised.
*----------------------------------------------------------------------------*/
static float64 propagateFloat64NaN(float64 a, float64 b, float_status *status)
{
bool aIsLargerSignificand;
uint64_t av, bv;
FloatClass a_cls, b_cls;
/* This is not complete, but is good enough for pickNaN. */
a_cls = (!float64_is_any_nan(a)
? float_class_normal
: float64_is_signaling_nan(a, status)
? float_class_snan
: float_class_qnan);
b_cls = (!float64_is_any_nan(b)
? float_class_normal
: float64_is_signaling_nan(b, status)
? float_class_snan
: float_class_qnan);
av = float64_val(a);
bv = float64_val(b);
if (is_snan(a_cls) || is_snan(b_cls)) {
float_raise(float_flag_invalid, status);
}
if (status->default_nan_mode) {
return float64_default_nan(status);
}
if ((uint64_t)(av << 1) < (uint64_t)(bv << 1)) {
aIsLargerSignificand = 0;
} else if ((uint64_t)(bv << 1) < (uint64_t)(av << 1)) {
aIsLargerSignificand = 1;
} else {
aIsLargerSignificand = (av < bv) ? 1 : 0;
}
if (pickNaN(a_cls, b_cls, aIsLargerSignificand, status)) {
if (is_snan(b_cls)) {
return float64_silence_nan(b, status);
}
return b;
} else {
if (is_snan(a_cls)) {
return float64_silence_nan(a, status);
}
return a;
}
}
/*----------------------------------------------------------------------------
| Returns 1 if the extended double-precision floating-point value `a' is a
| quiet NaN; otherwise returns 0. This slightly differs from the same
@ -947,56 +835,3 @@ bool float128_is_signaling_nan(float128 a, float_status *status)
}
}
}
/*----------------------------------------------------------------------------
| Takes two quadruple-precision floating-point values `a' and `b', one of
| which is a NaN, and returns the appropriate NaN result. If either `a' or
| `b' is a signaling NaN, the invalid exception is raised.
*----------------------------------------------------------------------------*/
static float128 propagateFloat128NaN(float128 a, float128 b,
float_status *status)
{
bool aIsLargerSignificand;
FloatClass a_cls, b_cls;
/* This is not complete, but is good enough for pickNaN. */
a_cls = (!float128_is_any_nan(a)
? float_class_normal
: float128_is_signaling_nan(a, status)
? float_class_snan
: float_class_qnan);
b_cls = (!float128_is_any_nan(b)
? float_class_normal
: float128_is_signaling_nan(b, status)
? float_class_snan
: float_class_qnan);
if (is_snan(a_cls) || is_snan(b_cls)) {
float_raise(float_flag_invalid, status);
}
if (status->default_nan_mode) {
return float128_default_nan(status);
}
if (lt128(a.high << 1, a.low, b.high << 1, b.low)) {
aIsLargerSignificand = 0;
} else if (lt128(b.high << 1, b.low, a.high << 1, a.low)) {
aIsLargerSignificand = 1;
} else {
aIsLargerSignificand = (a.high < b.high) ? 1 : 0;
}
if (pickNaN(a_cls, b_cls, aIsLargerSignificand, status)) {
if (is_snan(b_cls)) {
return float128_silence_nan(b, status);
}
return b;
} else {
if (is_snan(a_cls)) {
return float128_silence_nan(a, status);
}
return a;
}
}

File diff suppressed because it is too large Load diff

View file

@ -745,4 +745,38 @@ static inline bool ne128(uint64_t a0, uint64_t a1, uint64_t b0, uint64_t b1)
return a0 != b0 || a1 != b1;
}
/*
* Similarly, comparisons of 192-bit values.
*/
static inline bool eq192(uint64_t a0, uint64_t a1, uint64_t a2,
uint64_t b0, uint64_t b1, uint64_t b2)
{
return ((a0 ^ b0) | (a1 ^ b1) | (a2 ^ b2)) == 0;
}
static inline bool le192(uint64_t a0, uint64_t a1, uint64_t a2,
uint64_t b0, uint64_t b1, uint64_t b2)
{
if (a0 != b0) {
return a0 < b0;
}
if (a1 != b1) {
return a1 < b1;
}
return a2 <= b2;
}
static inline bool lt192(uint64_t a0, uint64_t a1, uint64_t a2,
uint64_t b0, uint64_t b1, uint64_t b2)
{
if (a0 != b0) {
return a0 < b0;
}
if (a1 != b1) {
return a1 < b1;
}
return a2 < b2;
}
#endif