]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libgfortran/generated/maxloc1_4_i4.c
Update copyright years.
[thirdparty/gcc.git] / libgfortran / generated / maxloc1_4_i4.c
index ee48be84e6f90b400a3cfc2a2ef78422903d8e65..b81ad0f9a3b9c4b949008b52f1de8ce86c57e387 100644 (file)
@@ -1,5 +1,5 @@
 /* Implementation of the MAXLOC intrinsic
-   Copyright (C) 2002-2018 Free Software Foundation, Inc.
+   Copyright (C) 2002-2021 Free Software Foundation, Inc.
    Contributed by Paul Brook <paul@nowt.org>
 
 This file is part of the GNU Fortran runtime library (libgfortran).
@@ -24,19 +24,22 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
 #include "libgfortran.h"
+#include <assert.h>
 
 
 #if defined (HAVE_GFC_INTEGER_4) && defined (HAVE_GFC_INTEGER_4)
 
+#define HAVE_BACK_ARG 1
+
 
 extern void maxloc1_4_i4 (gfc_array_i4 * const restrict, 
-       gfc_array_i4 * const restrict, const index_type * const restrict);
+       gfc_array_i4 * const restrict, const index_type * const restrict, GFC_LOGICAL_4 back);
 export_proto(maxloc1_4_i4);
 
 void
 maxloc1_4_i4 (gfc_array_i4 * const restrict retarray, 
        gfc_array_i4 * const restrict array, 
-       const index_type * const restrict pdim)
+       const index_type * const restrict pdim, GFC_LOGICAL_4 back)
 {
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
@@ -100,7 +103,7 @@ maxloc1_4_i4 (gfc_array_i4 * 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];
 
@@ -156,10 +159,14 @@ maxloc1_4_i4 (gfc_array_i4 * const restrict retarray,
          *dest = 0;
        else
          {
+#if ! defined HAVE_BACK_ARG
            for (n = 0; n < len; n++, src += delta)
              {
+#endif
 
 #if defined (GFC_INTEGER_4_QUIET_NAN)
+            for (n = 0; n < len; n++, src += delta)
+              {
                if (*src >= maxval)
                  {
                    maxval = *src;
@@ -167,10 +174,12 @@ maxloc1_4_i4 (gfc_array_i4 * const restrict retarray,
                    break;
                  }
              }
+#else
+           n = 0;
+#endif
            for (; n < len; n++, src += delta)
              {
-#endif
-               if (*src > maxval)
+               if (back ? *src >= maxval : *src > maxval)
                  {
                    maxval = *src;
                    result = (GFC_INTEGER_4)n + 1;
@@ -214,14 +223,14 @@ maxloc1_4_i4 (gfc_array_i4 * const restrict retarray,
 
 extern void mmaxloc1_4_i4 (gfc_array_i4 * const restrict, 
        gfc_array_i4 * const restrict, const index_type * const restrict,
-       gfc_array_l1 * const restrict);
+       gfc_array_l1 * const restrict, GFC_LOGICAL_4 back);
 export_proto(mmaxloc1_4_i4);
 
 void
 mmaxloc1_4_i4 (gfc_array_i4 * const restrict retarray, 
        gfc_array_i4 * const restrict array, 
        const index_type * const restrict pdim, 
-       gfc_array_l1 * const restrict mask)
+       gfc_array_l1 * const restrict mask, GFC_LOGICAL_4 back)
 {
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
@@ -239,6 +248,16 @@ mmaxloc1_4_i4 (gfc_array_i4 * const restrict retarray,
   index_type mdelta;
   int mask_kind;
 
+  if (mask == NULL)
+    {
+#ifdef HAVE_BACK_ARG
+      maxloc1_4_i4 (retarray, array, pdim, back);
+#else
+      maxloc1_4_i4 (retarray, array, pdim);
+#endif
+      return;
+    }
+
   dim = (*pdim) - 1;
   rank = GFC_DESCRIPTOR_RANK (array) - 1;
 
@@ -308,7 +327,7 @@ mmaxloc1_4_i4 (gfc_array_i4 * 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;
 
       if (alloc_size == 0)
        {
@@ -386,13 +405,23 @@ mmaxloc1_4_i4 (gfc_array_i4 * const restrict retarray,
              result = result2;
            else
 #endif
-           for (; n < len; n++, src += delta, msrc += mdelta)
-             {
-               if (*msrc && *src > maxval)
-                 {
-                   maxval = *src;
-                   result = (GFC_INTEGER_4)n + 1;
-                 }
+           if (back)
+             for (; n < len; n++, src += delta, msrc += mdelta)
+               {
+                 if (*msrc && unlikely (*src >= maxval))
+                   {
+                     maxval = *src;
+                     result = (GFC_INTEGER_4)n + 1;
+                   }
+               }
+           else
+             for (; n < len; n++, src += delta, msrc += mdelta)
+               {
+                 if (*msrc && unlikely (*src > maxval))
+                   {
+                     maxval = *src;
+                     result = (GFC_INTEGER_4)n + 1;
+                   }
          }
        *dest = result;
       }
@@ -433,14 +462,14 @@ mmaxloc1_4_i4 (gfc_array_i4 * const restrict retarray,
 
 extern void smaxloc1_4_i4 (gfc_array_i4 * const restrict, 
        gfc_array_i4 * const restrict, const index_type * const restrict,
-       GFC_LOGICAL_4 *);
+       GFC_LOGICAL_4 *, GFC_LOGICAL_4 back);
 export_proto(smaxloc1_4_i4);
 
 void
 smaxloc1_4_i4 (gfc_array_i4 * const restrict retarray, 
        gfc_array_i4 * const restrict array, 
        const index_type * const restrict pdim, 
-       GFC_LOGICAL_4 * mask)
+       GFC_LOGICAL_4 * mask, GFC_LOGICAL_4 back)
 {
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
@@ -451,9 +480,13 @@ smaxloc1_4_i4 (gfc_array_i4 * const restrict retarray,
   index_type dim;
 
 
-  if (*mask)
+  if (mask == NULL || *mask)
     {
+#ifdef HAVE_BACK_ARG
+      maxloc1_4_i4 (retarray, array, pdim, back);
+#else
       maxloc1_4_i4 (retarray, array, pdim);
+#endif
       return;
     }
   /* Make dim zero based to avoid confusion.  */
@@ -500,7 +533,7 @@ smaxloc1_4_i4 (gfc_array_i4 * 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];