diff mbox series

[v3,03/13] fpu: optimise float[16/32/64]_squash_denormal (HACK?)

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

Commit Message

Alex Bennée Aug. 13, 2019, 12:49 p.m. UTC
Using the floatXX_pack_raw functions is slight overkill for basically
just masking out all but the top bit of the number. This makes the
final code exactly the same as pre-conversion.

TODO: is this worth it, can the compiler do better with make_float?

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

---
 fpu/softfloat.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

-- 
2.20.1

Comments

Richard Henderson Aug. 13, 2019, 1:12 p.m. UTC | #1
On 8/13/19 1:49 PM, Alex Bennée wrote:
> Using the floatXX_pack_raw functions is slight overkill for basically

> just masking out all but the top bit of the number. This makes the

> final code exactly the same as pre-conversion.

> 

> TODO: is this worth it, can the compiler do better with make_float?

> 

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

> ---

>  fpu/softfloat.c | 22 ++++++++++++----------

>  1 file changed, 12 insertions(+), 10 deletions(-)


Hah.  I just suggested something similar vs patch 2.


r~
diff mbox series

Patch

diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index 0a434555cd8..9e57b7b5933 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -3294,23 +3294,23 @@  float64 float64_silence_nan(float64 a, float_status *status)
 | input-denormal exception and return zero. Otherwise just return the value.
 *----------------------------------------------------------------------------*/
 
-static FloatParts parts_squash_denormal(FloatParts p, float_status *status)
+static bool 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 true;
     }
 
-    return p;
+    return false;
 }
 
 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);
+        if (parts_squash_denormal(p, status)) {
+            a = make_float16(float16_val(a) & 0x8000);
+        }
     }
     return a;
 }
@@ -3319,8 +3319,9 @@  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);
+        if (parts_squash_denormal(p, status)) {
+            a = make_float32(float32_val(a) & 0x80000000);
+        }
     }
     return a;
 }
@@ -3329,8 +3330,9 @@  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);
+        if (parts_squash_denormal(p, status)) {
+            a = make_float64(float64_val(a) & (1ULL << 63));
+        }
     }
     return a;
 }