qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] softfloat: fix floatx80_is_{quiet, signaling}_nan()
@ 2011-01-12 19:59 Aurelien Jarno
  2011-01-12 21:05 ` [Qemu-devel] " Peter Maydell
  0 siblings, 1 reply; 4+ messages in thread
From: Aurelien Jarno @ 2011-01-12 19:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Aurelien Jarno

floatx80_is_{quiet,signaling}_nan() functions are incorrectly detecting
the type of NaN, depending on SNAN_BIT_IS_ONE, one of the two is
returning the correct value, and the other true for any kind of NaN.

This patch fixes that by applying the same kind of comparison as for
other float formats, but taking into account the explicit bit.

Cc: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
---
 fpu/softfloat-specialize.h |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/fpu/softfloat-specialize.h b/fpu/softfloat-specialize.h
index f293f24..50e56b4 100644
--- a/fpu/softfloat-specialize.h
+++ b/fpu/softfloat-specialize.h
@@ -482,7 +482,8 @@ int floatx80_is_quiet_nan( floatx80 a )
         && (bits64) ( aLow<<1 )
         && ( a.low == aLow );
 #else
-    return ( ( a.high & 0x7FFF ) == 0x7FFF ) && (bits64) ( a.low<<1 );
+    return ( ( a.high & 0x7FFF ) == 0x7FFF )
+        && (LIT64( 0x8000000000000000 ) >= ((bits64) ( a.low<<1 )));
 #endif
 }
 
@@ -494,7 +495,8 @@ int floatx80_is_quiet_nan( floatx80 a )
 int floatx80_is_signaling_nan( floatx80 a )
 {
 #if SNAN_BIT_IS_ONE
-    return ( ( a.high & 0x7FFF ) == 0x7FFF ) && (bits64) ( a.low<<1 );
+    return ( ( a.high & 0x7FFF ) == 0x7FFF )
+        && (LIT64( 0x8000000000000000 ) >= ((bits64) ( a.low<<1 )));
 #else
     bits64 aLow;
 
-- 
1.7.2.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Qemu-devel] Re: [PATCH] softfloat: fix floatx80_is_{quiet, signaling}_nan()
  2011-01-12 19:59 [Qemu-devel] [PATCH] softfloat: fix floatx80_is_{quiet, signaling}_nan() Aurelien Jarno
@ 2011-01-12 21:05 ` Peter Maydell
  2011-01-13  7:31   ` Aurelien Jarno
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Maydell @ 2011-01-12 21:05 UTC (permalink / raw)
  To: Aurelien Jarno; +Cc: qemu-devel

On 12 January 2011 13:59, Aurelien Jarno <aurelien@aurel32.net> wrote:

> @@ -494,7 +495,8 @@ int floatx80_is_quiet_nan( floatx80 a )
>  int floatx80_is_signaling_nan( floatx80 a )
>  {
>  #if SNAN_BIT_IS_ONE
> -    return ( ( a.high & 0x7FFF ) == 0x7FFF ) && (bits64) ( a.low<<1 );
> +    return ( ( a.high & 0x7FFF ) == 0x7FFF )
> +        && (LIT64( 0x8000000000000000 ) >= ((bits64) ( a.low<<1 )));
>  #else
>     bits64 aLow;

If a is {0x7ffff,0} (ie +inf) this will return true, which is wrong.
Do you want "<=" instead?

Actually, will
  return ((a.high & 0x7fff) == 0x7fff) && (a.low >= LIT64(0x4000000000000000));
do? Untested but I think it will do the right thing. I'm not sure
why this code has those bit64 casts, incidentally, since a.low is
already a uint64_t.

Also, maybe we should have a comment somewhere explaining
why this is different from the other NaN functions (ie that the
x80 format has an explicit bit and the others don't) ?

-- PMM

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Qemu-devel] Re: [PATCH] softfloat: fix floatx80_is_{quiet, signaling}_nan()
  2011-01-12 21:05 ` [Qemu-devel] " Peter Maydell
@ 2011-01-13  7:31   ` Aurelien Jarno
  2011-01-13 12:15     ` Peter Maydell
  0 siblings, 1 reply; 4+ messages in thread
From: Aurelien Jarno @ 2011-01-13  7:31 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel

On Wed, Jan 12, 2011 at 03:05:10PM -0600, Peter Maydell wrote:
> On 12 January 2011 13:59, Aurelien Jarno <aurelien@aurel32.net> wrote:
> 
> > @@ -494,7 +495,8 @@ int floatx80_is_quiet_nan( floatx80 a )
> >  int floatx80_is_signaling_nan( floatx80 a )
> >  {
> >  #if SNAN_BIT_IS_ONE
> > -    return ( ( a.high & 0x7FFF ) == 0x7FFF ) && (bits64) ( a.low<<1 );
> > +    return ( ( a.high & 0x7FFF ) == 0x7FFF )
> > +        && (LIT64( 0x8000000000000000 ) >= ((bits64) ( a.low<<1 )));
> >  #else
> >     bits64 aLow;
> 
> If a is {0x7ffff,0} (ie +inf) this will return true, which is wrong.
> Do you want "<=" instead?

Correct, I swapped the operands at the last minute to match the other
functions, but without changing the sign.

> Actually, will
>   return ((a.high & 0x7fff) == 0x7fff) && (a.low >= LIT64(0x4000000000000000));
> do? Untested but I think it will do the right thing. I'm not sure

The explicit bit might be one for a NaN, so you should filter it first.

> why this code has those bit64 casts, incidentally, since a.low is
> already a uint64_t.

Don't know either, but as they were already there, I left them.

> Also, maybe we should have a comment somewhere explaining
> why this is different from the other NaN functions (ie that the
> x80 format has an explicit bit and the others don't) ?
> 

Good idea, will do.

-- 
Aurelien Jarno                          GPG: 1024D/F1BCDB73
aurelien@aurel32.net                 http://www.aurel32.net

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Qemu-devel] Re: [PATCH] softfloat: fix floatx80_is_{quiet, signaling}_nan()
  2011-01-13  7:31   ` Aurelien Jarno
@ 2011-01-13 12:15     ` Peter Maydell
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2011-01-13 12:15 UTC (permalink / raw)
  To: Aurelien Jarno; +Cc: qemu-devel

On 13 January 2011 01:31, Aurelien Jarno <aurelien@aurel32.net> wrote:
> On Wed, Jan 12, 2011 at 03:05:10PM -0600, Peter Maydell wrote:
>> Actually, will
>>   return ((a.high & 0x7fff) == 0x7fff) && (a.low >= LIT64(0x4000000000000000));
>> do? Untested but I think it will do the right thing. I'm not sure
>
> The explicit bit might be one for a NaN, so you should filter it first.

Whoops, yes, explicit-bit-set but signalling-bit-clear would be
a false positive.

-- PMM

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-01-13 12:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-12 19:59 [Qemu-devel] [PATCH] softfloat: fix floatx80_is_{quiet, signaling}_nan() Aurelien Jarno
2011-01-12 21:05 ` [Qemu-devel] " Peter Maydell
2011-01-13  7:31   ` Aurelien Jarno
2011-01-13 12:15     ` Peter Maydell

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).