[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH] [SPARC] Fix floating point to integer conversion
From: |
Aurelien Jarno |
Subject: |
[Qemu-devel] [PATCH] [SPARC] Fix floating point to integer conversion |
Date: |
Wed, 7 Feb 2007 10:23:46 +0100 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
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
diff -u -d -p -r1.23 op.c
--- target-sparc/op.c 23 Oct 2006 21:37:34 -0000 1.23
+++ target-sparc/op.c 7 Feb 2007 01:25:09 -0000
@@ -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)
--
.''`. Aurelien Jarno | GPG: 1024D/F1BCDB73
: :' : Debian developer | Electrical Engineer
`. `' address@hidden | address@hidden
`- people.debian.org/~aurel32 | www.aurel32.net
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemu-devel] [PATCH] [SPARC] Fix floating point to integer conversion,
Aurelien Jarno <=