OSDN Git Service

Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[pf3gnuchains/gcc-fork.git] / libgfortran / generated / eoshift3_4.c
index 14c38b7..a165945 100644 (file)
@@ -1,5 +1,5 @@
 /* Implementation of the EOSHIFT intrinsic
-   Copyright 2002, 2005 Free Software Foundation, Inc.
+   Copyright 2002, 2005, 2007, 2009 Free Software Foundation, Inc.
    Contributed by Paul Brook <paul@nowt.org>
 
 This file is part of the GNU Fortran 95 runtime library (libgfortran).
@@ -7,52 +7,44 @@ This file is part of the GNU Fortran 95 runtime library (libgfortran).
 Libgfortran is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public
 License as published by the Free Software Foundation; either
-version 2 of the License, or (at your option) any later version.
-
-In addition to the permissions in the GNU General Public License, the
-Free Software Foundation gives you unlimited permission to link the
-compiled version of this file into combinations with other programs,
-and to distribute those combinations without any restriction coming
-from the use of this file.  (The General Public License restrictions
-do apply in other respects; for example, they cover modification of
-the file, and distribution when not linked into a combine
-executable.)
+version 3 of the License, or (at your option) any later version.
 
 Libgfortran is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
-You should have received a copy of the GNU General Public
-License along with libgfortran; see the file COPYING.  If not,
-write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
 
-#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 eoshift3_4 (gfc_array_char *, gfc_array_char *,
-                                    gfc_array_i4 *, const gfc_array_char *,
-                                    GFC_INTEGER_4 *);
-export_proto(eoshift3_4);
+#if defined (HAVE_GFC_INTEGER_4)
 
-void
-eoshift3_4 (gfc_array_char *ret, gfc_array_char *array,
-                      gfc_array_i4 *h, const gfc_array_char *bound,
-                      GFC_INTEGER_4 *pwhich)
+static void
+eoshift3 (gfc_array_char * const restrict ret, 
+       const gfc_array_char * const restrict array, 
+       const gfc_array_i4 * const restrict h,
+       const gfc_array_char * const restrict bound, 
+       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;
@@ -71,7 +63,6 @@ eoshift3_4 (gfc_array_char *ret, gfc_array_char *array,
   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;
@@ -89,13 +80,12 @@ eoshift3_4 (gfc_array_char *ret, gfc_array_char *array,
   else
     which = 0;
 
-  size = GFC_DESCRIPTOR_SIZE (ret);
   if (ret->data == NULL)
     {
       int i;
 
       ret->data = internal_malloc_size (size * size0 ((array_t *)array));
-      ret->base = 0;
+      ret->offset = 0;
       ret->dtype = array->dtype;
       for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
         {
@@ -108,11 +98,15 @@ eoshift3_4 (gfc_array_char *ret, gfc_array_char *array,
             ret->dim[i].stride = (ret->dim[i-1].ubound + 1) * ret->dim[i-1].stride;
         }
     }
+  else
+    {
+      if (size0 ((array_t *) ret) == 0)
+       return;
+    }
 
 
   extent[0] = 1;
   count[0] = 0;
-  size = GFC_DESCRIPTOR_SIZE (array);
   n = 0;
   for (dim = 0; dim < GFC_DESCRIPTOR_RANK (array); dim++)
     {
@@ -135,7 +129,7 @@ eoshift3_4 (gfc_array_char *ret, gfc_array_char *array,
 
           hstride[n] = h->dim[n].stride;
           if (bound)
-            bstride[n] = bound->dim[n].stride;
+            bstride[n] = bound->dim[n].stride * size;
           else
             bstride[n] = 0;
           n++;
@@ -161,13 +155,20 @@ eoshift3_4 (gfc_array_char *ret, gfc_array_char *array,
   if (bound)
     bptr = bound->data;
   else
-    bptr = zeros;
+    bptr = NULL;
 
   while (rptr)
     {
       /* Do the shift for this dimension.  */
       sh = *hptr;
-      delta = (sh >= 0) ? sh: -sh;
+      if (( sh >= 0 ? sh : -sh ) > len)
+       {
+         delta = len;
+         sh = len;
+       }
+      else
+       delta = (sh >= 0) ? sh: -sh;
+
       if (sh > 0)
         {
           src = &sptr[delta * soffset];
@@ -188,11 +189,25 @@ eoshift3_4 (gfc_array_char *ret, gfc_array_char *array,
         dest = rptr;
       n = delta;
 
-      while (n--)
-        {
-          memcpy (dest, bptr, size);
-          dest += roffset;
-        }
+      if (bptr)
+       while (n--)
+         {
+           memcpy (dest, bptr, 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;
@@ -207,7 +222,7 @@ eoshift3_4 (gfc_array_char *ret, gfc_array_char *array,
              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];
@@ -230,3 +245,71 @@ eoshift3_4 (gfc_array_char *ret, gfc_array_char *array,
         }
     }
 }
+
+extern void eoshift3_4 (gfc_array_char * const restrict, 
+       const gfc_array_char * const restrict,
+       const gfc_array_i4 * const restrict, 
+       const gfc_array_char * const restrict,
+       const GFC_INTEGER_4 *);
+export_proto(eoshift3_4);
+
+void
+eoshift3_4 (gfc_array_char * const restrict ret, 
+       const gfc_array_char * const restrict array,
+       const gfc_array_i4 * const restrict h, 
+       const gfc_array_char * const restrict bound,
+       const GFC_INTEGER_4 * const restrict pwhich)
+{
+  eoshift3 (ret, array, h, bound, pwhich, GFC_DESCRIPTOR_SIZE (array),
+           "\0", 1);
+}
+
+
+extern void eoshift3_4_char (gfc_array_char * const restrict, 
+       GFC_INTEGER_4,
+       const gfc_array_char * const restrict,
+       const gfc_array_i4 * const restrict,
+       const gfc_array_char * const restrict,
+       const GFC_INTEGER_4 * const restrict, 
+       GFC_INTEGER_4, GFC_INTEGER_4);
+export_proto(eoshift3_4_char);
+
+void
+eoshift3_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 gfc_array_char * const restrict bound,
+       const GFC_INTEGER_4 * const restrict pwhich,
+       GFC_INTEGER_4 array_length,
+       GFC_INTEGER_4 bound_length __attribute__((unused)))
+{
+  eoshift3 (ret, array, h, bound, pwhich, array_length, " ", 1);
+}
+
+
+extern void eoshift3_4_char4 (gfc_array_char * const restrict, 
+       GFC_INTEGER_4,
+       const gfc_array_char * const restrict,
+       const gfc_array_i4 * const restrict,
+       const gfc_array_char * const restrict,
+       const GFC_INTEGER_4 * const restrict, 
+       GFC_INTEGER_4, GFC_INTEGER_4);
+export_proto(eoshift3_4_char4);
+
+void
+eoshift3_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 gfc_array_char * const restrict bound,
+       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) ' ';
+  eoshift3 (ret, array, h, bound, pwhich, array_length * sizeof (gfc_char4_t),
+           (const char *) &space, sizeof (gfc_char4_t));
+}
+
+#endif