Thread (11 messages) flat view 11 messages, 6 authors, 2008-01-09
STALE6801d

[PATCH] Fix remainder calculating bug in single floating point division

From: Liu Yu <hidden>
Date: 2008-01-06 14:17:15
Subsystem: linux for powerpc (32-bit and 64-bit), the rest · Maintainers: Madhavan Srinivasan, Linus Torvalds

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 <redacted>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help