]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libgfortran/m4/maxloc1.m4
Update copyright years.
[thirdparty/gcc.git] / libgfortran / m4 / maxloc1.m4
index b609e88021e914a07d76b700a2bc4a4212532351..a5069a92034fc118b253276cd1aa2035d8e19e79 100644 (file)
@@ -1,5 +1,5 @@
 `/* Implementation of the MAXLOC intrinsic
-   Copyright (C) 2002-2015 Free Software Foundation, Inc.
+   Copyright (C) 2002-2023 Free Software Foundation, Inc.
    Contributed by Paul Brook <paul@nowt.org>
 
 This file is part of the GNU Fortran runtime library (libgfortran).
@@ -24,15 +24,15 @@ 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 <limits.h>'
+#include <assert.h>'
 
 include(iparm.m4)dnl
 include(ifunction.m4)dnl
 
 `#if defined (HAVE_'atype_name`) && defined (HAVE_'rtype_name`)'
 
+#define HAVE_BACK_ARG 1
+
 ARRAY_FUNCTION(0,
 `      atype_name maxval;
 #if defined ('atype_inf`)
@@ -42,6 +42,8 @@ ARRAY_FUNCTION(0,
 #endif
        result = 1;',
 `#if defined ('atype_nan`)
+            for (n = 0; n < len; n++, src += delta)
+              {
                if (*src >= maxval)
                  {
                    maxval = *src;
@@ -49,10 +51,12 @@ ARRAY_FUNCTION(0,
                    break;
                  }
              }
+#else
+           n = 0;
+#endif
            for (; n < len; n++, src += delta)
              {
-#endif
-               if (*src > maxval)
+               if (back ? *src >= maxval : *src > maxval)
                  {
                    maxval = *src;
                    result = (rtype_name)n + 1;
@@ -88,13 +92,23 @@ MASKED_ARRAY_FUNCTION(0,
              result = result2;
            else
 #endif
-           for (; n < len; n++, src += delta, msrc += mdelta)
-             {
-               if (*msrc && *src > maxval)
-                 {
-                   maxval = *src;
-                   result = (rtype_name)n + 1;
-                 }')
+           if (back)
+             for (; n < len; n++, src += delta, msrc += mdelta)
+               {
+                 if (*msrc && unlikely (*src >= maxval))
+                   {
+                     maxval = *src;
+                     result = (rtype_name)n + 1;
+                   }
+               }
+           else
+             for (; n < len; n++, src += delta, msrc += mdelta)
+               {
+                 if (*msrc && unlikely (*src > maxval))
+                   {
+                     maxval = *src;
+                     result = (rtype_name)n + 1;
+                   }')
 
 SCALAR_ARRAY_FUNCTION(0)