[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 052/115] target/i386: fix fscale handling of signaling NaN
From: |
Paolo Bonzini |
Subject: |
[PULL 052/115] target/i386: fix fscale handling of signaling NaN |
Date: |
Thu, 11 Jun 2020 15:43:46 -0400 |
From: Joseph Myers <joseph@codesourcery.com>
The implementation of the fscale instruction returns a NaN exponent
unchanged. Fix it to return a quiet NaN when the provided exponent is
a signaling NaN.
Signed-off-by: Joseph Myers <joseph@codesourcery.com>
Message-Id: <alpine.DEB.2.21.2005070043330.18350@digraph.polyomino.org.uk>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
target/i386/fpu_helper.c | 4 ++++
tests/tcg/i386/test-i386-fscale.c | 37 +++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+)
create mode 100644 tests/tcg/i386/test-i386-fscale.c
diff --git a/target/i386/fpu_helper.c b/target/i386/fpu_helper.c
index 568bd3b359..0671de6952 100644
--- a/target/i386/fpu_helper.c
+++ b/target/i386/fpu_helper.c
@@ -970,6 +970,10 @@ void helper_fscale(CPUX86State *env)
{
if (floatx80_is_any_nan(ST1)) {
ST0 = ST1;
+ 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);
+ }
} else {
int n = floatx80_to_int32_round_to_zero(ST1, &env->fp_status);
ST0 = floatx80_scalbn(ST0, n, &env->fp_status);
diff --git a/tests/tcg/i386/test-i386-fscale.c
b/tests/tcg/i386/test-i386-fscale.c
new file mode 100644
index 0000000000..aecac5125f
--- /dev/null
+++ b/tests/tcg/i386/test-i386-fscale.c
@@ -0,0 +1,37 @@
+/* Test fscale instruction. */
+
+#include <stdint.h>
+#include <stdio.h>
+
+union u {
+ struct { uint64_t sig; uint16_t sign_exp; } s;
+ long double ld;
+};
+
+volatile long double ld_res;
+
+int isnan_ld(long double x)
+{
+ union u tmp = { .ld = x };
+ return ((tmp.s.sign_exp & 0x7fff) == 0x7fff &&
+ (tmp.s.sig >> 63) != 0 &&
+ (tmp.s.sig << 1) != 0);
+}
+
+int issignaling_ld(long double x)
+{
+ union u tmp = { .ld = x };
+ return isnan_ld(x) && (tmp.s.sig & UINT64_C(0x4000000000000000)) == 0;
+}
+
+int main(void)
+{
+ int ret = 0;
+ __asm__ volatile ("fscale" : "=t" (ld_res) :
+ "0" (2.5L), "u" (__builtin_nansl("")));
+ if (!isnan_ld(ld_res) || issignaling_ld(ld_res)) {
+ printf("FAIL: fscale snan\n");
+ ret = 1;
+ }
+ return ret;
+}
--
2.26.2
- [PULL 013/115] target/i386: Fix OUTL debug output, (continued)
- [PULL 013/115] target/i386: Fix OUTL debug output, Paolo Bonzini, 2020/06/11
- [PULL 036/115] i386/cpu: Store LAPIC bus frequency in CPU structure, Paolo Bonzini, 2020/06/11
- [PULL 039/115] accel: Move Xen accelerator code under accel/xen/, Paolo Bonzini, 2020/06/11
- [PULL 026/115] hw/i386/vmport: Add device properties, Paolo Bonzini, 2020/06/11
- [PULL 051/115] target/i386: implement special cases for fxtract, Paolo Bonzini, 2020/06/11
- [PULL 056/115] exec: Let address_space_read/write_cached() propagate MemTxResult, Paolo Bonzini, 2020/06/11
- [PULL 038/115] hw/i386/vmport: Assert vmport initialized before registering commands, Paolo Bonzini, 2020/06/11
- [PULL 042/115] qom/object: simplify type_initialize_interface(), Paolo Bonzini, 2020/06/11
- [PULL 046/115] hax: Dynamic allocate vcpu state structure, Paolo Bonzini, 2020/06/11
- [PULL 053/115] target/i386: fix fscale handling of invalid exponent encodings, Paolo Bonzini, 2020/06/11
- [PULL 052/115] target/i386: fix fscale handling of signaling NaN,
Paolo Bonzini <=
- [PULL 043/115] qom/object: pass (Object *) to object_initialize_with_type(), Paolo Bonzini, 2020/06/11
- [PULL 034/115] hw/i386/vmport: Add support for CMD_GET_VCPU_INFO, Paolo Bonzini, 2020/06/11
- [PULL 049/115] megasas: avoid NULL pointer dereference, Paolo Bonzini, 2020/06/11
- [PULL 061/115] target/i386: fix fxam handling of invalid encodings, Paolo Bonzini, 2020/06/11
- [PULL 062/115] target/i386: fix fbstp handling of negative zero, Paolo Bonzini, 2020/06/11
- [PULL 065/115] hw/i386/vmport: Allow QTest use without crashing, Paolo Bonzini, 2020/06/11
- [PULL 063/115] target/i386: fix fbstp handling of out-of-range values, Paolo Bonzini, 2020/06/11
- [PULL 054/115] target/i386: fix fscale handling of infinite exponents, Paolo Bonzini, 2020/06/11
- [PULL 044/115] qom/container: remove .instance_size initializer from container_info, Paolo Bonzini, 2020/06/11
- [PULL 037/115] hw/i386/vmport: Add support for CMD_GETHZ, Paolo Bonzini, 2020/06/11