This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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] Speedup cshift0 for the case in facerec


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.


Attachment: temp.diff.txt
Description: Text document




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;

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