From 95368d250b5a0ea3f019a798164ff507e69eb36f Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Mon, 15 Jun 2020 13:05:29 -0400 Subject: [PATCH] target/i386: fix fscale handling of rounding precision 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. Backports commit c535d68755576bfa33be7aef7bd294a601f776e0 from qemu --- qemu/target/i386/fpu_helper.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/qemu/target/i386/fpu_helper.c b/qemu/target/i386/fpu_helper.c index 28bf818e..b5cd89ef 100644 --- a/qemu/target/i386/fpu_helper.c +++ b/qemu/target/i386/fpu_helper.c @@ -967,7 +967,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; } }