This is the mail archive of the gcc-bugs@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]

[Bug c/13381] New: fp-bit.c rounding problem


Multiply of 2 float numbers yield bad results, on systems which use fp-bit.c.
(eg. ARM, SH3 etc.)

0x3f800400 * 0x00000fff => 0x00001000  (0x00000fff expected)
0x3fc88888 * 0x0000000f => 0x00000018  (0x00000017 expected)
0x3f844444 * 0x0000000f => 0x00000010  (0x0000000f expected)
(hex numbers above are all 32-bits float numbers)

I think that the problem is fp-bit.c try to round twice in above calculations.
One is done in fpmul_parts(), and second rounding is done in pack_d().

I think that the fpmul_parts() and fpdiv_parts() should not do rounding,
and just help pack_d() to work correct.


--- fp-bit.c    2003-04-10 04:31:06.000000000 +0900
+++ fp-bit.c.fixed      2003-10-20 19:12:35.000000000 +0900
@@ -856,48 +856,26 @@
     }
   while (high < IMPLICIT_1)
     {
       tmp->normal_exp--;
 
       high <<= 1;
       if (low & FRACHIGH)
        high |= 1;
       low <<= 1;
     }
-  /* rounding is tricky. if we only round if it won't make us round later.  */
-#if 0
-  if (low & FRACHIGH2)
+
+  if (!ROUND_TOWARDS_ZERO)
     {
-      if (((high & GARDMASK) != GARDMSB)
-         && (((high + 1) & GARDMASK) == GARDMSB))
-       {
-         /* don't round, it gets done again later.  */
-       }
-      else
-       {
-         high++;
-       }
-    }
-#endif
-  if (!ROUND_TOWARDS_ZERO && (high & GARDMASK) == GARDMSB)
-    {
-      if (high & (1 << NGARDS))
-       {
-         /* half way, so round to even */
-         high += GARDROUND + 1;
-       }
-      else if (low)
-       {
-         /* but we really weren't half way */
-         high += GARDROUND + 1;
-       }
+      if (low) high |= 1;
     }
+
   tmp->fraction.ll = high;
   tmp->class = CLASS_NUMBER;
   return tmp;
 }
 
 FLO_type
 multiply (FLO_type arg_a, FLO_type arg_b)
 {
   fp_number_type a;
   fp_number_type b;
@@ -981,32 +959,23 @@
       {
        if (numerator >= denominator)
          {
            quotient |= bit;
            numerator -= denominator;
          }
        bit >>= 1;
        numerator *= 2;
       }
 
-    if (!ROUND_TOWARDS_ZERO && (quotient & GARDMASK) == GARDMSB)
+    if (!ROUND_TOWARDS_ZERO)
       {
-       if (quotient & (1 << NGARDS))
-         {
-           /* half way, so round to even */
-           quotient += GARDROUND + 1;
-         }
-       else if (numerator)
-         {
-           /* but we really weren't half way, more bits exist */
-           quotient += GARDROUND + 1;
-         }
+        if (numerator) quotient |= 1;
       }
 
     a->fraction.ll = quotient;
     return (a);
   }
 }
 
 FLO_type
 divide (FLO_type arg_a, FLO_type arg_b)
 {
--- end ---

-- 
           Summary: fp-bit.c rounding problem
           Product: gcc
           Version: 3.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: matsui at kuramae dot ne dot jp
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13381


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