[PATCH] Speedup cshift0 for the case in facerec

Andrew Pinski apinski@apple.com
Sun Aug 15 01:25:00 GMT 2004


I found that a lot of the time in facerec was being spent in memcpy 
which was being
called from the cshift0 intrinsic and then I found out that the size 
which we were
calling memcpy was only 4 (aka the sizeof(int)).  So I decided to 
special case this
size and inline the call memcpy.  I also noticed a call to div which 
could be replaced
with % operator so it could be inlined.

OK? Bootstrapped on powerpc-apple-darwin with no regressions.

Thanks,
Andrew Pinski


ChangeLog:

	* intrinsics/cshift0.c (__cshift0): Use % instead of calling div.
	Special case size==sizeof(int) and split the for loops into two
	different loops.


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: temp.diff.txt
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20040815/8bc3b8df/attachment.txt>
-------------- next part --------------



Index: intrinsics/cshift0.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/intrinsics/cshift0.c,v
retrieving revision 1.3
diff -u -p -r1.3 cshift0.c
--- intrinsics/cshift0.c	4 Aug 2004 14:30:46 -0000	1.3
+++ intrinsics/cshift0.c	15 Aug 2004 01:20:25 -0000
@@ -120,7 +120,7 @@ __cshift0 (gfc_array_char * ret, const g
    rptr = ret->data;
    sptr = array->data;

-  shift = (div (shift, len)).rem;
+  shift = shift % len;
    if (shift < 0)
      shift += len;

@@ -129,15 +129,39 @@ __cshift0 (gfc_array_char * ret, const g
        /* Do the shift for this dimension.  */
        src = &sptr[shift * soffset];
        dest = rptr;
-      for (n = 0; n < len; n++)
+      if (size == sizeof (int))
          {
-          memcpy (dest, src, size);
-          dest += roffset;
-          if (n == len - shift - 1)
-            src = sptr;
-          else
-            src += soffset;
-        }
+	  for (n = 0; n < len - shift; n++)
+	    {
+	      int *dst = (int*)dest;
+	      int *src1 = (int*)src;
+	      *dst = *src1;
+
+	      dest += roffset;
+	      src += soffset;
+	    }
+	  src = sptr;
+	  for (; n < len; n++)
+	    {
+	      int *dst = (int*)dest;
+	      int *src1 = (int*)src;
+	      *dst = *src1;
+
+	      dest += roffset;
+	      src += soffset;
+	    }
+	}
+      else
+	for (n = 0; n < len; n++)
+	  {
+	    memcpy (dest, src, size);
+
+	    dest += roffset;
+	    if (n == len - shift - 1)
+	      src = sptr;
+	    else
+	      src += soffset;
+	  }

        /* Advance to the next section.  */
        rptr += rstride0;


More information about the Fortran mailing list