From: Aurelien Jarno <aurelien@aurel32.net>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 01/20] softfloat: fix floatx80 handling of NaN
Date: Wed, 20 Apr 2011 11:02:44 +0200 [thread overview]
Message-ID: <20110420090243.GA6388@volta.aurel32.net> (raw)
In-Reply-To: <BANLkTinYQ=zcO-zoZvBHrVT7q0hA2ZejAA@mail.gmail.com>
On Tue, Apr 19, 2011 at 11:53:50AM +0100, Peter Maydell wrote:
> On 18 April 2011 21:59, Aurelien Jarno <aurelien@aurel32.net> wrote:
> > The floatx80 format uses an explicit bit that should be taken into account
> > when converting to and from commonNaN format.
> >
> > When converting to commonNaN, the explicit bit should be removed if it is
> > a 1, and a default NaN should be used if it is 0.
> >
> > When converting from commonNan, the explicit bit should be added.
> >
> > Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
> > ---
> > fpu/softfloat-specialize.h | 19 +++++++++++++------
> > 1 files changed, 13 insertions(+), 6 deletions(-)
> >
> > diff --git a/fpu/softfloat-specialize.h b/fpu/softfloat-specialize.h
> > index b110187..fb2b5b4 100644
> > --- a/fpu/softfloat-specialize.h
> > +++ b/fpu/softfloat-specialize.h
> > @@ -603,9 +603,15 @@ static commonNaNT floatx80ToCommonNaN( floatx80 a STATUS_PARAM)
> > commonNaNT z;
> >
> > if ( floatx80_is_signaling_nan( a ) ) float_raise( float_flag_invalid STATUS_VAR);
> > - z.sign = a.high>>15;
> > - z.low = 0;
> > - z.high = a.low;
> > + if ( a.low >> 63 ) {
> > + z.sign = a.high >> 15;
> > + z.low = 0;
> > + z.high = a.low << 1;
> > + } else {
> > + z.sign = floatx80_default_nan_high >> 15;
> > + z.low = 0;
> > + z.high = floatx80_default_nan_low << 1;
> > + }
> > return z;
> > }
>
> The intel manuals don't seem to define what a number with non-zero exponent
> field but explicit bit clear actually means. Presumably this (generate a
> default NaN) is what the hardware does if you try to convert such a thing
> to float64?
I tested that on my hardware, on an Intel CPU, and it behaves like that.
> > @@ -624,10 +630,11 @@ static floatx80 commonNaNToFloatx80( commonNaNT a STATUS_PARAM)
> > return z;
> > }
> >
> > - if (a.high)
> > - z.low = a.high;
> > - else
> > + if (a.high) {
> > + z.low = LIT64( 0x8000000000000000 ) | a.high >> 1;
> > + } else {
> > z.low = floatx80_default_nan_low;
> > + }
> > z.high = ( ( (uint16_t) a.sign )<<15 ) | 0x7FFF;
> > return z;
> > }
>
> I think the condition here should be "if (a.high >> 1)" -- otherwise we
> might construct an infinity instead (explicit bit 1 but all fraction bits 0).
> Also we are keeping the sign of the input even if we return the default
> NaN. It might be better to start with
> uint64_t mantissa = a.high >> 1;
> and then roll the 'mantissa == 0' check into the default_nan_mode if().
>
Correct, good catch. Will fix that in v2.
--
Aurelien Jarno GPG: 1024D/F1BCDB73
aurelien@aurel32.net http://www.aurel32.net
next prev parent reply other threads:[~2011-04-20 9:03 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-18 20:59 [Qemu-devel] [PATCH 00/20] target-i386 conversion to softfloat Aurelien Jarno
2011-04-18 20:59 ` [Qemu-devel] [PATCH 01/20] softfloat: fix floatx80 handling of NaN Aurelien Jarno
2011-04-19 10:53 ` Peter Maydell
2011-04-20 9:02 ` Aurelien Jarno [this message]
2011-04-18 20:59 ` [Qemu-devel] [PATCH 02/20] softfloat: fix floatx80_is_infinity() Aurelien Jarno
2011-04-19 10:55 ` Peter Maydell
2011-04-18 20:59 ` [Qemu-devel] [PATCH 03/20] softfloat: add floatx80 constants Aurelien Jarno
2011-04-19 11:07 ` Peter Maydell
2011-04-20 9:05 ` Aurelien Jarno
2011-04-18 20:59 ` [Qemu-devel] [PATCH 04/20] softfloat: add pi constants Aurelien Jarno
2011-04-19 11:10 ` Peter Maydell
2011-04-20 9:05 ` Aurelien Jarno
2011-04-18 20:59 ` [Qemu-devel] [PATCH 05/20] softfloat-native: add a few constant values Aurelien Jarno
2011-04-19 11:12 ` Peter Maydell
2011-04-18 20:59 ` [Qemu-devel] [PATCH 06/20] softfloat: add floatx80_compare*() functions Aurelien Jarno
2011-04-19 11:16 ` Peter Maydell
2011-04-18 20:59 ` [Qemu-devel] [PATCH 07/20] softfloat: fix float*_scalnb() corner cases Aurelien Jarno
2011-04-19 11:57 ` Peter Maydell
2011-04-20 9:21 ` Aurelien Jarno
2011-04-18 21:00 ` [Qemu-devel] [PATCH 08/20] softfloat-native: fix float*_scalbn() functions Aurelien Jarno
2011-04-19 12:35 ` Peter Maydell
2011-04-18 21:00 ` [Qemu-devel] [PATCH 09/20] softfloat-native: add float*_is_any_nan() functions Aurelien Jarno
2011-04-19 12:42 ` Peter Maydell
2011-04-20 9:22 ` Aurelien Jarno
2011-04-18 21:00 ` [Qemu-devel] [PATCH 10/20] target-i386: fix helper_fscale() wrt softfloat Aurelien Jarno
2011-04-19 16:57 ` Peter Maydell
2011-04-18 21:00 ` [Qemu-devel] [PATCH 11/20] target-i386: fix helper_flbd_ST0() " Aurelien Jarno
2011-04-19 17:06 ` Peter Maydell
2011-04-20 9:37 ` Aurelien Jarno
2011-04-18 21:00 ` [Qemu-devel] [PATCH 12/20] target-i386: fix helper_fxtract() " Aurelien Jarno
2011-04-19 17:46 ` Peter Maydell
2011-04-18 21:00 ` [Qemu-devel] [PATCH 13/20] target-i386: fix helper_fdiv() " Aurelien Jarno
2011-04-19 17:11 ` Peter Maydell
2011-04-20 9:37 ` Aurelien Jarno
2011-04-18 21:00 ` [Qemu-devel] [PATCH 14/20] target-i386: fix helper_fsqrt() " Aurelien Jarno
2011-04-19 17:13 ` Peter Maydell
2011-04-18 21:00 ` [Qemu-devel] [PATCH 15/20] target-i386: replace approx_rsqrt and approx_rcp by softfloat ops Aurelien Jarno
2011-04-19 17:20 ` Peter Maydell
2011-04-18 21:00 ` [Qemu-devel] [PATCH 16/20] target-i386: add CPU86_LDouble <-> double conversion functions Aurelien Jarno
2011-04-19 17:31 ` Peter Maydell
2011-04-18 21:00 ` [Qemu-devel] [PATCH 17/20] target-i386: fix logarithmic and trigonometric helpers wrt softfloat Aurelien Jarno
2011-04-19 17:37 ` Peter Maydell
2011-04-20 9:41 ` Aurelien Jarno
2011-04-18 21:00 ` [Qemu-devel] [PATCH 18/20] target-i386: fix helper_fprem() and helper_fprem1() " Aurelien Jarno
2011-04-19 17:41 ` Peter Maydell
2011-04-18 21:00 ` [Qemu-devel] [PATCH 19/20] target-i386: fix constants " Aurelien Jarno
2011-04-19 17:26 ` Peter Maydell
2011-04-18 21:00 ` [Qemu-devel] [PATCH 20/20] target-i386: switch to softfloat Aurelien Jarno
2011-04-19 17:28 ` Peter Maydell
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=20110420090243.GA6388@volta.aurel32.net \
--to=aurelien@aurel32.net \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.