[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[patches] Fix soft-fp truncation bug



I've applied this patch to fix a bug in soft-fp's truncation that showed 
up with the GCC test gcc.c-torture/execute/ieee/20000320-1.c:

* An off-by-one error meant values between half the smallest denormal and 
the smallest denormal got truncated to 0.

* Even for smaller exponents, the truncation needs to set the sticky bit 
for the sake of rounding modes where the result should be the smallest 
denormal not 0.

Index: ChangeLog.eglibc
===================================================================
--- ChangeLog.eglibc	(revision 2124)
+++ ChangeLog.eglibc	(working copy)
@@ -1,3 +1,9 @@
+2007-04-30  Joseph Myers  <joseph@xxxxxxxxxxxxxxxx>
+
+	* soft-fp/op-common.h (FP_TRUNC): Correct off-by-one error in
+	condition for truncating to 0.  Set sticky bit for such
+	truncation.
+
 2007-04-20  Jim Blandy  <jimb@xxxxxxxxxxxxxxxx>
 
 	* EGLIBC.cross-building: doc fix.
Index: soft-fp/op-common.h
===================================================================
--- soft-fp/op-common.h	(revision 2124)
+++ soft-fp/op-common.h	(working copy)
@@ -1211,8 +1211,11 @@
 	{								     \
 	  if (D##_e <= 0)						     \
 	    {								     \
-	      if (D##_e <= 1 - _FP_FRACBITS_##dfs)			     \
-		_FP_FRAC_SET_##swc(S, _FP_ZEROFRAC_##swc);		     \
+	      if (D##_e < 1 - _FP_FRACBITS_##dfs)			     \
+		{							     \
+		  _FP_FRAC_SET_##swc(S, _FP_ZEROFRAC_##swc);		     \
+		  _FP_FRAC_LOW_##swc(S) |= 1;				     \
+		}							     \
 	      else							     \
 		{							     \
 		  _FP_FRAC_HIGH_##sfs(S) |= _FP_IMPLBIT_SH_##sfs;	     \

-- 
Joseph S. Myers
joseph@xxxxxxxxxxxxxxxx