2018-03-08 Richard Biener <rguenther@suse.de>
[official-gcc.git] / libgfortran / m4 / maxloc0.m4
blob98d898f86a7ea72d99d0ad55ecce534378634ebb
1 `/* Implementation of the MAXLOC intrinsic
2    Copyright (C) 2002-2018 Free Software Foundation, Inc.
3    Contributed by Paul Brook <paul@nowt.org>
5 This file is part of the GNU Fortran 95 runtime library (libgfortran).
7 Libgfortran is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either
10 version 3 of the License, or (at your option) any later version.
12 Libgfortran is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24 <http://www.gnu.org/licenses/>.  */
26 #include "libgfortran.h"
27 #include <assert.h>'
29 include(iparm.m4)dnl
30 include(iforeach.m4)dnl
32 `#if defined (HAVE_'atype_name`) && defined (HAVE_'rtype_name`)'
34 FOREACH_FUNCTION(
35 `    atype_name maxval;
36 #if defined('atype_nan`)
37     int fast = 0;
38 #endif
40 #if defined('atype_inf`)
41     maxval = -atype_inf;
42 #else
43     maxval = atype_min;
44 #endif',
45 `#if defined('atype_nan`)
46         }
47       while (0);
48       if (unlikely (!fast))
49         {
50           do
51             {
52               if (*base >= maxval)
53                 {
54                   fast = 1;
55                   maxval = *base;
56                   for (n = 0; n < rank; n++)
57                     dest[n * dstride] = count[n] + 1;
58                   break;
59                 }
60               base += sstride[0];
61             }
62           while (++count[0] != extent[0]);
63           if (likely (fast))
64             continue;
65         }
66       else do
67         {
68 #endif
69           if (*base > maxval)
70             {
71               maxval = *base;
72               for (n = 0; n < rank; n++)
73                 dest[n * dstride] = count[n] + 1;
74             }')
76 MASKED_FOREACH_FUNCTION(
77 `  atype_name maxval;
78    int fast = 0;
80 #if defined('atype_inf`)
81     maxval = -atype_inf;
82 #else
83     maxval = atype_min;
84 #endif',
85 `       }
86       while (0);
87       if (unlikely (!fast))
88         {
89           do
90             {
91               if (*mbase)
92                 {
93 #if defined('atype_nan`)
94                   if (unlikely (dest[0] == 0))
95                     for (n = 0; n < rank; n++)
96                       dest[n * dstride] = count[n] + 1;
97                   if (*base >= maxval)
98 #endif
99                     {
100                       fast = 1;
101                       maxval = *base;
102                       for (n = 0; n < rank; n++)
103                         dest[n * dstride] = count[n] + 1;
104                       break;
105                     }
106                 }
107               base += sstride[0];
108               mbase += mstride[0];
109             }
110           while (++count[0] != extent[0]);
111           if (likely (fast))
112             continue;
113         }
114       else do
115         {
116           if (*mbase && *base > maxval)
117             {
118               maxval = *base;
119               for (n = 0; n < rank; n++)
120                 dest[n * dstride] = count[n] + 1;
121             }')
123 SCALAR_FOREACH_FUNCTION(`0')
124 #endif