linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Liu Yu <Yu.Liu@freescale.com>
To: linuxppc-dev@ozlabs.org
Cc: Liu Yu <Yu.Liu@freescale.com>
Subject: [PATCH] Fix remainder calculating bug in single floating point division
Date: Sun,  6 Jan 2008 22:26:53 +0800	[thread overview]
Message-ID: <11996296134110-git-send-email-Yu.Liu@freescale.com> (raw)

This bug exists in the emulation of floating point division for powerpc.

The original code cannot count the remainder correctly. 
I can provide a test case to trigger this bug. 
When use fdiv to count 1.1754941e-38f / 0.9999999f, 
the result is expected to be 1.175494e-38f, 
but we will get 1.174921e-38f in the original case.

Comments are always welcomed!

Signed-off-by: Liu Yu <Yu.Liu@freescale.com>
---
 arch/powerpc/math-emu/sfp-machine.h |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/math-emu/sfp-machine.h b/arch/powerpc/math-emu/sfp-machine.h
index 4b17d83..644cee2 100644
--- a/arch/powerpc/math-emu/sfp-machine.h
+++ b/arch/powerpc/math-emu/sfp-machine.h
@@ -324,10 +324,10 @@ extern int  fp_pack_ds(void *, long, unsigned long, unsigned long, long, long);
     __r1 = __r1 * __ll_B | __ll_highpart (n0);				\
     if (__r1 < __m)							\
       {									\
-	__q1--, __r1 += (d);						\
-	if (__r1 >= (d)) /* we didn't get carry when adding to __r1 */	\
-	  if (__r1 < __m)						\
+	do {								\
 	    __q1--, __r1 += (d);					\
+	  /* we didn't get carry when adding to __r1 */			\
+	} while (__r1 >= (d) && __r1 < __m);				\
       }									\
     __r1 -= __m;							\
 									\
@@ -337,10 +337,9 @@ extern int  fp_pack_ds(void *, long, unsigned long, unsigned long, long, long);
     __r0 = __r0 * __ll_B | __ll_lowpart (n0);				\
     if (__r0 < __m)							\
       {									\
-	__q0--, __r0 += (d);						\
-	if (__r0 >= (d))						\
-	  if (__r0 < __m)						\
+	do {								\
 	    __q0--, __r0 += (d);					\
+	} while (__r0 >= (d) && __r0 < __m);				\
       }									\
     __r0 -= __m;							\
 									\
-- 
1.5.2

             reply	other threads:[~2008-01-06 14:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-06 14:26 Liu Yu [this message]
2008-01-06 20:07 ` [PATCH] Fix remainder calculating bug in single floating point division Benjamin Herrenschmidt
2008-01-06 20:44   ` Dan Malek
2008-01-06 20:49     ` Benjamin Herrenschmidt
2008-01-07  1:09       ` Josh Boyer
2008-01-08  6:20     ` Kumar Gala
2008-01-09 15:38       ` [PATCH] Fix remainder calculating bug in single floating pointdivision Liu Yu
2008-01-09 16:19         ` Kumar Gala
2008-01-08  6:22 ` [PATCH] Fix remainder calculating bug in single floating point division Kumar Gala
2008-01-09  1:24   ` Liu Yu
2008-01-09 23:48     ` David Gibson

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=11996296134110-git-send-email-Yu.Liu@freescale.com \
    --to=yu.liu@freescale.com \
    --cc=linuxppc-dev@ozlabs.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).