diff mbox series

[v3,02/13] fpu: convert float[16/32/64]_squash_denormal to new modern style

Message ID 20190813124946.25322-3-alex.bennee@linaro.org
State Superseded
Headers show
Series softfloat updates (include tweaks, rm LIT64) | expand

Commit Message

Alex Bennée Aug. 13, 2019, 12:49 p.m. UTC
This also allows us to remove the extractFloat16exp/frac helpers.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
 fpu/softfloat.c | 110 +++++++++++++++++++++---------------------------
 1 file changed, 47 insertions(+), 63 deletions(-)

-- 
2.20.1

Comments

Richard Henderson Aug. 13, 2019, 1:11 p.m. UTC | #1
On 8/13/19 1:49 PM, Alex Bennée wrote:
> +static FloatParts parts_squash_denormal(FloatParts p, float_status *status)

> +{

> +    if (p.exp == 0 && p.frac != 0) {

> +        float_raise(float_flag_input_denormal, status);

> +        p.frac = 0;

> +        p.cls = float_class_zero;

> +    }

> +

> +    return p;

> +}

> +

> +float16 float16_squash_input_denormal(float16 a, float_status *status)

> +{

> +    if (status->flush_inputs_to_zero) {

> +        FloatParts p = float16_unpack_raw(a);

> +        p = parts_squash_denormal(p, status);

> +        return float16_pack_raw(p);

> +    }

> +    return a;

> +}


Hmm.  Maybe avoid the re-pack in the likely chance that we can?

static bool parts_squash_denormal(FloatParts p, float_status *status)
{
    if (p.exp == 0 && p.frac != 0) {
        float_raise(float_flag_input_denormal, status);
        return true;
    }
    return false;
}

float16 float16_squash_input_denormal(float16 a, float_status *status)
{
    if (status->flush_inputs_to_zero) {
        FloatParts p = float16_unpack_raw(a);
        if (parts_squash_denormal(p, status)) {
            return float16_set_sign(float16_zero, p.sign);
        }
    }
    return a;
}
Alex Bennée Aug. 13, 2019, 1:38 p.m. UTC | #2
Richard Henderson <richard.henderson@linaro.org> writes:

> On 8/13/19 1:49 PM, Alex Bennée wrote:

>> +static FloatParts parts_squash_denormal(FloatParts p, float_status *status)

>> +{

>> +    if (p.exp == 0 && p.frac != 0) {

>> +        float_raise(float_flag_input_denormal, status);

>> +        p.frac = 0;

>> +        p.cls = float_class_zero;

>> +    }

>> +

>> +    return p;

>> +}

>> +

>> +float16 float16_squash_input_denormal(float16 a, float_status *status)

>> +{

>> +    if (status->flush_inputs_to_zero) {

>> +        FloatParts p = float16_unpack_raw(a);

>> +        p = parts_squash_denormal(p, status);

>> +        return float16_pack_raw(p);

>> +    }

>> +    return a;

>> +}

>

> Hmm.  Maybe avoid the re-pack in the likely chance that we can?

>

> static bool parts_squash_denormal(FloatParts p, float_status *status)

> {

>     if (p.exp == 0 && p.frac != 0) {

>         float_raise(float_flag_input_denormal, status);

>         return true;

>     }

>     return false;

> }

>

> float16 float16_squash_input_denormal(float16 a, float_status *status)

> {

>     if (status->flush_inputs_to_zero) {

>         FloatParts p = float16_unpack_raw(a);

>         if (parts_squash_denormal(p, status)) {

>             return float16_set_sign(float16_zero, p.sign);

>         }


I'll squash with the next patch and use the set_sign rather than
make_float and see if it's the same.

>     }

>     return a;

> }



--
Alex Bennée
diff mbox series

Patch

diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index 2ba36ec3703..0a434555cd8 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -414,24 +414,6 @@  float64_gen2(float64 xa, float64 xb, float_status *s,
     return soft(ua.s, ub.s, s);
 }
 
-/*----------------------------------------------------------------------------
-| Returns the fraction bits of the half-precision floating-point value `a'.
-*----------------------------------------------------------------------------*/
-
-static inline uint32_t extractFloat16Frac(float16 a)
-{
-    return float16_val(a) & 0x3ff;
-}
-
-/*----------------------------------------------------------------------------
-| Returns the exponent bits of the half-precision floating-point value `a'.
-*----------------------------------------------------------------------------*/
-
-static inline int extractFloat16Exp(float16 a)
-{
-    return (float16_val(a) >> 10) & 0x1f;
-}
-
 /*----------------------------------------------------------------------------
 | Returns the fraction bits of the single-precision floating-point value `a'.
 *----------------------------------------------------------------------------*/
@@ -3306,6 +3288,53 @@  float64 float64_silence_nan(float64 a, float_status *status)
     return float64_pack_raw(p);
 }
 
+
+/*----------------------------------------------------------------------------
+| If `a' is denormal and we are in flush-to-zero mode then set the
+| input-denormal exception and return zero. Otherwise just return the value.
+*----------------------------------------------------------------------------*/
+
+static FloatParts parts_squash_denormal(FloatParts p, float_status *status)
+{
+    if (p.exp == 0 && p.frac != 0) {
+        float_raise(float_flag_input_denormal, status);
+        p.frac = 0;
+        p.cls = float_class_zero;
+    }
+
+    return p;
+}
+
+float16 float16_squash_input_denormal(float16 a, float_status *status)
+{
+    if (status->flush_inputs_to_zero) {
+        FloatParts p = float16_unpack_raw(a);
+        p = parts_squash_denormal(p, status);
+        return float16_pack_raw(p);
+    }
+    return a;
+}
+
+float32 float32_squash_input_denormal(float32 a, float_status *status)
+{
+    if (status->flush_inputs_to_zero) {
+        FloatParts p = float32_unpack_raw(a);
+        p = parts_squash_denormal(p, status);
+        return float32_pack_raw(p);
+    }
+    return a;
+}
+
+float64 float64_squash_input_denormal(float64 a, float_status *status)
+{
+    if (status->flush_inputs_to_zero) {
+        FloatParts p = float64_unpack_raw(a);
+        p = parts_squash_denormal(p, status);
+        return float64_pack_raw(p);
+    }
+    return a;
+}
+
 /*----------------------------------------------------------------------------
 | Takes a 64-bit fixed-point value `absZ' with binary point between bits 6
 | and 7, and returns the properly rounded 32-bit integer corresponding to the
@@ -3482,21 +3511,6 @@  static int64_t roundAndPackUint64(flag zSign, uint64_t absZ0,
     return absZ0;
 }
 
-/*----------------------------------------------------------------------------
-| If `a' is denormal and we are in flush-to-zero mode then set the
-| input-denormal exception and return zero. Otherwise just return the value.
-*----------------------------------------------------------------------------*/
-float32 float32_squash_input_denormal(float32 a, float_status *status)
-{
-    if (status->flush_inputs_to_zero) {
-        if (extractFloat32Exp(a) == 0 && extractFloat32Frac(a) != 0) {
-            float_raise(float_flag_input_denormal, status);
-            return make_float32(float32_val(a) & 0x80000000);
-        }
-    }
-    return a;
-}
-
 /*----------------------------------------------------------------------------
 | Normalizes the subnormal single-precision floating-point value represented
 | by the denormalized significand `aSig'.  The normalized exponent and
@@ -3635,21 +3649,6 @@  static float32
 
 }
 
-/*----------------------------------------------------------------------------
-| If `a' is denormal and we are in flush-to-zero mode then set the
-| input-denormal exception and return zero. Otherwise just return the value.
-*----------------------------------------------------------------------------*/
-float64 float64_squash_input_denormal(float64 a, float_status *status)
-{
-    if (status->flush_inputs_to_zero) {
-        if (extractFloat64Exp(a) == 0 && extractFloat64Frac(a) != 0) {
-            float_raise(float_flag_input_denormal, status);
-            return make_float64(float64_val(a) & (1ULL << 63));
-        }
-    }
-    return a;
-}
-
 /*----------------------------------------------------------------------------
 | Normalizes the subnormal double-precision floating-point value represented
 | by the denormalized significand `aSig'.  The normalized exponent and
@@ -4981,21 +4980,6 @@  int float32_unordered_quiet(float32 a, float32 b, float_status *status)
     return 0;
 }
 
-/*----------------------------------------------------------------------------
-| If `a' is denormal and we are in flush-to-zero mode then set the
-| input-denormal exception and return zero. Otherwise just return the value.
-*----------------------------------------------------------------------------*/
-float16 float16_squash_input_denormal(float16 a, float_status *status)
-{
-    if (status->flush_inputs_to_zero) {
-        if (extractFloat16Exp(a) == 0 && extractFloat16Frac(a) != 0) {
-            float_raise(float_flag_input_denormal, status);
-            return make_float16(float16_val(a) & 0x8000);
-        }
-    }
-    return a;
-}
-
 /*----------------------------------------------------------------------------
 | Returns the result of converting the double-precision floating-point value
 | `a' to the extended double-precision floating-point format.  The conversion