linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix remainder calculating bug in single floating point division
@ 2008-01-06 14:26 Liu Yu
  2008-01-06 20:07 ` Benjamin Herrenschmidt
  2008-01-08  6:22 ` [PATCH] Fix remainder calculating bug in single floating point division Kumar Gala
  0 siblings, 2 replies; 11+ messages in thread
From: Liu Yu @ 2008-01-06 14:26 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Liu Yu

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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2008-01-09 23:48 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-06 14:26 [PATCH] Fix remainder calculating bug in single floating point division Liu Yu
2008-01-06 20:07 ` 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

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).