* [Qemu-devel] [PATCH] [SPARC] Fix floating point to integer conversion
@ 2007-02-07 9:23 Aurelien Jarno
0 siblings, 0 replies; only message in thread
From: Aurelien Jarno @ 2007-02-07 9:23 UTC (permalink / raw)
To: qemu-devel
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
`. `' aurel32@debian.org | aurelien@aurel32.net
`- people.debian.org/~aurel32 | www.aurel32.net
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2007-02-07 9:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-07 9:23 [Qemu-devel] [PATCH] [SPARC] Fix floating point to integer conversion Aurelien Jarno
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).