From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, Joseph Myers <joseph@codesourcery.com>
Subject: [PULL 4/4] softfloat: fix floatx80 pseudo-denormal round to integer
Date: Fri, 15 May 2020 11:47:22 -0700 [thread overview]
Message-ID: <20200515184722.31182-5-richard.henderson@linaro.org> (raw)
In-Reply-To: <20200515184722.31182-1-richard.henderson@linaro.org>
From: Joseph Myers <joseph@codesourcery.com>
The softfloat function floatx80_round_to_int incorrectly handles the
case of a pseudo-denormal where only the high bit of the significand
is set, ignoring that bit (treating the number as an exact zero)
rather than treating the number as an alternative representation of
+/- 2^-16382 (which may round to +/- 1 depending on the rounding mode)
as hardware does. Fix this check (simplifying the code in the
process).
Signed-off-by: Joseph Myers <joseph@codesourcery.com>
Message-Id: <alpine.DEB.2.21.2005042339420.22972@digraph.polyomino.org.uk>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
fpu/softfloat.c | 2 +-
tests/tcg/i386/test-i386-pseudo-denormal.c | 10 ++++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index c57f72e3a6..a362bf89ca 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -5741,7 +5741,7 @@ floatx80 floatx80_round_to_int(floatx80 a, float_status *status)
}
if ( aExp < 0x3FFF ) {
if ( ( aExp == 0 )
- && ( (uint64_t) ( extractFloatx80Frac( a )<<1 ) == 0 ) ) {
+ && ( (uint64_t) ( extractFloatx80Frac( a ) ) == 0 ) ) {
return a;
}
status->float_exception_flags |= float_flag_inexact;
diff --git a/tests/tcg/i386/test-i386-pseudo-denormal.c b/tests/tcg/i386/test-i386-pseudo-denormal.c
index acf2b9cf03..00d510cf4a 100644
--- a/tests/tcg/i386/test-i386-pseudo-denormal.c
+++ b/tests/tcg/i386/test-i386-pseudo-denormal.c
@@ -14,6 +14,7 @@ volatile long double ld_res;
int main(void)
{
+ short cw;
int ret = 0;
ld_res = ld_pseudo_m16382.ld + ld_pseudo_m16382.ld;
if (ld_res != 0x1p-16381L) {
@@ -24,5 +25,14 @@ int main(void)
printf("FAIL: pseudo-denormal compare\n");
ret = 1;
}
+ /* Set round-upward. */
+ __asm__ volatile ("fnstcw %0" : "=m" (cw));
+ cw = (cw & ~0xc00) | 0x800;
+ __asm__ volatile ("fldcw %0" : : "m" (cw));
+ __asm__ ("frndint" : "=t" (ld_res) : "0" (ld_pseudo_m16382.ld));
+ if (ld_res != 1.0L) {
+ printf("FAIL: pseudo-denormal round-to-integer\n");
+ ret = 1;
+ }
return ret;
}
--
2.20.1
next prev parent reply other threads:[~2020-05-15 18:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-15 18:47 [PULL 0/4] softfloat patch queue Richard Henderson
2020-05-15 18:47 ` [PULL 1/4] softfloat: silence sNaN for conversions to/from floatx80 Richard Henderson
2020-05-15 18:47 ` [PULL 2/4] softfloat: fix floatx80 pseudo-denormal addition / subtraction Richard Henderson
2020-05-15 18:47 ` [PULL 3/4] softfloat: fix floatx80 pseudo-denormal comparisons Richard Henderson
2020-05-15 18:47 ` Richard Henderson [this message]
2020-05-15 21:31 ` [PULL 0/4] softfloat patch queue Peter Maydell
2020-05-16 5:46 ` no-reply
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=20200515184722.31182-5-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=joseph@codesourcery.com \
--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 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).