Fix floating point to integer conversion
PATCH 1/1 Fix floating point to integer conversion
Hi,
I have found a bug on QEMU sparc, the floating point to integer conversion instructions (fstoi, fdtoi, fstox, fdtox) are not correctly emulated. The specifications says:
"The result is always rounded toward zero; that is, the rounding direction (RD) field of the FSR register is ignored."
Those instructions are used when casting a float to an int. For example, in the following code:
float f;
int i;
f = 12.95;
i = (int) f;
the variable i holds 13 and not 12 at then end of the execution.
The problem affact for example wget which is unable to download a file unless used with the -q argument. But given the bug I think a lot more softwares are affected!
The patch below fixes the problem.
Bye,
Aurelien
Index: target-sparc/op.c
===================================================================
RCS file: /sources/qemu/qemu/target-sparc/op.c,v
retrieving revision 1.23
op.c +4 -4
@@ -1472,23 +1472,23 @@ void OPPROTO op_fstod(void)/* Float to integer conversion. */ void OPPROTO op_fstoi(void) { - *((int32_t *)&FT0 ) =float32_to_int32 (FT1 , &env->fp_status); + *((int32_t *)&FT0 ) =float32_to_int32_round_to_zero (FT1 , &env->fp_status); } void OPPROTO op_fdtoi(void) { - *((int32_t *)&FT0 ) =float64_to_int32 (DT1 , &env->fp_status); + *((int32_t *)&FT0 ) =float64_to_int32_round_to_zero (DT1 , &env->fp_status); }#ifdef TARGET_SPARC64 void OPPROTO op_fstox(void) { - *((int64_t *)&DT0 ) =float32_to_int64 (FT1 , &env->fp_status); + *((int64_t *)&DT0 ) =float32_to_int64_round_to_zero (FT1 , &env->fp_status); } void OPPROTO op_fdtox(void) { - *((int64_t *)&DT0 ) =float64_to_int64 (DT1 , &env->fp_status); + *((int64_t *)&DT0 ) =float64_to_int64_round_to_zero (DT1 , &env->fp_status); } void OPPROTO op_fmovs_cc(void)
Signature · 4 lines
.''`. Aurelien Jarno | GPG: 1024D/F1BCDB73 : :' : Debian developer | Electrical Engineer `. `' [email protected] | [email protected] `- people.debian.org/~aurel32 | www.aurel32.net