qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Aurelien Jarno <aurelien@aurel32.net>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] [SPARC] Fix floating point to integer conversion
Date: Wed, 7 Feb 2007 10:23:46 +0100	[thread overview]
Message-ID: <20070207092346.GA23949@farad.aurel32.net> (raw)

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

                 reply	other threads:[~2007-02-07  9:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070207092346.GA23949@farad.aurel32.net \
    --to=aurelien@aurel32.net \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).