[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 055/115] target/i386: fix fscale handling of rounding precision
From: |
Paolo Bonzini |
Subject: |
[PULL 055/115] target/i386: fix fscale handling of rounding precision |
Date: |
Thu, 11 Jun 2020 15:43:49 -0400 |
From: Joseph Myers <joseph@codesourcery.com>
The fscale implementation uses floatx80_scalbn for the final scaling
operation. floatx80_scalbn ends up rounding the result using the
dynamic rounding precision configured for the FPU. But only a limited
set of x87 floating-point instructions are supposed to respect the
dynamic rounding precision, and fscale is not in that set. Fix the
implementation to save and restore the rounding precision around the
call to floatx80_scalbn.
Signed-off-by: Joseph Myers <joseph@codesourcery.com>
Message-Id: <alpine.DEB.2.21.2005070045430.18350@digraph.polyomino.org.uk>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
target/i386/fpu_helper.c | 3 +++
tests/tcg/i386/test-i386-fscale.c | 13 +++++++++++++
2 files changed, 16 insertions(+)
diff --git a/target/i386/fpu_helper.c b/target/i386/fpu_helper.c
index 72d1e77eb0..4d14c1ca24 100644
--- a/target/i386/fpu_helper.c
+++ b/target/i386/fpu_helper.c
@@ -1001,7 +1001,10 @@ void helper_fscale(CPUX86State *env)
}
} else {
int n = floatx80_to_int32_round_to_zero(ST1, &env->fp_status);
+ signed char save = env->fp_status.floatx80_rounding_precision;
+ env->fp_status.floatx80_rounding_precision = 80;
ST0 = floatx80_scalbn(ST0, n, &env->fp_status);
+ env->fp_status.floatx80_rounding_precision = save;
}
}
diff --git a/tests/tcg/i386/test-i386-fscale.c
b/tests/tcg/i386/test-i386-fscale.c
index b953e7c563..d23b3cfeec 100644
--- a/tests/tcg/i386/test-i386-fscale.c
+++ b/tests/tcg/i386/test-i386-fscale.c
@@ -8,6 +8,8 @@ union u {
long double ld;
};
+volatile long double ld_third = 1.0L / 3.0L;
+volatile long double ld_four_thirds = 4.0L / 3.0L;
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 } };
@@ -91,5 +93,16 @@ int main(void)
printf("FAIL: fscale finite down inf\n");
ret = 1;
}
+ /* Set round-to-nearest with single-precision rounding. */
+ cw = cw & ~0xf00;
+ __asm__ volatile ("fldcw %0" : : "m" (cw));
+ __asm__ volatile ("fscale" : "=t" (ld_res) :
+ "0" (ld_third), "u" (2.0L));
+ cw = cw | 0x300;
+ __asm__ volatile ("fldcw %0" : : "m" (cw));
+ if (ld_res != ld_four_thirds) {
+ printf("FAIL: fscale single-precision\n");
+ ret = 1;
+ }
return ret;
}
--
2.26.2
- [PULL 049/115] megasas: avoid NULL pointer dereference, (continued)
- [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
- [PULL 045/115] cpus: Fix botched configure_icount() error API violation fix, Paolo Bonzini, 2020/06/11
- [PULL 041/115] qom/object: factor out the initialization of hash table of properties, Paolo Bonzini, 2020/06/11
- [PULL 055/115] target/i386: fix fscale handling of rounding precision,
Paolo Bonzini <=
- [PULL 059/115] hw/elf_ops: Do not ignore write failures when loading ELF, Paolo Bonzini, 2020/06/11
- [PULL 025/115] hw/i386/vmport: Add reference to VMware open-vm-tools, Paolo Bonzini, 2020/06/11
- [PULL 017/115] hyperv: expose API to determine if synic is enabled, Paolo Bonzini, 2020/06/11
- [PULL 014/115] qom/object: Move Object typedef to 'qemu/typedefs.h', Paolo Bonzini, 2020/06/11
- [PULL 066/115] x86/cpu: Enable AVX512_VP2INTERSECT cpu feature, Paolo Bonzini, 2020/06/11
- [PULL 067/115] vfio/pci: Use kvm_irqchip_add_irqfd_notifier_gsi() for irqfds, Paolo Bonzini, 2020/06/11
- [PULL 035/115] hw/i386/vmport: Allow x2apic without IR, Paolo Bonzini, 2020/06/11
- [PULL 030/115] hw/i386/vmport: Report vmware-vmx-type in CMD_GETVERSION, Paolo Bonzini, 2020/06/11
- [PULL 064/115] target/i386: fix fisttpl, fisttpll handling of out-of-range values, Paolo Bonzini, 2020/06/11
- [PULL 024/115] target/i386: fix phadd* with identical destination and source register, Paolo Bonzini, 2020/06/11