This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] m68k soft-float denormals


The attached patch adds support for denormal values to the m68k softfloat 
SF<->DF conversion routines. Previously __truncdfsf2(FLT_MIN / 2.0) would 
return nonsense values.

Tested with cross to m68k-none-elf/-m5200
Ok?

Paul

2005-09-18  Paul Brook  <paul@codesourcery.com>

	* config/m68k/fpgnulib.c (__extendsfdf2, __truncdfsf2): Handle
	denormals.
Index: config/m68k/fpgnulib.c
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/gcc/config/m68k/fpgnulib.c,v
retrieving revision 1.4
diff -u -p -r1.4 fpgnulib.c
--- config/m68k/fpgnulib.c	18 Sep 2005 00:11:30 -0000	1.4
+++ config/m68k/fpgnulib.c	18 Sep 2005 11:56:58 -0000
@@ -166,6 +166,7 @@ __extendsfdf2 (float a1)
   register union float_long fl1;
   register union double_long dl;
   register long exp;
+  register long mant;
 
   fl1.f = a1;
 
@@ -176,10 +177,23 @@ __extendsfdf2 (float a1)
     }
 
   dl.l.upper = SIGN (fl1.l);
-  exp = EXP (fl1.l) - EXCESS + EXCESSD;
+  exp = EXP(fl1.l);
+  mant = MANT (fl1.l) & ~HIDDEN;
+  if (exp == 0)
+    {
+      /* Denormal.  */
+      exp = 1;
+      while (!(mant & HIDDEN))
+	{
+	  mant <<= 1;
+	  exp--;
+	}
+      mant &= ~HIDDEN;
+    }
+  exp = exp - EXCESS + EXCESSD;
   dl.l.upper |= exp << 20;
-  dl.l.upper |= (MANT (fl1.l) & ~HIDDEN) >> 3;
-  dl.l.lower = MANT (fl1.l) << 29;
+  dl.l.upper |= mant >> 3;
+  dl.l.lower = mant << 29;
 	
   return dl.d;
 }
@@ -203,6 +217,16 @@ __truncdfsf2 (double a1)
   /* shift double mantissa 6 bits so we can round */
   mant = MANTD (dl1) >> 6;
 
+  /* Check for underflow and denormals.  */
+  if (exp <= 0)
+    {
+      if (exp < -24)
+	mant = 0;
+      else
+	mant >>= 1 - exp;
+      exp = 0;
+    }
+  
   /* now round and shift down */
   mant += 1;
   mant >>= 1;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]