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 to speed up fp-bit.c:_fpadd_parts


This patch slightly speeds up addition and subtraction in fp-bit.c.
It yields a 0.4% improvement (geometric mean) in EEMBC results on IBM
PowerPC 440 (--with-cpu=440 compiler).

Tested with no regressions with cross-compilers (--with-cpu=440) to
powerpc-ibm-linux-gnu.  Applied to csl-ppc4xx-branch.  OK to commit to
mainline?

2005-11-25  Joseph S. Myers  <joseph@codesourcery.com>

	* config/fp-bit.h (LSHIFT): Take shift count parameter.
	* config/fp-bit.c (_fpadd_parts): Shift in one go instead of one
	bit at a time.

diff -rupN GCC.orig/gcc/config/fp-bit.c GCC.fpadd/gcc/config/fp-bit.c
--- GCC.orig/gcc/config/fp-bit.c	2005-11-22 00:36:13.000000000 +0000
+++ GCC.fpadd/gcc/config/fp-bit.c	2005-11-22 21:13:25.000000000 +0000
@@ -649,6 +649,7 @@ _fpadd_parts (fp_number_type * a,
      they're the same */
   {
     int diff;
+    int sdiff;
 
     a_normal_exp = a->normal_exp;
     b_normal_exp = b->normal_exp;
@@ -656,21 +657,21 @@ _fpadd_parts (fp_number_type * a,
     b_fraction = b->fraction.ll;
 
     diff = a_normal_exp - b_normal_exp;
+    sdiff = diff;
 
     if (diff < 0)
       diff = -diff;
     if (diff < FRAC_NBITS)
       {
-	/* ??? This does shifts one bit at a time.  Optimize.  */
-	while (a_normal_exp > b_normal_exp)
+	if (sdiff > 0)
 	  {
-	    b_normal_exp++;
-	    LSHIFT (b_fraction);
+	    b_normal_exp += diff;
+	    LSHIFT (b_fraction, diff);
 	  }
-	while (b_normal_exp > a_normal_exp)
+	else if (sdiff < 0)
 	  {
-	    a_normal_exp++;
-	    LSHIFT (a_fraction);
+	    a_normal_exp += diff;
+	    LSHIFT (a_fraction, diff);
 	  }
       }
     else
@@ -731,7 +732,7 @@ _fpadd_parts (fp_number_type * a,
 
   if (tmp->fraction.ll >= IMPLICIT_2)
     {
-      LSHIFT (tmp->fraction.ll);
+      LSHIFT (tmp->fraction.ll, 1);
       tmp->normal_exp++;
     }
   return tmp;
diff -rupN GCC.orig/gcc/config/fp-bit.h GCC.fpadd/gcc/config/fp-bit.h
--- GCC.orig/gcc/config/fp-bit.h	2005-10-28 23:34:08.000000000 +0000
+++ GCC.fpadd/gcc/config/fp-bit.h	2005-11-22 01:06:14.000000000 +0000
@@ -318,7 +318,7 @@ typedef unsigned int UTItype __attribute
 #endif
 
 /* Preserve the sticky-bit when shifting fractions to the right.  */
-#define LSHIFT(a) { a = (a & 1) | (a >> 1); }
+#define LSHIFT(a, s) { a = (a >> s) | !!(a & (((fractype) 1 << s) - 1)); }
 
 /* numeric parameters */
 /* F_D_BITOFF is the number of bits offset between the MSB of the mantissa

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    joseph@codesourcery.com (CodeSourcery mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)


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