]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libgfortran/generated/minloc0_4_s1.c
Update copyright years.
[thirdparty/gcc.git] / libgfortran / generated / minloc0_4_s1.c
index 47d71c5174ab0eb6ce0d62eba1832c9910190227..3ab4d9e0cb7da83302dc6f302965289e332fc29e 100644 (file)
@@ -1,5 +1,5 @@
 /* Implementation of the MINLOC 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).
@@ -30,12 +30,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #include <limits.h>
 
 
-#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_4)
+#if defined (HAVE_GFC_UINTEGER_1) && defined (HAVE_GFC_INTEGER_4)
+
+#define HAVE_BACK_ARG 1
 
 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);
@@ -43,18 +45,18 @@ compare_fcn (const GFC_INTEGER_1 *a, const GFC_INTEGER_1 *b, gfc_charlen_type n)
 }
 
 extern void minloc0_4_s1 (gfc_array_i4 * const restrict retarray, 
-       gfc_array_s1 * const restrict array, gfc_charlen_type len);
+       gfc_array_s1 * const restrict array, GFC_LOGICAL_4 back, gfc_charlen_type len);
 export_proto(minloc0_4_s1);
 
 void
 minloc0_4_s1 (gfc_array_i4 * const restrict retarray, 
-       gfc_array_s1 * const restrict array, gfc_charlen_type len)
+       gfc_array_s1 * const restrict array, GFC_LOGICAL_4 back, gfc_charlen_type len)
 {
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sstride[GFC_MAX_DIMENSIONS];
   index_type dstride;
-  const GFC_INTEGER_1 *base;
+  const GFC_UINTEGER_1 *base;
   GFC_INTEGER_4 * restrict dest;
   index_type rank;
   index_type n;
@@ -66,7 +68,7 @@ minloc0_4_s1 (gfc_array_i4 * const restrict retarray,
   if (retarray->base_addr == NULL)
     {
       GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
-      retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+      retarray->dtype.rank = 1;
       retarray->offset = 0;
       retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
     }
@@ -100,8 +102,8 @@ minloc0_4_s1 (gfc_array_i4 * const restrict retarray,
     dest[n * dstride] = 1;
   {
 
-  const GFC_INTEGER_1 *minval;
-   minval = base;
+  const GFC_UINTEGER_1 *minval;
+   minval = NULL;
 
   while (base)
     {
@@ -109,7 +111,8 @@ minloc0_4_s1 (gfc_array_i4 * const restrict retarray,
        {
          /* Implementation start.  */
 
-  if (compare_fcn (base, minval, len) < 0)
+    if (minval == NULL || (back ? compare_fcn (base, minval, len) <= 0 :
+                                          compare_fcn (base, minval, len) < 0))
     {
       minval = base;
       for (n = 0; n < rank; n++)
@@ -149,13 +152,15 @@ minloc0_4_s1 (gfc_array_i4 * const restrict retarray,
 
 
 extern void mminloc0_4_s1 (gfc_array_i4 * const restrict, 
-       gfc_array_s1 * const restrict, gfc_array_l1 * const restrict, gfc_charlen_type len);
+       gfc_array_s1 * const restrict, gfc_array_l1 * const restrict , GFC_LOGICAL_4 back,
+       gfc_charlen_type len);
 export_proto(mminloc0_4_s1);
 
 void
 mminloc0_4_s1 (gfc_array_i4 * const restrict retarray, 
        gfc_array_s1 * const restrict array,
-       gfc_array_l1 * const restrict mask, gfc_charlen_type len)
+       gfc_array_l1 * const restrict mask, GFC_LOGICAL_4 back,
+       gfc_charlen_type len)
 {
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
@@ -163,12 +168,22 @@ mminloc0_4_s1 (gfc_array_i4 * const restrict retarray,
   index_type mstride[GFC_MAX_DIMENSIONS];
   index_type dstride;
   GFC_INTEGER_4 *dest;
-  const GFC_INTEGER_1 *base;
+  const GFC_UINTEGER_1 *base;
   GFC_LOGICAL_1 *mbase;
   int rank;
   index_type n;
   int mask_kind;
 
+  if (mask == NULL)
+    {
+#ifdef HAVE_BACK_ARG    
+      minloc0_4_s1 (retarray, array, back, len);
+#else
+      minloc0_4_s1 (retarray, array, len);
+#endif
+      return;
+    }
+
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
     runtime_error ("Rank of array needs to be > 0");
@@ -176,7 +191,7 @@ mminloc0_4_s1 (gfc_array_i4 * const restrict retarray,
   if (retarray->base_addr == NULL)
     {
       GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
-      retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+      retarray->dtype.rank = 1;
       retarray->offset = 0;
       retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
     }
@@ -229,7 +244,7 @@ mminloc0_4_s1 (gfc_array_i4 * const restrict retarray,
     dest[n * dstride] = 0;
   {
 
-  const GFC_INTEGER_1 *minval;
+  const GFC_UINTEGER_1 *minval;
 
   minval = NULL;
 
@@ -239,7 +254,9 @@ mminloc0_4_s1 (gfc_array_i4 * const restrict retarray,
        {
          /* Implementation start.  */
 
-  if (*mbase && (minval == NULL || compare_fcn (base, minval, len) < 0))
+  if (*mbase &&
+      (minval == NULL || (back ? compare_fcn (base, minval, len) <= 0 :
+                                        compare_fcn (base, minval, len) < 0)))
     {
       minval = base;
       for (n = 0; n < rank; n++)
@@ -282,22 +299,28 @@ mminloc0_4_s1 (gfc_array_i4 * const restrict retarray,
 
 
 extern void sminloc0_4_s1 (gfc_array_i4 * const restrict, 
-       gfc_array_s1 * const restrict, GFC_LOGICAL_4 *, gfc_charlen_type len);
+       gfc_array_s1 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4 back,
+       gfc_charlen_type len);
 export_proto(sminloc0_4_s1);
 
 void
 sminloc0_4_s1 (gfc_array_i4 * const restrict retarray, 
        gfc_array_s1 * const restrict array,
-       GFC_LOGICAL_4 * mask, gfc_charlen_type len)
+       GFC_LOGICAL_4 * mask, GFC_LOGICAL_4 back,
+       gfc_charlen_type len)
 {
   index_type rank;
   index_type dstride;
   index_type n;
   GFC_INTEGER_4 *dest;
 
-  if (*mask)
+  if (mask == NULL || *mask)
     {
+#ifdef HAVE_BACK_ARG    
+      minloc0_4_s1 (retarray, array, back, len);
+#else
       minloc0_4_s1 (retarray, array, len);
+#endif
       return;
     }
 
@@ -309,7 +332,7 @@ sminloc0_4_s1 (gfc_array_i4 * const restrict retarray,
   if (retarray->base_addr == NULL)
     {
       GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
-      retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+      retarray->dtype.rank = 1;
       retarray->offset = 0;
       retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
     }