All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aurelien Jarno <aurelien@aurel32.net>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: patches@linaro.org, qemu-devel@nongnu.org,
	Richard Henderson <rth@twiddle.net>
Subject: Re: [Qemu-devel] [PATCH v2] softfloat: Fix factor 2 error for scalbn on denormal inputs
Date: Sun, 22 Dec 2013 17:38:15 +0100	[thread overview]
Message-ID: <20131222163815.GD4326@ohm.rr44.fr> (raw)
In-Reply-To: <1387660099-22390-1-git-send-email-peter.maydell@linaro.org>

On Sat, Dec 21, 2013 at 09:08:19PM +0000, Peter Maydell wrote:
> If the input to float*_scalbn() is denormal then it represents
> a number 0.[mantissabits] * 2^(1-exponentbias) (and the actual
> exponent field is all zeroes). This means that when we convert
> it to our unpacked encoding the unpacked exponent must be one
> greater than for a normal number, which represents
> 1.[mantissabits] * 2^(e-exponentbias) for an exponent field e.
> 
> This meant we were giving answers too small by a factor of 2 for
> all denormal inputs.
> 
> Note that the float-to-int routines also have this behaviour
> of not adjusting the exponent for denormals; however there it is
> harmless because denormals will all convert to integer zero anyway.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> Changes v1->v2: propagated fix to 80 bit and 128 bit float functions.
> 
> These function names remind me of Ken Thompson's reply to a question
> about what he'd do differently if he were redesigning UNIX:
> "I'd spell creat with an e."
> 
>  fpu/softfloat.c | 29 +++++++++++++++++++++--------
>  1 file changed, 21 insertions(+), 8 deletions(-)
> 
> diff --git a/fpu/softfloat.c b/fpu/softfloat.c
> index dbda61b..7f5e8c7 100644
> --- a/fpu/softfloat.c
> +++ b/fpu/softfloat.c
> @@ -6795,10 +6795,13 @@ float32 float32_scalbn( float32 a, int n STATUS_PARAM )
>          }
>          return a;
>      }
> -    if ( aExp != 0 )
> +    if (aExp != 0) {
>          aSig |= 0x00800000;
> -    else if ( aSig == 0 )
> +    } else if (aSig == 0) {
>          return a;
> +    } else {
> +        aExp++;
> +    }
>  
>      if (n > 0x200) {
>          n = 0x200;
> @@ -6828,10 +6831,13 @@ float64 float64_scalbn( float64 a, int n STATUS_PARAM )
>          }
>          return a;
>      }
> -    if ( aExp != 0 )
> +    if (aExp != 0) {
>          aSig |= LIT64( 0x0010000000000000 );
> -    else if ( aSig == 0 )
> +    } else if (aSig == 0) {
>          return a;
> +    } else {
> +        aExp++;
> +    }
>  
>      if (n > 0x1000) {
>          n = 0x1000;
> @@ -6861,8 +6867,12 @@ floatx80 floatx80_scalbn( floatx80 a, int n STATUS_PARAM )
>          return a;
>      }
>  
> -    if (aExp == 0 && aSig == 0)
> -        return a;
> +    if (aExp == 0) {
> +        if (aSig == 0) {
> +            return a;
> +        }
> +        aExp++;
> +    }
>  
>      if (n > 0x10000) {
>          n = 0x10000;
> @@ -6891,10 +6901,13 @@ float128 float128_scalbn( float128 a, int n STATUS_PARAM )
>          }
>          return a;
>      }
> -    if ( aExp != 0 )
> +    if (aExp != 0) {
>          aSig0 |= LIT64( 0x0001000000000000 );
> -    else if ( aSig0 == 0 && aSig1 == 0 )
> +    } else if (aSig0 == 0 && aSig1 == 0) {
>          return a;
> +    } else {
> +        aExp++;
> +    }
>  
>      if (n > 0x10000) {
>          n = 0x10000;

Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>

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

  reply	other threads:[~2013-12-22 16:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-21 21:08 [Qemu-devel] [PATCH v2] softfloat: Fix factor 2 error for scalbn on denormal inputs Peter Maydell
2013-12-22 16:38 ` Aurelien Jarno [this message]
2013-12-22 16:41 ` Richard Henderson

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=20131222163815.GD4326@ohm.rr44.fr \
    --to=aurelien@aurel32.net \
    --cc=patches@linaro.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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.