]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libgfortran/generated/eoshift3_8.c
Update copyright years.
[thirdparty/gcc.git] / libgfortran / generated / eoshift3_8.c
index 7a7b196eec4840d829fe5a6924e516b28e4274e8..49d9406607df19230fa19449445b2e8e35a77788 100644 (file)
@@ -1,8 +1,8 @@
 /* Implementation of the EOSHIFT intrinsic
-   Copyright 2002, 2005, 2007, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2002-2024 Free Software Foundation, Inc.
    Contributed by Paul Brook <paul@nowt.org>
 
-This file is part of the GNU Fortran 95 runtime library (libgfortran).
+This file is part of the GNU Fortran runtime library (libgfortran).
 
 Libgfortran is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public
@@ -24,8 +24,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
 #include "libgfortran.h"
-#include <stdlib.h>
-#include <assert.h>
 #include <string.h>
 
 
@@ -85,14 +83,12 @@ eoshift3 (gfc_array_char * const restrict ret,
   else
     which = 0;
 
-  if (ret->data == NULL)
+  if (ret->base_addr == NULL)
     {
-      int i;
-
-      ret->data = internal_malloc_size (size * arraysize);
+      ret->base_addr = xmallocarray (arraysize, size);
       ret->offset = 0;
-      ret->dtype = array->dtype;
-      for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+      GFC_DTYPE_COPY(ret,array);
+      for (index_type i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
         {
          index_type ub, str;
 
@@ -107,8 +103,8 @@ eoshift3 (gfc_array_char * const restrict ret,
          GFC_DIMENSION_SET(ret->dim[i], 0, ub, str);
 
         }
-      /* internal_malloc_size allocates a single byte for zero size.  */
-      ret->data = internal_malloc_size (size * arraysize);
+      /* xmallocarray allocates a single byte for zero size.  */
+      ret->base_addr = xmallocarray (arraysize, size);
 
     }
   else if (unlikely (compile_options.bounds_check))
@@ -170,11 +166,11 @@ eoshift3 (gfc_array_char * const restrict ret,
   sstride0 = sstride[0];
   hstride0 = hstride[0];
   bstride0 = bstride[0];
-  rptr = ret->data;
-  sptr = array->data;
-  hptr = h->data;
+  rptr = ret->base_addr;
+  sptr = array->base_addr;
+  hptr = h->base_addr;
   if (bound)
-    bptr = bound->data;
+    bptr = bound->base_addr;
   else
     bptr = NULL;
 
@@ -200,12 +196,24 @@ eoshift3 (gfc_array_char * const restrict ret,
           src = sptr;
           dest = &rptr[delta * roffset];
         }
-      for (n = 0; n < len - delta; n++)
-        {
-          memcpy (dest, src, size);
-          dest += roffset;
-          src += soffset;
-        }
+
+      /* If the elements are contiguous, perform a single block move.  */
+      if (soffset == size && roffset == size)
+       {
+         size_t chunk = size * (len - delta);
+         memcpy (dest, src, chunk);
+         dest += chunk;
+       }
+      else
+       {
+         for (n = 0; n < len - delta; n++)
+           {
+             memcpy (dest, src, size);
+             dest += roffset;
+             src += soffset;
+           }
+       }
+
       if (sh < 0)
         dest = rptr;
       n = delta;