All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: Richard Henderson <richard.henderson@linaro.org>
Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org
Subject: Re: [Qemu-devel] [PATCH 2/2] fpu: Bound increment for scalbn
Date: Tue, 17 Apr 2018 14:51:44 +0100	[thread overview]
Message-ID: <871sfeaqkv.fsf@linaro.org> (raw)
In-Reply-To: <20180417025328.25431-3-richard.henderson@linaro.org>


Richard Henderson <richard.henderson@linaro.org> writes:

> Without bounding the increment, we can overflow exp either here
> in scalbn_decomposed or when adding the bias in round_canonical.
> This can result in e.g. underflowing to 0 instead of overflowing
> to infinity.
>
> The old softfloat code did bound the increment.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  fpu/softfloat.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/fpu/softfloat.c b/fpu/softfloat.c
> index ba6e654050..a589f328c9 100644
> --- a/fpu/softfloat.c
> +++ b/fpu/softfloat.c
> @@ -1883,6 +1883,12 @@ static FloatParts scalbn_decomposed(FloatParts a, int n, float_status *s)
>          return return_nan(a, s);
>      }
>      if (a.cls == float_class_normal) {
> +        /* The largest float type (even though not supported by FloatParts)
> +         * is float128, which has a 15 bit exponent.  Bounding N to 16 bits
> +         * still allows rounding to infinity, without allowing overflow
> +         * within the int32_t that backs FloatParts.exp.
> +         */
> +        n = MIN(MAX(n, -0x10000), 0x10000);
>          a.exp += n;
>      }
>      return a;

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Tested-by: Alex Bennée <alex.bennee@linaro.org>

(risu FWIW although it obviously didn't catch this failure ;-)

--
Alex Bennée

  parent reply	other threads:[~2018-04-17 13:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-17  2:53 [Qemu-devel] [PATCH for-2.12 0/2] softfloat fixes Richard Henderson
2018-04-17  2:53 ` [Qemu-devel] [PATCH 1/2] fpu: Check for inf/x before x/0 Richard Henderson
2018-04-17  9:02   ` Peter Maydell
2018-04-17  2:53 ` [Qemu-devel] [PATCH 2/2] fpu: Bound increment for scalbn Richard Henderson
2018-04-17  9:53   ` Peter Maydell
2018-04-17 13:51   ` Alex Bennée [this message]
2018-04-17 13:53     ` 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=871sfeaqkv.fsf@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.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.