]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libgfortran/generated/minloc1_4_r4.c
Update copyright years.
[thirdparty/gcc.git] / libgfortran / generated / minloc1_4_r4.c
index d79f905a659da3771529ac2146374a827684d047..0e55bd9986314032da1cd396f6eb4056c4b35994 100644 (file)
@@ -1,5 +1,5 @@
 /* Implementation of the MINLOC intrinsic
-   Copyright (C) 2002-2017 Free Software Foundation, Inc.
+   Copyright (C) 2002-2020 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_REAL_4) && defined (HAVE_GFC_INTEGER_4)
 
+#define HAVE_BACK_ARG 1
+
 
 extern void minloc1_4_r4 (gfc_array_i4 * const restrict, 
-       gfc_array_r4 * const restrict, const index_type * const restrict);
+       gfc_array_r4 * const restrict, const index_type * const restrict, GFC_LOGICAL_4 back);
 export_proto(minloc1_4_r4);
 
 void
 minloc1_4_r4 (gfc_array_i4 * const restrict retarray, 
        gfc_array_r4 * 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 @@ minloc1_4_r4 (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 @@ minloc1_4_r4 (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_REAL_4_QUIET_NAN)
+          for (n = 0; n < len; n++, src += delta)
+            {
                if (*src <= minval)
                  {
                    minval = *src;
@@ -167,14 +174,26 @@ minloc1_4_r4 (gfc_array_i4 * const restrict retarray,
                    break;
                  }
              }
-           for (; n < len; n++, src += delta)
-             {
+#else
+           n = 0;
 #endif
-               if (*src < minval)
-                 {
-                   minval = *src;
-                   result = (GFC_INTEGER_4)n + 1;
-                 }
+           if (back)
+             for (; n < len; n++, src += delta)
+               {
+                 if (unlikely (*src <= minval))
+                   {
+                     minval = *src;
+                     result = (GFC_INTEGER_4)n + 1;
+                   }
+               }
+           else
+             for (; n < len; n++, src += delta)
+               {
+                 if (unlikely (*src < minval))
+                   {
+                     minval = *src;
+                     result = (GFC_INTEGER_4) n + 1;
+                   }
              }
            
            *dest = result;
@@ -214,14 +233,14 @@ minloc1_4_r4 (gfc_array_i4 * const restrict retarray,
 
 extern void mminloc1_4_r4 (gfc_array_i4 * const restrict, 
        gfc_array_r4 * const restrict, const index_type * const restrict,
-       gfc_array_l1 * const restrict);
+       gfc_array_l1 * const restrict, GFC_LOGICAL_4 back);
 export_proto(mminloc1_4_r4);
 
 void
 mminloc1_4_r4 (gfc_array_i4 * const restrict retarray, 
        gfc_array_r4 * 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 +258,16 @@ mminloc1_4_r4 (gfc_array_i4 * const restrict retarray,
   index_type mdelta;
   int mask_kind;
 
+  if (mask == NULL)
+    {
+#ifdef HAVE_BACK_ARG
+      minloc1_4_r4 (retarray, array, pdim, back);
+#else
+      minloc1_4_r4 (retarray, array, pdim);
+#endif
+      return;
+    }
+
   dim = (*pdim) - 1;
   rank = GFC_DESCRIPTOR_RANK (array) - 1;
 
@@ -308,7 +337,7 @@ mminloc1_4_r4 (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 +415,23 @@ mminloc1_4_r4 (gfc_array_i4 * const restrict retarray,
              result = result2;
            else
 #endif
-           for (; n < len; n++, src += delta, msrc += mdelta)
-             {
-               if (*msrc && *src < minval)
+           if (back)
+             for (; n < len; n++, src += delta, msrc += mdelta)
+               {
+                 if (*msrc && unlikely (*src <= minval))
+                   {
+                     minval = *src;
+                     result = (GFC_INTEGER_4)n + 1;
+                   }
+               }
+             else
+               for (; n < len; n++, src += delta, msrc += mdelta)
                  {
-                   minval = *src;
-                   result = (GFC_INTEGER_4)n + 1;
-                 }
+                   if (*msrc && unlikely (*src < minval))
+                     {
+                       minval = *src;
+                       result = (GFC_INTEGER_4) n + 1;
+                     }
          }
        *dest = result;
       }
@@ -433,14 +472,14 @@ mminloc1_4_r4 (gfc_array_i4 * const restrict retarray,
 
 extern void sminloc1_4_r4 (gfc_array_i4 * const restrict, 
        gfc_array_r4 * const restrict, const index_type * const restrict,
-       GFC_LOGICAL_4 *);
+       GFC_LOGICAL_4 *, GFC_LOGICAL_4 back);
 export_proto(sminloc1_4_r4);
 
 void
 sminloc1_4_r4 (gfc_array_i4 * const restrict retarray, 
        gfc_array_r4 * 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 +490,13 @@ sminloc1_4_r4 (gfc_array_i4 * const restrict retarray,
   index_type dim;
 
 
-  if (*mask)
+  if (mask == NULL || *mask)
     {
+#ifdef HAVE_BACK_ARG
+      minloc1_4_r4 (retarray, array, pdim, back);
+#else
       minloc1_4_r4 (retarray, array, pdim);
+#endif
       return;
     }
   /* Make dim zero based to avoid confusion.  */
@@ -500,7 +543,7 @@ sminloc1_4_r4 (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];