diff mbox

[v2,5/7] softfloat: Rework `*_is_*_nan' functions

Message ID alpine.DEB.1.10.1412121931300.19155@tp.orcam.me.uk
State New
Headers show

Commit Message

Maciej W. Rozycki Dec. 12, 2014, 7:35 p.m. UTC
Precompute the possible results, and then pick the suitable one.  The 
calculation of the unused result will be optimized away by the compiler 
at any reasonable optimization level, so no run-time performance loss.

Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
Signed-off-by: Maciej W. Rozycki <macro@codesourcery.com>
---
Changes from v1:

- regenerate on top of the SoftFloat relicensing patch set.

qemu-softfloat-nan-precompute.diff

Comments

Peter Maydell Feb. 5, 2015, 4:42 p.m. UTC | #1
On 12 December 2014 at 19:35, Maciej W. Rozycki <macro@codesourcery.com> wrote:
> Precompute the possible results, and then pick the suitable one.  The
> calculation of the unused result will be optimized away by the compiler
> at any reasonable optimization level, so no run-time performance loss.
>
> Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
> Signed-off-by: Maciej W. Rozycki <macro@codesourcery.com>

> --- qemu-git-trunk.orig/fpu/softfloat-specialize.h      2014-12-11 22:41:47.118930659 +0000
> +++ qemu-git-trunk/fpu/softfloat-specialize.h   2014-12-11 22:42:29.128941855 +0000
> @@ -207,10 +207,13 @@ int float16_is_signaling_nan(float16 a_
>  int float16_is_quiet_nan(float16 a_ STATUS_PARAM)
>  {
>      uint16_t a = float16_val(a_);
> +    int __attribute__ ((unused)) x, y;
> +    x = (((a >> 9) & 0x3F) == 0x3E) && (a & 0x1FF);
> +    y = (a & ~0x8000) >= 0x7c80;
>  #if SNAN_BIT_IS_ONE
> -    return (((a >> 9) & 0x3F) == 0x3E) && (a & 0x1FF);
> +    return x;
>  #else
> -    return ((a & ~0x8000) >= 0x7c80);
> +    return y;
>  #endif
>  }

I don't really see the point in this patch -- the existing
version of the code seems better to me (doesn't need the
extra __attribute__ ((unused)) variables, for instance).
What's the benefit?

thanks
-- PMM
diff mbox

Patch

Index: qemu-git-trunk/fpu/softfloat-specialize.h
===================================================================
--- qemu-git-trunk.orig/fpu/softfloat-specialize.h	2014-12-11 22:41:47.118930659 +0000
+++ qemu-git-trunk/fpu/softfloat-specialize.h	2014-12-11 22:42:29.128941855 +0000
@@ -207,10 +207,13 @@  int float16_is_signaling_nan(float16 a_ 
 int float16_is_quiet_nan(float16 a_ STATUS_PARAM)
 {
     uint16_t a = float16_val(a_);
+    int __attribute__ ((unused)) x, y;
+    x = (((a >> 9) & 0x3F) == 0x3E) && (a & 0x1FF);
+    y = (a & ~0x8000) >= 0x7c80;
 #if SNAN_BIT_IS_ONE
-    return (((a >> 9) & 0x3F) == 0x3E) && (a & 0x1FF);
+    return x;
 #else
-    return ((a & ~0x8000) >= 0x7c80);
+    return y;
 #endif
 }
 
@@ -222,10 +225,13 @@  int float16_is_quiet_nan(float16 a_ STAT
 int float16_is_signaling_nan(float16 a_ STATUS_PARAM)
 {
     uint16_t a = float16_val(a_);
+    int __attribute__ ((unused)) x, y;
+    x = (a & ~0x8000) >= 0x7c80;
+    y = (((a >> 9) & 0x3F) == 0x3E) && (a & 0x1FF);
 #if SNAN_BIT_IS_ONE
-    return ((a & ~0x8000) >= 0x7c80);
+    return x;
 #else
-    return (((a >> 9) & 0x3F) == 0x3E) && (a & 0x1FF);
+    return y;
 #endif
 }
 #endif
@@ -311,10 +317,13 @@  int float32_is_signaling_nan(float32 a_ 
 int float32_is_quiet_nan(float32 a_ STATUS_PARAM)
 {
     uint32_t a = float32_val(a_);
+    int __attribute__ ((unused)) x, y;
+    x = (((a >> 22) & 0x1ff) == 0x1fe) && (a & 0x003fffff);
+    y = (uint32_t)(a << 1) >= 0xff800000;
 #if SNAN_BIT_IS_ONE
-    return (((a >> 22) & 0x1ff) == 0x1fe) && (a & 0x003fffff);
+    return x;
 #else
-    return ((uint32_t)(a << 1) >= 0xff800000);
+    return y;
 #endif
 }
 
@@ -326,10 +335,13 @@  int float32_is_quiet_nan(float32 a_ STAT
 int float32_is_signaling_nan(float32 a_ STATUS_PARAM)
 {
     uint32_t a = float32_val(a_);
+    int __attribute__ ((unused)) x, y;
+    x = (uint32_t)(a << 1) >= 0xff800000;
+    y = (((a >> 22) & 0x1FF) == 0x1FE) && (a & 0x003FFFFF);
 #if SNAN_BIT_IS_ONE
-    return ((uint32_t)(a << 1) >= 0xff800000);
+    return x;
 #else
-    return ( ( ( a>>22 ) & 0x1FF ) == 0x1FE ) && ( a & 0x003FFFFF );
+    return y;
 #endif
 }
 #endif
@@ -721,11 +733,13 @@  int float64_is_signaling_nan(float64 a_ 
 int float64_is_quiet_nan(float64 a_ STATUS_PARAM)
 {
     uint64_t a = float64_val(a_);
+    int __attribute__ ((unused)) x, y;
+    x = (((a >> 51) & 0xfff) == 0xffe) && (a & 0x0007ffffffffffffULL);
+    y = (a << 1) >= 0xfff0000000000000ULL;
 #if SNAN_BIT_IS_ONE
-    return (((a >> 51) & 0xfff) == 0xffe)
-           && (a & 0x0007ffffffffffffULL);
+    return x;
 #else
-    return ((a << 1) >= 0xfff0000000000000ULL);
+    return y;
 #endif
 }
 
@@ -737,12 +751,13 @@  int float64_is_quiet_nan(float64 a_ STAT
 int float64_is_signaling_nan(float64 a_ STATUS_PARAM)
 {
     uint64_t a = float64_val(a_);
+    int __attribute__ ((unused)) x, y;
+    x = ((a << 1) >= 0xfff0000000000000ULL);
+    y = (((a >> 51) & 0xFFF) == 0xFFE) && (a & LIT64(0x0007FFFFFFFFFFFF));
 #if SNAN_BIT_IS_ONE
-    return ((a << 1) >= 0xfff0000000000000ULL);
+    return x;
 #else
-    return
-           ( ( ( a>>51 ) & 0xFFF ) == 0xFFE )
-        && ( a & LIT64( 0x0007FFFFFFFFFFFF ) );
+    return y;
 #endif
 }
 #endif
@@ -921,16 +936,18 @@  int floatx80_is_signaling_nan(floatx80 a
 
 int floatx80_is_quiet_nan(floatx80 a STATUS_PARAM)
 {
-#if SNAN_BIT_IS_ONE
     uint64_t aLow;
-
+    int __attribute__ ((unused)) x, y;
     aLow = a.low & ~0x4000000000000000ULL;
-    return ((a.high & 0x7fff) == 0x7fff)
+    x = ((a.high & 0x7fff) == 0x7fff)
         && (aLow << 1)
         && (a.low == aLow);
+    y = ((a.high & 0x7FFF) == 0x7FFF)
+        && (LIT64(0x8000000000000000) <= ((uint64_t) (a.low << 1)));
+#if SNAN_BIT_IS_ONE
+    return x;
 #else
-    return ( ( a.high & 0x7FFF ) == 0x7FFF )
-        && (LIT64( 0x8000000000000000 ) <= ((uint64_t) ( a.low<<1 )));
+    return y;
 #endif
 }
 
@@ -942,17 +959,18 @@  int floatx80_is_quiet_nan(floatx80 a STA
 
 int floatx80_is_signaling_nan(floatx80 a STATUS_PARAM)
 {
-#if SNAN_BIT_IS_ONE
-    return ((a.high & 0x7fff) == 0x7fff)
+    uint64_t aLow;
+    int __attribute__ ((unused)) x, y;
+    aLow = a.low & ~LIT64(0x4000000000000000);
+    x = ((a.high & 0x7fff) == 0x7fff)
         && ((a.low << 1) >= 0x8000000000000000ULL);
+    y = ((a.high & 0x7FFF) == 0x7FFF)
+        && (uint64_t) (aLow << 1)
+        && (a.low == aLow);
+#if SNAN_BIT_IS_ONE
+    return x;
 #else
-    uint64_t aLow;
-
-    aLow = a.low & ~ LIT64( 0x4000000000000000 );
-    return
-           ( ( a.high & 0x7FFF ) == 0x7FFF )
-        && (uint64_t) ( aLow<<1 )
-        && ( a.low == aLow );
+    return y;
 #endif
 }
 #endif
@@ -1081,13 +1099,15 @@  int float128_is_signaling_nan(float128 a
 
 int float128_is_quiet_nan(float128 a STATUS_PARAM)
 {
-#if SNAN_BIT_IS_ONE
-    return (((a.high >> 47) & 0xffff) == 0xfffe)
+    int __attribute__ ((unused)) x, y;
+    x = (((a.high >> 47) & 0xffff) == 0xfffe)
         && (a.low || (a.high & 0x00007fffffffffffULL));
-#else
-    return
-        ((a.high << 1) >= 0xffff000000000000)
+    y = ((a.high << 1) >= 0xffff000000000000)
         && (a.low || (a.high & 0x0000ffffffffffffULL));
+#if SNAN_BIT_IS_ONE
+    return x;
+#else
+    return y;
 #endif
 }
 
@@ -1098,14 +1118,15 @@  int float128_is_quiet_nan(float128 a STA
 
 int float128_is_signaling_nan(float128 a STATUS_PARAM)
 {
-#if SNAN_BIT_IS_ONE
-    return
-        ((a.high << 1) >= 0xffff000000000000)
+    int __attribute__ ((unused)) x, y;
+    x = ((a.high << 1) >= 0xffff000000000000)
         && (a.low || (a.high & 0x0000ffffffffffffULL));
+    y = (((a.high >> 47) & 0xFFFF) == 0xFFFE)
+        && (a.low || (a.high & LIT64(0x00007FFFFFFFFFFF)));
+#if SNAN_BIT_IS_ONE
+    return x;
 #else
-    return
-           ( ( ( a.high>>47 ) & 0xFFFF ) == 0xFFFE )
-        && ( a.low || ( a.high & LIT64( 0x00007FFFFFFFFFFF ) ) );
+    return y;
 #endif
 }
 #endif