[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 5/7] softfloat: Rework `*_is_*_nan' functions
From: |
Maciej W. Rozycki |
Subject: |
[Qemu-devel] [PATCH 5/7] softfloat: Rework `*_is_*_nan' functions |
Date: |
Tue, 9 Dec 2014 01:55:41 +0000 |
User-agent: |
Alpine 1.10 (DEB 962 2008-03-14) |
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 <address@hidden>
Signed-off-by: Maciej W. Rozycki <address@hidden>
---
qemu-softfloat-nan-precompute.diff
Index: qemu-git-trunk/fpu/softfloat-specialize.h
===================================================================
--- qemu-git-trunk.orig/fpu/softfloat-specialize.h 2014-12-01
21:58:05.937673826 +0000
+++ qemu-git-trunk/fpu/softfloat-specialize.h 2014-12-01 22:58:50.328200913
+0000
@@ -159,10 +159,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
}
@@ -174,10 +177,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
@@ -263,10 +269,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 = 0xFF800000 <= (uint32_t) (a << 1);
#if SNAN_BIT_IS_ONE
- return ( ( ( a>>22 ) & 0x1FF ) == 0x1FE ) && ( a & 0x003FFFFF );
+ return x;
#else
- return ( 0xFF800000 <= (uint32_t) ( a<<1 ) );
+ return y;
#endif
}
@@ -278,10 +287,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 = 0xFF800000 <= (uint32_t) (a << 1);
+ y = (((a >> 22) & 0x1FF) == 0x1FE) && (a & 0x003FFFFF);
#if SNAN_BIT_IS_ONE
- return ( 0xFF800000 <= (uint32_t) ( a<<1 ) );
+ return x;
#else
- return ( ( ( a>>22 ) & 0x1FF ) == 0x1FE ) && ( a & 0x003FFFFF );
+ return y;
#endif
}
#endif
@@ -673,12 +685,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 & LIT64(0x0007FFFFFFFFFFFF));
+ y = LIT64(0xFFF0000000000000) <= (uint64_t) (a << 1);
#if SNAN_BIT_IS_ONE
- return
- ( ( ( a>>51 ) & 0xFFF ) == 0xFFE )
- && ( a & LIT64( 0x0007FFFFFFFFFFFF ) );
+ return x;
#else
- return ( LIT64( 0xFFF0000000000000 ) <= (uint64_t) ( a<<1 ) );
+ return y;
#endif
}
@@ -690,12 +703,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 = LIT64(0xFFF0000000000000) <= (uint64_t) (a << 1);
+ y = (((a >> 51) & 0xFFF) == 0xFFE) && (a & LIT64(0x0007FFFFFFFFFFFF));
#if SNAN_BIT_IS_ONE
- return ( LIT64( 0xFFF0000000000000 ) <= (uint64_t) ( a<<1 ) );
+ return x;
#else
- return
- ( ( ( a>>51 ) & 0xFFF ) == 0xFFE )
- && ( a & LIT64( 0x0007FFFFFFFFFFFF ) );
+ return y;
#endif
}
#endif
@@ -874,17 +888,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;
-
- aLow = a.low & ~ LIT64( 0x4000000000000000 );
- return
- ( ( a.high & 0x7FFF ) == 0x7FFF )
- && (uint64_t) ( aLow<<1 )
- && ( a.low == aLow );
+ int __attribute__ ((unused)) x, y;
+ aLow = a.low & ~LIT64(0x4000000000000000);
+ x = (((a.high & 0x7FFF) == 0x7FFF)
+ && (uint64_t) (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
}
@@ -896,17 +911,18 @@ int floatx80_is_quiet_nan(floatx80 a STA
int floatx80_is_signaling_nan(floatx80 a STATUS_PARAM)
{
+ uint64_t aLow;
+ int __attribute__ ((unused)) x, y;
+ aLow = a.low & ~LIT64(0x4000000000000000);
+ x = (((a.high & 0x7FFF) == 0x7FFF)
+ && (LIT64(0x8000000000000000) <= ((uint64_t) (a.low << 1))));
+ y = (((a.high & 0x7FFF) == 0x7FFF)
+ && (uint64_t) (aLow << 1)
+ && (a.low == aLow));
#if SNAN_BIT_IS_ONE
- return ( ( a.high & 0x7FFF ) == 0x7FFF )
- && (LIT64( 0x8000000000000000 ) <= ((uint64_t) ( a.low<<1 )));
+ 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
@@ -1035,14 +1051,15 @@ int float128_is_signaling_nan(float128 a
int float128_is_quiet_nan(float128 a STATUS_PARAM)
{
+ int __attribute__ ((unused)) x, y;
+ x = ((((a.high >> 47) & 0xFFFF) == 0xFFFE)
+ && (a.low || (a.high & LIT64(0x00007FFFFFFFFFFF))));
+ y = ((LIT64(0xFFFE000000000000) <= (uint64_t) (a.high << 1))
+ && (a.low || (a.high & LIT64(0x0000FFFFFFFFFFFF))));
#if SNAN_BIT_IS_ONE
- return
- ( ( ( a.high>>47 ) & 0xFFFF ) == 0xFFFE )
- && ( a.low || ( a.high & LIT64( 0x00007FFFFFFFFFFF ) ) );
+ return x;
#else
- return
- ( LIT64( 0xFFFE000000000000 ) <= (uint64_t) ( a.high<<1 ) )
- && ( a.low || ( a.high & LIT64( 0x0000FFFFFFFFFFFF ) ) );
+ return y;
#endif
}
@@ -1053,14 +1070,15 @@ int float128_is_quiet_nan(float128 a STA
int float128_is_signaling_nan(float128 a STATUS_PARAM)
{
+ int __attribute__ ((unused)) x, y;
+ x = ((LIT64(0xFFFE000000000000) <= (uint64_t) (a.high << 1))
+ && (a.low || (a.high & LIT64(0x0000FFFFFFFFFFFF))));
+ y = ((((a.high >> 47) & 0xFFFF) == 0xFFFE)
+ && (a.low || (a.high & LIT64(0x00007FFFFFFFFFFF))));
#if SNAN_BIT_IS_ONE
- return
- ( LIT64( 0xFFFE000000000000 ) <= (uint64_t) ( a.high<<1 ) )
- && ( a.low || ( a.high & LIT64( 0x0000FFFFFFFFFFFF ) ) );
+ return x;
#else
- return
- ( ( ( a.high>>47 ) & 0xFFFF ) == 0xFFFE )
- && ( a.low || ( a.high & LIT64( 0x00007FFFFFFFFFFF ) ) );
+ return y;
#endif
}
#endif
- [Qemu-devel] [PATCH 0/7] MIPS: IEEE 754-2008 features support, Maciej W. Rozycki, 2014/12/08
- [Qemu-devel] [PATCH 1/7] softfloat: Fix sNaN handling in FP conversion operations, Maciej W. Rozycki, 2014/12/08
- [Qemu-devel] [PATCH 2/7] softfloat: Simplify `floatx80ToCommonNaN' function, Maciej W. Rozycki, 2014/12/08
- [Qemu-devel] [PATCH 3/7] softfloat: Convert `*_default_nan' variables into inline functions, Maciej W. Rozycki, 2014/12/08
- [Qemu-devel] [PATCH 4/7] softfloat: Add SoftFloat status parameter to `*_nan' functions, Maciej W. Rozycki, 2014/12/08
- [Qemu-devel] [PATCH 5/7] softfloat: Rework `*_is_*_nan' functions,
Maciej W. Rozycki <=
- [Qemu-devel] [PATCH 6/7] softfloat: Add SoftFloat status `nan2008_mode' flag, Maciej W. Rozycki, 2014/12/08
- [Qemu-devel] [PATCH 7/7] target-mips: Add IEEE 754-2008 features support, Maciej W. Rozycki, 2014/12/08
- Re: [Qemu-devel] [PATCH 0/7] MIPS: IEEE 754-2008 features support, Peter Maydell, 2014/12/09