From: Eduardo Habkost <ehabkost@redhat.com>
To: Joseph Myers <joseph@codesourcery.com>
Cc: pbonzini@redhat.com, qemu-devel@nongnu.org, rth@twiddle.net
Subject: Re: [PATCH 1/5] target/i386: implement special cases for fxtract
Date: Tue, 23 Jun 2020 17:42:26 -0400 [thread overview]
Message-ID: <20200623214226.GH9925@habkost.net> (raw)
In-Reply-To: <alpine.DEB.2.21.2005070042360.18350@digraph.polyomino.org.uk>
On Thu, May 07, 2020 at 12:43:30AM +0000, Joseph Myers wrote:
> The implementation of the fxtract instruction treats all nonzero
> operands as normal numbers, so yielding incorrect results for invalid
> formats, infinities, NaNs and subnormal and pseudo-denormal operands.
> Implement appropriate handling of all those cases.
>
> Signed-off-by: Joseph Myers <joseph@codesourcery.com>
> ---
> target/i386/fpu_helper.c | 25 +++++-
> tests/tcg/i386/test-i386-fxtract.c | 120 +++++++++++++++++++++++++++++
> 2 files changed, 144 insertions(+), 1 deletion(-)
> create mode 100644 tests/tcg/i386/test-i386-fxtract.c
>
> diff --git a/target/i386/fpu_helper.c b/target/i386/fpu_helper.c
> index 792a128a6d..71a696a863 100644
> --- a/target/i386/fpu_helper.c
> +++ b/target/i386/fpu_helper.c
> @@ -767,10 +767,33 @@ void helper_fxtract(CPUX86State *env)
> &env->fp_status);
> fpush(env);
> ST0 = temp.d;
> + } else if (floatx80_invalid_encoding(ST0)) {
> + float_raise(float_flag_invalid, &env->fp_status);
> + ST0 = floatx80_default_nan(&env->fp_status);
> + fpush(env);
> + ST0 = ST1;
> + } else if (floatx80_is_any_nan(ST0)) {
> + if (floatx80_is_signaling_nan(ST0, &env->fp_status)) {
> + float_raise(float_flag_invalid, &env->fp_status);
> + ST0 = floatx80_silence_nan(ST0, &env->fp_status);
> + }
> + fpush(env);
> + ST0 = ST1;
> + } else if (floatx80_is_infinity(ST0)) {
> + fpush(env);
> + ST0 = ST1;
> + ST1 = floatx80_infinity;
> } else {
> int expdif;
>
> - expdif = EXPD(temp) - EXPBIAS;
> + if (EXPD(temp) == 0) {
> + int shift = clz64(temp.l.lower);
> + temp.l.lower <<= shift;
Coverity reports the following. It looks like a false positive
because floatx80_is_zero() would be true if both EXPD(temp) and
temp.l.lower were zero, but maybe I'm missing something.
________________________________________________________________________________________________________
*** CID 1429970: Integer handling issues (BAD_SHIFT)
/target/i386/fpu_helper.c: 922 in helper_fxtract()
916 ST1 = floatx80_infinity;
917 } else {
918 int expdif;
919
920 if (EXPD(temp) == 0) {
921 int shift = clz64(temp.l.lower);
>>> CID 1429970: Integer handling issues (BAD_SHIFT)
>>> In expression "temp.l.lower <<= shift", left shifting by more than 63 bits has undefined behavior. The shift amount, "shift", is 64.
922 temp.l.lower <<= shift;
923 expdif = 1 - EXPBIAS - shift;
924 float_raise(float_flag_input_denormal, &env->fp_status);
925 } else {
926 expdif = EXPD(temp) - EXPBIAS;
927 }
> + expdif = 1 - EXPBIAS - shift;
> + float_raise(float_flag_input_denormal, &env->fp_status);
> + } else {
> + expdif = EXPD(temp) - EXPBIAS;
> + }
> /* DP exponent bias */
> ST0 = int32_to_floatx80(expdif, &env->fp_status);
> fpush(env);
--
Eduardo
next prev parent reply other threads:[~2020-06-23 21:43 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-07 0:42 [PATCH 0/5] target/i386: fxtract, fscale fixes Joseph Myers
2020-05-07 0:43 ` [PATCH 1/5] target/i386: implement special cases for fxtract Joseph Myers
2020-05-15 8:59 ` Alex Bennée
2020-06-23 21:42 ` Eduardo Habkost [this message]
2020-06-23 22:00 ` Joseph Myers
2020-06-25 9:43 ` Peter Maydell
2020-05-07 0:44 ` [PATCH 2/5] target/i386: fix fscale handling of signaling NaN Joseph Myers
2020-05-07 0:44 ` [PATCH 3/5] target/i386: fix fscale handling of invalid exponent encodings Joseph Myers
2020-05-07 0:45 ` [PATCH 4/5] target/i386: fix fscale handling of infinite exponents Joseph Myers
2020-05-07 0:46 ` [PATCH 5/5] target/i386: fix fscale handling of rounding precision Joseph Myers
2020-05-07 2:13 ` [PATCH 0/5] target/i386: fxtract, fscale fixes no-reply
2020-05-07 14:57 ` Joseph Myers
2020-05-08 3:42 ` Richard Henderson
2020-05-14 18:25 ` Ping " Joseph Myers
2020-05-14 23:02 ` Paolo Bonzini
2020-05-15 7:03 ` Philippe Mathieu-Daudé
2020-05-21 15:36 ` 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=20200623214226.GH9925@habkost.net \
--to=ehabkost@redhat.com \
--cc=joseph@codesourcery.com \
--cc=pbonzini@redhat.com \
--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.