[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 053/115] target/i386: fix fscale handling of invalid exponent enco
From: |
Paolo Bonzini |
Subject: |
[PULL 053/115] target/i386: fix fscale handling of invalid exponent encodings |
Date: |
Thu, 11 Jun 2020 15:43:47 -0400 |
From: Joseph Myers <joseph@codesourcery.com>
The fscale implementation does not check for invalid encodings in the
exponent operand, thus treating them like INT_MIN (the value returned
for invalid encodings by floatx80_to_int32_round_to_zero). Fix it to
treat them similarly to signaling NaN exponents, thus generating a
quiet NaN result.
Signed-off-by: Joseph Myers <joseph@codesourcery.com>
Message-Id: <alpine.DEB.2.21.2005070044190.18350@digraph.polyomino.org.uk>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
target/i386/fpu_helper.c | 5 ++++-
tests/tcg/i386/test-i386-fscale.c | 29 +++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/target/i386/fpu_helper.c b/target/i386/fpu_helper.c
index 0671de6952..10ff90370e 100644
--- a/target/i386/fpu_helper.c
+++ b/target/i386/fpu_helper.c
@@ -968,7 +968,10 @@ void helper_frndint(CPUX86State *env)
void helper_fscale(CPUX86State *env)
{
- if (floatx80_is_any_nan(ST1)) {
+ if (floatx80_invalid_encoding(ST1)) {
+ float_raise(float_flag_invalid, &env->fp_status);
+ ST0 = floatx80_default_nan(&env->fp_status);
+ } else 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);
diff --git a/tests/tcg/i386/test-i386-fscale.c
b/tests/tcg/i386/test-i386-fscale.c
index aecac5125f..b65a055d0a 100644
--- a/tests/tcg/i386/test-i386-fscale.c
+++ b/tests/tcg/i386/test-i386-fscale.c
@@ -8,6 +8,11 @@ union u {
long double ld;
};
+volatile union u ld_invalid_1 = { .s = { 1, 1234 } };
+volatile union u ld_invalid_2 = { .s = { 0, 1234 } };
+volatile union u ld_invalid_3 = { .s = { 0, 0x7fff } };
+volatile union u ld_invalid_4 = { .s = { (UINT64_C(1) << 63) - 1, 0x7fff } };
+
volatile long double ld_res;
int isnan_ld(long double x)
@@ -33,5 +38,29 @@ int main(void)
printf("FAIL: fscale snan\n");
ret = 1;
}
+ __asm__ volatile ("fscale" : "=t" (ld_res) :
+ "0" (2.5L), "u" (ld_invalid_1.ld));
+ if (!isnan_ld(ld_res) || issignaling_ld(ld_res)) {
+ printf("FAIL: fscale invalid 1\n");
+ ret = 1;
+ }
+ __asm__ volatile ("fscale" : "=t" (ld_res) :
+ "0" (2.5L), "u" (ld_invalid_2.ld));
+ if (!isnan_ld(ld_res) || issignaling_ld(ld_res)) {
+ printf("FAIL: fscale invalid 2\n");
+ ret = 1;
+ }
+ __asm__ volatile ("fscale" : "=t" (ld_res) :
+ "0" (2.5L), "u" (ld_invalid_3.ld));
+ if (!isnan_ld(ld_res) || issignaling_ld(ld_res)) {
+ printf("FAIL: fscale invalid 3\n");
+ ret = 1;
+ }
+ __asm__ volatile ("fscale" : "=t" (ld_res) :
+ "0" (2.5L), "u" (ld_invalid_4.ld));
+ if (!isnan_ld(ld_res) || issignaling_ld(ld_res)) {
+ printf("FAIL: fscale invalid 4\n");
+ ret = 1;
+ }
return ret;
}
--
2.26.2
- [PULL 032/115] hw/i386/vmport: Define enum for all commands, (continued)
- [PULL 032/115] hw/i386/vmport: Define enum for all commands, Paolo Bonzini, 2020/06/11
- [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 <=
- [PULL 052/115] target/i386: fix fscale handling of signaling NaN, Paolo Bonzini, 2020/06/11
- [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