]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libgfortran/generated/maxloc1_16_s1.c
Update copyright years.
[thirdparty/gcc.git] / libgfortran / generated / maxloc1_16_s1.c
index f74539729656314f65bddfc00b7be4fa8e6f9ff0..eddfe5f44cc7faed213ed975f8e2c0ea02c68755 100644 (file)
@@ -1,5 +1,5 @@
 /* Implementation of the MAXLOC intrinsic
-   Copyright (C) 2017-2018 Free Software Foundation, Inc.
+   Copyright (C) 2017-2024 Free Software Foundation, Inc.
    Contributed by Thomas Koenig
 
 This file is part of the GNU Fortran runtime library (libgfortran).
@@ -26,34 +26,38 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #include "libgfortran.h"
 
 
-#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_16)
+#if defined (HAVE_GFC_UINTEGER_1) && defined (HAVE_GFC_INTEGER_16)
+
+#define HAVE_BACK_ARG 1
 
 #include <string.h>
+#include <assert.h>
 
 static inline int
-compare_fcn (const GFC_INTEGER_1 *a, const GFC_INTEGER_1 *b, gfc_charlen_type n)
+compare_fcn (const GFC_UINTEGER_1 *a, const GFC_UINTEGER_1 *b, gfc_charlen_type n)
 {
-  if (sizeof (GFC_INTEGER_1) == 1)
+  if (sizeof (GFC_UINTEGER_1) == 1)
     return memcmp (a, b, n);
   else
     return memcmp_char4 (a, b, n);
 }
 
 extern void maxloc1_16_s1 (gfc_array_i16 * const restrict, 
-       gfc_array_s1 * const restrict, const index_type * const restrict,
+       gfc_array_s1 * const restrict, const index_type * const restrict , GFC_LOGICAL_4 back,
        gfc_charlen_type);
 export_proto(maxloc1_16_s1);
 
 void
 maxloc1_16_s1 (gfc_array_i16 * const restrict retarray, 
        gfc_array_s1 * const restrict array, 
-       const index_type * const restrict pdim, gfc_charlen_type string_len)
+       const index_type * const restrict pdim, GFC_LOGICAL_4 back,
+       gfc_charlen_type string_len)
 {
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sstride[GFC_MAX_DIMENSIONS];
   index_type dstride[GFC_MAX_DIMENSIONS];
-  const GFC_INTEGER_1 * restrict base;
+  const GFC_UINTEGER_1 * restrict base;
   GFC_INTEGER_16 * restrict dest;
   index_type rank;
   index_type n;
@@ -111,18 +115,13 @@ maxloc1_16_s1 (gfc_array_i16 * const restrict retarray,
        }
 
       retarray->offset = 0;
-      retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+      retarray->dtype.rank = rank;
 
       alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
 
       retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
       if (alloc_size == 0)
-       {
-         /* Make sure we have a zero-sized array.  */
-         GFC_DIMENSION_SET(retarray->dim[0], 0, -1, 1);
-         return;
-
-       }
+       return;
     }
   else
     {
@@ -151,14 +150,14 @@ maxloc1_16_s1 (gfc_array_i16 * const restrict retarray,
   continue_loop = 1;
   while (continue_loop)
     {
-      const GFC_INTEGER_1 * restrict src;
+      const GFC_UINTEGER_1 * restrict src;
       GFC_INTEGER_16 result;
       src = base;
       {
 
-       const GFC_INTEGER_1 *maxval;
-       maxval = base;
-       result = 1;
+       const GFC_UINTEGER_1 *maxval;
+       maxval = NULL;
+       result = 0;
        if (len <= 0)
          *dest = 0;
        else
@@ -166,7 +165,8 @@ maxloc1_16_s1 (gfc_array_i16 * const restrict retarray,
            for (n = 0; n < len; n++, src += delta)
              {
 
-               if (compare_fcn (src, maxval, string_len) > 0)
+               if (maxval == NULL || (back ? compare_fcn (src, maxval, string_len) >= 0 :
+                                             compare_fcn (src, maxval, string_len) > 0))
                  {
                    maxval = src;
                    result = (GFC_INTEGER_16)n + 1;
@@ -210,14 +210,15 @@ maxloc1_16_s1 (gfc_array_i16 * const restrict retarray,
 
 extern void mmaxloc1_16_s1 (gfc_array_i16 * const restrict, 
        gfc_array_s1 * const restrict, const index_type * const restrict,
-       gfc_array_l1 * const restrict, gfc_charlen_type);
+       gfc_array_l1 * const restrict, GFC_LOGICAL_4 back, gfc_charlen_type);
 export_proto(mmaxloc1_16_s1);
 
 void
 mmaxloc1_16_s1 (gfc_array_i16 * const restrict retarray, 
        gfc_array_s1 * const restrict array, 
        const index_type * const restrict pdim, 
-       gfc_array_l1 * const restrict mask, gfc_charlen_type string_len)
+       gfc_array_l1 * const restrict mask, GFC_LOGICAL_4 back,
+       gfc_charlen_type string_len)
 {
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
@@ -225,7 +226,7 @@ mmaxloc1_16_s1 (gfc_array_i16 * const restrict retarray,
   index_type dstride[GFC_MAX_DIMENSIONS];
   index_type mstride[GFC_MAX_DIMENSIONS];
   GFC_INTEGER_16 * restrict dest;
-  const GFC_INTEGER_1 * restrict base;
+  const GFC_UINTEGER_1 * restrict base;
   const GFC_LOGICAL_1 * restrict mbase;
   index_type rank;
   index_type dim;
@@ -235,6 +236,16 @@ mmaxloc1_16_s1 (gfc_array_i16 * const restrict retarray,
   index_type mdelta;
   int mask_kind;
 
+  if (mask == NULL)
+    {
+#ifdef HAVE_BACK_ARG
+      maxloc1_16_s1 (retarray, array, pdim, back, string_len);
+#else
+      maxloc1_16_s1 (retarray, array, pdim, string_len);
+#endif
+      return;
+    }
+
   dim = (*pdim) - 1;
   rank = GFC_DESCRIPTOR_RANK (array) - 1;
 
@@ -247,8 +258,8 @@ mmaxloc1_16_s1 (gfc_array_i16 * const restrict retarray,
     }
 
   len = GFC_DESCRIPTOR_EXTENT(array,dim);
-  if (len <= 0)
-    return;
+  if (len < 0)
+    len = 0;
 
   mbase = mask->base_addr;
 
@@ -304,17 +315,11 @@ mmaxloc1_16_s1 (gfc_array_i16 * const restrict retarray,
       alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
 
       retarray->offset = 0;
-      retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+      retarray->dtype.rank = rank;
 
+      retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
       if (alloc_size == 0)
-       {
-         /* Make sure we have a zero-sized array.  */
-         GFC_DIMENSION_SET(retarray->dim[0], 0, -1, 1);
-         return;
-       }
-      else
-       retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
-
+       return;
     }
   else
     {
@@ -343,14 +348,14 @@ mmaxloc1_16_s1 (gfc_array_i16 * const restrict retarray,
 
   while (base)
     {
-      const GFC_INTEGER_1 * restrict src;
+      const GFC_UINTEGER_1 * restrict src;
       const GFC_LOGICAL_1 * restrict msrc;
       GFC_INTEGER_16 result;
       src = base;
       msrc = mbase;
       {
 
-       const GFC_INTEGER_1 *maxval;
+       const GFC_UINTEGER_1 *maxval;
        maxval = base;
        result = 0;
        for (n = 0; n < len; n++, src += delta, msrc += mdelta)
@@ -365,7 +370,8 @@ mmaxloc1_16_s1 (gfc_array_i16 * const restrict retarray,
            }
            for (; n < len; n++, src += delta, msrc += mdelta)
              {
-               if (*msrc && compare_fcn (src, maxval, string_len) > 0)
+               if (*msrc && (back ? compare_fcn (src, maxval, string_len) >= 0 :
+                                    compare_fcn (src, maxval, string_len) > 0))
                  {
                    maxval = src;
                    result = (GFC_INTEGER_16)n + 1;
@@ -411,14 +417,14 @@ mmaxloc1_16_s1 (gfc_array_i16 * const restrict retarray,
 
 extern void smaxloc1_16_s1 (gfc_array_i16 * const restrict, 
        gfc_array_s1 * const restrict, const index_type * const restrict,
-       GFC_LOGICAL_4 *, gfc_charlen_type);
+       GFC_LOGICAL_4 *, GFC_LOGICAL_4 back, gfc_charlen_type);
 export_proto(smaxloc1_16_s1);
 
 void
 smaxloc1_16_s1 (gfc_array_i16 * const restrict retarray, 
        gfc_array_s1 * const restrict array, 
        const index_type * const restrict pdim, 
-       GFC_LOGICAL_4 * mask, gfc_charlen_type string_len)
+       GFC_LOGICAL_4 * mask , GFC_LOGICAL_4 back, gfc_charlen_type string_len)
 {
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
@@ -429,9 +435,13 @@ smaxloc1_16_s1 (gfc_array_i16 * const restrict retarray,
   index_type dim;
 
 
-  if (*mask)
+  if (mask == NULL || *mask)
     {
+#ifdef HAVE_BACK_ARG
+      maxloc1_16_s1 (retarray, array, pdim, back, string_len);
+#else
       maxloc1_16_s1 (retarray, array, pdim, string_len);
+#endif
       return;
     }
   /* Make dim zero based to avoid confusion.  */
@@ -478,18 +488,13 @@ smaxloc1_16_s1 (gfc_array_i16 * const restrict retarray,
        }
 
       retarray->offset = 0;
-      retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+      retarray->dtype.rank = rank;
 
       alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
 
+      retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
       if (alloc_size == 0)
-       {
-         /* Make sure we have a zero-sized array.  */
-         GFC_DIMENSION_SET(retarray->dim[0], 0, -1, 1);
-         return;
-       }
-      else
-       retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+       return;
     }
   else
     {