From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Richard Henderson" <rth@twiddle.net>,
patches@linaro.org, "Max Filippov" <jcmvbkbc@gmail.com>,
"Richard Sandiford" <rdsandiford@googlemail.com>,
"Paul Brook" <paul@codesourcery.com>,
"Juan Quintela" <quintela@redhat.com>,
"Blue Swirl" <blauwirbel@gmail.com>,
"Christophe Lyon" <christophe.lyon@st.com>,
"Anthony Liguori" <aliguori@amazon.com>,
"Stefan Weil" <sw@weilnetz.de>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Guan Xuetao" <gxt@mprc.pku.edu.cn>,
"Andreas Färber" <afaerber@suse.de>,
"Aurelien Jarno" <aurelien@aurel32.net>,
"Avi Kivity" <avi.kivity@gmail.com>
Subject: [Qemu-devel] [PATCH 5/6] softfloat: reimplement SNAN_BIT_IS_ONE support
Date: Tue, 25 Nov 2014 14:17:36 +0000 [thread overview]
Message-ID: <1416925057-692-6-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1416925057-692-1-git-send-email-peter.maydell@linaro.org>
Reimplement support for architectures where the most significant bit
in the mantissa is 1 for a signaling NaN rather than a quiet NaN,
by adding handling for SNAN_BIT_IS_ONE being set to the functions
which test values for NaN-ness.
This includes restoring the bugfixes lost in the reversion where
some of the float*_is_quiet_nan() functions were returning true
for both signaling and quiet NaNs.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
fpu/softfloat-specialize.h | 74 +++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 70 insertions(+), 4 deletions(-)
diff --git a/fpu/softfloat-specialize.h b/fpu/softfloat-specialize.h
index 187cdf6..6de66ce 100644
--- a/fpu/softfloat-specialize.h
+++ b/fpu/softfloat-specialize.h
@@ -33,6 +33,16 @@ this code that are retained.
===============================================================================
*/
+/* Does the target distinguish signaling NaNs from non-signaling NaNs
+ * by setting the most significant bit of the mantissa for a signaling NaN?
+ * (The more common choice is to have it be zero for SNaN and one for QNaN.)
+ */
+#if defined(TARGET_MIPS) || defined(TARGET_SH4) || defined(TARGET_UNICORE32)
+#define SNAN_BIT_IS_ONE 1
+#else
+#define SNAN_BIT_IS_ONE 0
+#endif
+
#if defined(TARGET_XTENSA)
/* Define for architectures which deviate from IEEE in not supporting
* signaling NaNs (so all NaNs are treated as quiet).
@@ -59,6 +69,8 @@ const float32 float32_default_nan = const_float32(0x7FFFFFFF);
#elif defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_ALPHA) || \
defined(TARGET_XTENSA)
const float32 float32_default_nan = const_float32(0x7FC00000);
+#elif SNAN_BIT_IS_ONE
+const float32 float32_default_nan = const_float32(0xFF800000);
#else
const float32 float32_default_nan = const_float32(0xFFC00000);
#endif
@@ -70,6 +82,8 @@ const float32 float32_default_nan = const_float32(0xFFC00000);
const float64 float64_default_nan = const_float64(LIT64( 0x7FFFFFFFFFFFFFFF ));
#elif defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_ALPHA)
const float64 float64_default_nan = const_float64(LIT64( 0x7FF8000000000000 ));
+#elif SNAN_BIT_IS_ONE
+const float64 float64_default_nan = const_float64(LIT64(0xFFF0000000000000));
#else
const float64 float64_default_nan = const_float64(LIT64( 0xFFF8000000000000 ));
#endif
@@ -77,8 +91,13 @@ const float64 float64_default_nan = const_float64(LIT64( 0xFFF8000000000000 ));
/*----------------------------------------------------------------------------
| The pattern for a default generated extended double-precision NaN.
*----------------------------------------------------------------------------*/
+#if SNAN_BIT_IS_ONE
+#define floatx80_default_nan_high 0xFFFF
+#define floatx80_default_nan_low LIT64(0x8000000000000000)
+#else
#define floatx80_default_nan_high 0xFFFF
#define floatx80_default_nan_low LIT64( 0xC000000000000000 )
+#endif
const floatx80 floatx80_default_nan
= make_floatx80_init(floatx80_default_nan_high, floatx80_default_nan_low);
@@ -87,8 +106,13 @@ const floatx80 floatx80_default_nan
| The pattern for a default generated quadruple-precision NaN. The `high' and
| `low' values hold the most- and least-significant bits, respectively.
*----------------------------------------------------------------------------*/
+#if SNAN_BIT_IS_ONE
+#define float128_default_nan_high LIT64(0xFFFF000000000000)
+#define float128_default_nan_low LIT64(0x0000000000000000)
+#else
#define float128_default_nan_high LIT64( 0xFFFF800000000000 )
#define float128_default_nan_low LIT64( 0x0000000000000000 )
+#endif
const float128 float128_default_nan
= make_float128_init(float128_default_nan_high, float128_default_nan_low);
@@ -234,7 +258,11 @@ int float32_is_signaling_nan(float32 a_)
int float32_is_quiet_nan( float32 a_ )
{
uint32_t a = float32_val(a_);
- return ( 0xFF000000 <= (uint32_t) ( a<<1 ) );
+#if SNAN_BIT_IS_ONE
+ return (((a >> 22) & 0x1ff) == 0x1fe) && (a & 0x003fffff);
+#else
+ return ((uint32_t)(a << 1) >= 0xff800000);
+#endif
}
/*----------------------------------------------------------------------------
@@ -245,7 +273,11 @@ int float32_is_quiet_nan( float32 a_ )
int float32_is_signaling_nan( float32 a_ )
{
uint32_t a = float32_val(a_);
+#if SNAN_BIT_IS_ONE
+ return ((uint32_t)(a << 1) >= 0xff800000);
+#else
return ( ( ( a>>22 ) & 0x1FF ) == 0x1FE ) && ( a & 0x003FFFFF );
+#endif
}
#endif
@@ -634,7 +666,12 @@ int float64_is_signaling_nan(float64 a_)
int float64_is_quiet_nan( float64 a_ )
{
uint64_t a = float64_val(a_);
- return ( LIT64( 0xFFE0000000000000 ) <= (uint64_t) ( a<<1 ) );
+#if SNAN_BIT_IS_ONE
+ return (((a >> 51) & 0xfff) == 0xffe)
+ && (a & 0x0007ffffffffffffULL);
+#else
+ return ((a << 1) >= 0xfff0000000000000ULL);
+#endif
}
/*----------------------------------------------------------------------------
@@ -645,9 +682,13 @@ int float64_is_quiet_nan( float64 a_ )
int float64_is_signaling_nan( float64 a_ )
{
uint64_t a = float64_val(a_);
+#if SNAN_BIT_IS_ONE
+ return ((a << 1) >= 0xfff0000000000000ULL);
+#else
return
( ( ( a>>51 ) & 0xFFF ) == 0xFFE )
&& ( a & LIT64( 0x0007FFFFFFFFFFFF ) );
+#endif
}
#endif
@@ -823,8 +864,17 @@ int floatx80_is_signaling_nan(floatx80 a_)
int floatx80_is_quiet_nan( floatx80 a )
{
+#if SNAN_BIT_IS_ONE
+ uint64_t aLow;
+
+ aLow = a.low & ~0x4000000000000000ULL;
+ return ((a.high & 0x7fff) == 0x7fff)
+ && (aLow << 1)
+ && (a.low == aLow);
+#else
return ( ( a.high & 0x7FFF ) == 0x7FFF )
&& (LIT64( 0x8000000000000000 ) <= ((uint64_t) ( a.low<<1 )));
+#endif
}
/*----------------------------------------------------------------------------
@@ -835,6 +885,10 @@ int floatx80_is_quiet_nan( floatx80 a )
int floatx80_is_signaling_nan( floatx80 a )
{
+#if SNAN_BIT_IS_ONE
+ return ((a.high & 0x7fff) == 0x7fff)
+ && ((a.low << 1) >= 0x8000000000000000ULL);
+#else
uint64_t aLow;
aLow = a.low & ~ LIT64( 0x4000000000000000 );
@@ -842,6 +896,7 @@ int floatx80_is_signaling_nan( floatx80 a )
( ( a.high & 0x7FFF ) == 0x7FFF )
&& (uint64_t) ( aLow<<1 )
&& ( a.low == aLow );
+#endif
}
#endif
@@ -975,9 +1030,14 @@ int float128_is_signaling_nan(float128 a_)
int float128_is_quiet_nan( float128 a )
{
+#if SNAN_BIT_IS_ONE
+ return (((a.high >> 47) & 0xffff) == 0xfffe)
+ && (a.low || (a.high & 0x00007fffffffffffULL));
+#else
return
- ( LIT64( 0xFFFE000000000000 ) <= (uint64_t) ( a.high<<1 ) )
- && ( a.low || ( a.high & LIT64( 0x0000FFFFFFFFFFFF ) ) );
+ ((a.high << 1) >= 0xffff000000000000)
+ && (a.low || (a.high & 0x0000ffffffffffffULL));
+#endif
}
/*----------------------------------------------------------------------------
@@ -987,9 +1047,15 @@ int float128_is_quiet_nan( float128 a )
int float128_is_signaling_nan( float128 a )
{
+#if SNAN_BIT_IS_ONE
+ return
+ ((a.high << 1) >= 0xffff000000000000)
+ && (a.low || (a.high & 0x0000ffffffffffffULL));
+#else
return
( ( ( a.high>>47 ) & 0xFFFF ) == 0xFFFE )
&& ( a.low || ( a.high & LIT64( 0x00007FFFFFFFFFFF ) ) );
+#endif
}
#endif
--
1.9.1
next prev parent reply other threads:[~2014-11-25 14:45 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-25 14:17 [Qemu-devel] [PATCH 0/6] relicense QEMU softfloat from 2b to to 2a Peter Maydell
2014-11-25 14:17 ` [Qemu-devel] [PATCH 1/6] softfloat: Apply patch corresponding to rebasing to softfloat-2a Peter Maydell
2014-11-25 14:17 ` [Qemu-devel] [PATCH 2/6] softfloat: Revert remaining portions of commits 75d62a5856 and 3430b0be36f Peter Maydell
2014-11-25 14:17 ` [Qemu-devel] [PATCH 3/6] softfloat: Revert remaining parts of commits b645bb4885 and 5a6932d51d Peter Maydell
2014-11-25 14:17 ` [Qemu-devel] [PATCH 4/6] softfloat: Implement uint64_to_float64() and uint64_to_float32() Peter Maydell
2014-11-25 14:17 ` Peter Maydell [this message]
2014-12-11 16:41 ` [Qemu-devel] [PATCH 5/6] softfloat: reimplement SNAN_BIT_IS_ONE support Maciej W. Rozycki
2014-12-11 18:02 ` Peter Maydell
2014-11-25 14:17 ` [Qemu-devel] [PATCH 6/6] softfloat: Clarify license status Peter Maydell
2014-12-05 11:15 ` [Qemu-devel] [PATCH 0/6] relicense QEMU softfloat from 2b to to 2a Peter Maydell
2014-12-17 14:06 ` Peter Maydell
2015-01-05 11:03 ` Peter Maydell
2015-01-07 6:13 ` Paolo Bonzini
2015-01-07 10:34 ` Peter Maydell
2015-01-07 11:04 ` Paolo Bonzini
2015-01-07 16:23 ` Peter Maydell
2015-01-07 16:29 ` Paolo Bonzini
2015-01-07 16:34 ` Peter Maydell
2015-01-07 16:49 ` Paolo Bonzini
2015-01-12 12:53 ` Peter Maydell
2015-01-12 12:55 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1416925057-692-6-git-send-email-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=afaerber@suse.de \
--cc=aliguori@amazon.com \
--cc=aurelien@aurel32.net \
--cc=avi.kivity@gmail.com \
--cc=blauwirbel@gmail.com \
--cc=christophe.lyon@st.com \
--cc=gxt@mprc.pku.edu.cn \
--cc=jcmvbkbc@gmail.com \
--cc=patches@linaro.org \
--cc=paul@codesourcery.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=rdsandiford@googlemail.com \
--cc=rth@twiddle.net \
--cc=sw@weilnetz.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).