OSDN Git Service

2008-07-21 Thomas Koenig <tkoenig@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / libgfortran / generated / eoshift1_4.c
index d2580f8..d78c40a 100644 (file)
@@ -1,5 +1,5 @@
 /* Implementation of the EOSHIFT intrinsic
-   Copyright 2002, 2005 Free Software Foundation, Inc.
+   Copyright 2002, 2005, 2007 Free Software Foundation, Inc.
    Contributed by Paul Brook <paul@nowt.org>
 
 This file is part of the GNU Fortran 95 runtime library (libgfortran).
@@ -28,33 +28,28 @@ License along with libgfortran; see the file COPYING.  If not,
 write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 Boston, MA 02110-1301, USA.  */
 
-#include "config.h"
+#include "libgfortran.h"
 #include <stdlib.h>
 #include <assert.h>
 #include <string.h>
-#include "libgfortran.h"
 
-static const char zeros[16] =
-  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 
-extern void eoshift1_4 (gfc_array_char *,
-                                    const gfc_array_char *,
-                                    const gfc_array_i4 *, const char *,
-                                    const GFC_INTEGER_4 *);
-export_proto(eoshift1_4);
+#if defined (HAVE_GFC_INTEGER_4)
 
-void
-eoshift1_4 (gfc_array_char *ret,
-                      const gfc_array_char *array,
-                      const gfc_array_i4 *h, const char *pbound,
-                      const GFC_INTEGER_4 *pwhich)
+static void
+eoshift1 (gfc_array_char * const restrict ret, 
+       const gfc_array_char * const restrict array, 
+       const gfc_array_i4 * const restrict h,
+       const char * const restrict pbound, 
+       const GFC_INTEGER_4 * const restrict pwhich, 
+       index_type size, const char * filler, index_type filler_len)
 {
   /* r.* indicates the return array.  */
   index_type rstride[GFC_MAX_DIMENSIONS];
   index_type rstride0;
   index_type roffset;
   char *rptr;
-  char *dest;
+  char * restrict dest;
   /* s.* indicates the source array.  */
   index_type sstride[GFC_MAX_DIMENSIONS];
   index_type sstride0;
@@ -69,7 +64,6 @@ eoshift1_4 (gfc_array_char *ret,
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type dim;
-  index_type size;
   index_type len;
   index_type n;
   int which;
@@ -87,14 +81,8 @@ eoshift1_4 (gfc_array_char *ret,
   else
     which = 0;
 
-  if (!pbound)
-    pbound = zeros;
-
-  size = GFC_DESCRIPTOR_SIZE (ret);
-
   extent[0] = 1;
   count[0] = 0;
-  size = GFC_DESCRIPTOR_SIZE (array);
 
   if (ret->data == NULL)
     {
@@ -114,6 +102,11 @@ eoshift1_4 (gfc_array_char *ret,
             ret->dim[i].stride = (ret->dim[i-1].ubound + 1) * ret->dim[i-1].stride;
         }
     }
+  else
+    {
+      if (size0 ((array_t *) ret) == 0)
+       return;
+    }
 
   n = 0;
   for (dim = 0; dim < GFC_DESCRIPTOR_RANK (array); dim++)
@@ -135,7 +128,7 @@ eoshift1_4 (gfc_array_char *ret,
           rstride[n] = ret->dim[dim].stride * size;
           sstride[n] = array->dim[dim].stride * size;
 
-          hstride[n] = h->dim[n].stride * size;
+          hstride[n] = h->dim[n].stride;
           n++;
         }
     }
@@ -186,11 +179,25 @@ eoshift1_4 (gfc_array_char *ret,
         dest = rptr;
       n = delta;
 
-      while (n--)
-        {
-          memcpy (dest, pbound, size);
-          dest += roffset;
-        }
+      if (pbound)
+       while (n--)
+         {
+           memcpy (dest, pbound, size);
+           dest += roffset;
+         }
+      else
+       while (n--)
+         {
+           index_type i;
+
+           if (filler_len == 1)
+             memset (dest, filler[0], size);
+           else
+             for (i = 0; i < size; i += filler_len)
+               memcpy (&dest[i], filler, filler_len);
+
+           dest += roffset;
+         }
 
       /* Advance to the next section.  */
       rptr += rstride0;
@@ -204,7 +211,7 @@ eoshift1_4 (gfc_array_char *ret,
              the next dimension.  */
           count[n] = 0;
           /* We could precalculate these products, but this is a less
-             frequently used path so proabably not worth it.  */
+             frequently used path so probably not worth it.  */
           rptr -= rstride[n] * extent[n];
           sptr -= sstride[n] * extent[n];
          hptr -= hstride[n] * extent[n];
@@ -225,3 +232,70 @@ eoshift1_4 (gfc_array_char *ret,
         }
     }
 }
+
+void eoshift1_4 (gfc_array_char * const restrict, 
+       const gfc_array_char * const restrict,
+       const gfc_array_i4 * const restrict, const char * const restrict, 
+       const GFC_INTEGER_4 * const restrict);
+export_proto(eoshift1_4);
+
+void
+eoshift1_4 (gfc_array_char * const restrict ret, 
+       const gfc_array_char * const restrict array,
+       const gfc_array_i4 * const restrict h, 
+       const char * const restrict pbound,
+       const GFC_INTEGER_4 * const restrict pwhich)
+{
+  eoshift1 (ret, array, h, pbound, pwhich, GFC_DESCRIPTOR_SIZE (array),
+           "\0", 1);
+}
+
+
+void eoshift1_4_char (gfc_array_char * const restrict, 
+       GFC_INTEGER_4,
+       const gfc_array_char * const restrict, 
+       const gfc_array_i4 * const restrict,
+       const char * const restrict, 
+       const GFC_INTEGER_4 * const restrict,
+       GFC_INTEGER_4, GFC_INTEGER_4);
+export_proto(eoshift1_4_char);
+
+void
+eoshift1_4_char (gfc_array_char * const restrict ret,
+       GFC_INTEGER_4 ret_length __attribute__((unused)),
+       const gfc_array_char * const restrict array, 
+       const gfc_array_i4 * const restrict h,
+       const char *  const restrict pbound, 
+       const GFC_INTEGER_4 * const restrict pwhich,
+       GFC_INTEGER_4 array_length,
+       GFC_INTEGER_4 bound_length __attribute__((unused)))
+{
+  eoshift1 (ret, array, h, pbound, pwhich, array_length, " ", 1);
+}
+
+
+void eoshift1_4_char4 (gfc_array_char * const restrict, 
+       GFC_INTEGER_4,
+       const gfc_array_char * const restrict, 
+       const gfc_array_i4 * const restrict,
+       const char * const restrict, 
+       const GFC_INTEGER_4 * const restrict,
+       GFC_INTEGER_4, GFC_INTEGER_4);
+export_proto(eoshift1_4_char4);
+
+void
+eoshift1_4_char4 (gfc_array_char * const restrict ret,
+       GFC_INTEGER_4 ret_length __attribute__((unused)),
+       const gfc_array_char * const restrict array, 
+       const gfc_array_i4 * const restrict h,
+       const char *  const restrict pbound, 
+       const GFC_INTEGER_4 * const restrict pwhich,
+       GFC_INTEGER_4 array_length,
+       GFC_INTEGER_4 bound_length __attribute__((unused)))
+{
+  static const gfc_char4_t space = (unsigned char) ' ';
+  eoshift1 (ret, array, h, pbound, pwhich, array_length * sizeof (gfc_char4_t),
+           (const char *) &space, sizeof (gfc_char4_t));
+}
+
+#endif