]>
Commit | Line | Data |
---|---|---|
6de9cd9a | 1 | `/* Implementation of the MAXLOC intrinsic |
a945c346 | 2 | Copyright (C) 2002-2024 Free Software Foundation, Inc. |
6de9cd9a DN |
3 | Contributed by Paul Brook <paul@nowt.org> |
4 | ||
0cd0559e | 5 | This file is part of the GNU Fortran runtime library (libgfortran). |
6de9cd9a DN |
6 | |
7 | Libgfortran is free software; you can redistribute it and/or | |
57dea9f6 | 8 | modify it under the terms of the GNU General Public |
6de9cd9a | 9 | License as published by the Free Software Foundation; either |
748086b7 | 10 | version 3 of the License, or (at your option) any later version. |
6de9cd9a DN |
11 | |
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 | |
57dea9f6 | 15 | GNU General Public License for more details. |
6de9cd9a | 16 | |
748086b7 JJ |
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. | |
20 | ||
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/>. */ | |
6de9cd9a | 25 | |
64b1806b TK |
26 | #include "libgfortran.h" |
27 | #include <assert.h>' | |
6de9cd9a DN |
28 | |
29 | include(iparm.m4)dnl | |
30 | include(ifunction.m4)dnl | |
644cb69f FXC |
31 | |
32 | `#if defined (HAVE_'atype_name`) && defined (HAVE_'rtype_name`)' | |
33 | ||
64b1806b TK |
34 | #define HAVE_BACK_ARG 1 |
35 | ||
6de9cd9a | 36 | ARRAY_FUNCTION(0, |
80927a56 JJ |
37 | ` atype_name maxval; |
38 | #if defined ('atype_inf`) | |
39 | maxval = -atype_inf; | |
40 | #else | |
41 | maxval = atype_min; | |
42 | #endif | |
43 | result = 1;', | |
44 | `#if defined ('atype_nan`) | |
b573f931 TK |
45 | for (n = 0; n < len; n++, src += delta) |
46 | { | |
80927a56 JJ |
47 | if (*src >= maxval) |
48 | { | |
49 | maxval = *src; | |
50 | result = (rtype_name)n + 1; | |
51 | break; | |
52 | } | |
53 | } | |
b573f931 TK |
54 | #else |
55 | n = 0; | |
56 | #endif | |
80927a56 JJ |
57 | for (; n < len; n++, src += delta) |
58 | { | |
b573f931 | 59 | if (back ? *src >= maxval : *src > maxval) |
80927a56 JJ |
60 | { |
61 | maxval = *src; | |
62 | result = (rtype_name)n + 1; | |
0cd0559e | 63 | }', `') |
6de9cd9a DN |
64 | |
65 | MASKED_ARRAY_FUNCTION(0, | |
80927a56 JJ |
66 | ` atype_name maxval; |
67 | #if defined ('atype_inf`) | |
68 | maxval = -atype_inf; | |
69 | #else | |
70 | maxval = atype_min; | |
71 | #endif | |
72 | #if defined ('atype_nan`) | |
73 | rtype_name result2 = 0; | |
74 | #endif | |
75 | result = 0;', | |
76 | ` if (*msrc) | |
77 | { | |
78 | #if defined ('atype_nan`) | |
79 | if (!result2) | |
80 | result2 = (rtype_name)n + 1; | |
81 | if (*src >= maxval) | |
82 | #endif | |
83 | { | |
84 | maxval = *src; | |
85 | result = (rtype_name)n + 1; | |
86 | break; | |
87 | } | |
88 | } | |
89 | } | |
90 | #if defined ('atype_nan`) | |
91 | if (unlikely (n >= len)) | |
92 | result = result2; | |
93 | else | |
94 | #endif | |
b573f931 TK |
95 | if (back) |
96 | for (; n < len; n++, src += delta, msrc += mdelta) | |
97 | { | |
98 | if (*msrc && unlikely (*src >= maxval)) | |
99 | { | |
100 | maxval = *src; | |
101 | result = (rtype_name)n + 1; | |
102 | } | |
103 | } | |
104 | else | |
105 | for (; n < len; n++, src += delta, msrc += mdelta) | |
106 | { | |
107 | if (*msrc && unlikely (*src > maxval)) | |
108 | { | |
109 | maxval = *src; | |
110 | result = (rtype_name)n + 1; | |
111 | }') | |
6de9cd9a | 112 | |
97a62038 TK |
113 | SCALAR_ARRAY_FUNCTION(0) |
114 | ||
644cb69f | 115 | #endif |