From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HEj1g-0001Nw-Ox for qemu-devel@nongnu.org; Wed, 07 Feb 2007 04:23:40 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HEj1f-0001NE-3Y for qemu-devel@nongnu.org; Wed, 07 Feb 2007 04:23:39 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HEj1e-0001NA-QP for qemu-devel@nongnu.org; Wed, 07 Feb 2007 04:23:38 -0500 Received: from farad.aurel32.net ([82.232.2.251] helo=mail.aurel32.net) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1HEj1e-0001Tq-5Q for qemu-devel@nongnu.org; Wed, 07 Feb 2007 04:23:38 -0500 Received: from farad.aurel32.net ([2001:618:400:fc13:216:3eff:fe00:100c]) by mail.aurel32.net with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1HEj1n-0005qG-2A for qemu-devel@nongnu.org; Wed, 07 Feb 2007 10:23:47 +0100 Received: from aurel32 by farad.aurel32.net with local (Exim 4.63) (envelope-from ) id 1HEj1m-0006EQ-Oj for qemu-devel@nongnu.org; Wed, 07 Feb 2007 10:23:46 +0100 Date: Wed, 7 Feb 2007 10:23:46 +0100 From: Aurelien Jarno Message-ID: <20070207092346.GA23949@farad.aurel32.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Subject: [Qemu-devel] [PATCH] [SPARC] Fix floating point to integer conversion Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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