]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libgfortran/generated/minloc0_8_r4.c
1 /* Implementation of the MINLOC intrinsic
2 Copyright 2002 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 2 of the License, or (at your option) any later version.
12 In addition to the permissions in the GNU General Public License, the
13 Free Software Foundation gives you unlimited permission to link the
14 compiled version of this file into combinations with other programs,
15 and to distribute those combinations without any restriction coming
16 from the use of this file. (The General Public License restrictions
17 do apply in other respects; for example, they cover modification of
18 the file, and distribution when not linked into a combine
21 Libgfortran is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public
27 License along with libgfortran; see the file COPYING. If not,
28 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
29 Boston, MA 02111-1307, USA. */
36 #include "libgfortran.h"
40 extern void minloc0_8_r4 (gfc_array_i8
* retarray
, gfc_array_r4
*array
);
41 export_proto(minloc0_8_r4
);
44 minloc0_8_r4 (gfc_array_i8
* retarray
, gfc_array_r4
*array
)
46 index_type count
[GFC_MAX_DIMENSIONS
];
47 index_type extent
[GFC_MAX_DIMENSIONS
];
48 index_type sstride
[GFC_MAX_DIMENSIONS
];
55 rank
= GFC_DESCRIPTOR_RANK (array
);
57 assert (GFC_DESCRIPTOR_RANK (retarray
) == 1);
58 assert (retarray
->dim
[0].ubound
+ 1 - retarray
->dim
[0].lbound
== rank
);
59 if (array
->dim
[0].stride
== 0)
60 array
->dim
[0].stride
= 1;
61 if (retarray
->dim
[0].stride
== 0)
62 retarray
->dim
[0].stride
= 1;
64 dstride
= retarray
->dim
[0].stride
;
65 dest
= retarray
->data
;
66 for (n
= 0; n
< rank
; n
++)
68 sstride
[n
] = array
->dim
[n
].stride
;
69 extent
[n
] = array
->dim
[n
].ubound
+ 1 - array
->dim
[n
].lbound
;
73 /* Set the return value. */
74 for (n
= 0; n
< rank
; n
++)
75 dest
[n
* dstride
] = 0;
82 /* Initialize the return value. */
83 for (n
= 0; n
< rank
; n
++)
84 dest
[n
* dstride
] = 1;
89 minval
= GFC_REAL_4_HUGE
;
94 /* Implementation start. */
99 for (n
= 0; n
< rank
; n
++)
100 dest
[n
* dstride
] = count
[n
] + 1;
102 /* Implementation end. */
104 /* Advance to the next element. */
108 while (count
[n
] == extent
[n
])
110 /* When we get to the end of a dimension, reset it and increment
111 the next dimension. */
113 /* We could precalculate these products, but this is a less
114 frequently used path so proabably not worth it. */
115 base
-= sstride
[n
] * extent
[n
];
119 /* Break out of the loop. */
134 extern void mminloc0_8_r4 (gfc_array_i8
*, gfc_array_r4
*, gfc_array_l4
*);
135 export_proto(mminloc0_8_r4
);
138 mminloc0_8_r4 (gfc_array_i8
* retarray
, gfc_array_r4
*array
,
141 index_type count
[GFC_MAX_DIMENSIONS
];
142 index_type extent
[GFC_MAX_DIMENSIONS
];
143 index_type sstride
[GFC_MAX_DIMENSIONS
];
144 index_type mstride
[GFC_MAX_DIMENSIONS
];
148 GFC_LOGICAL_4
*mbase
;
152 rank
= GFC_DESCRIPTOR_RANK (array
);
154 assert (GFC_DESCRIPTOR_RANK (retarray
) == 1);
155 assert (retarray
->dim
[0].ubound
+ 1 - retarray
->dim
[0].lbound
== rank
);
156 assert (GFC_DESCRIPTOR_RANK (mask
) == rank
);
158 if (array
->dim
[0].stride
== 0)
159 array
->dim
[0].stride
= 1;
160 if (retarray
->dim
[0].stride
== 0)
161 retarray
->dim
[0].stride
= 1;
162 if (retarray
->dim
[0].stride
== 0)
163 retarray
->dim
[0].stride
= 1;
165 dstride
= retarray
->dim
[0].stride
;
166 dest
= retarray
->data
;
167 for (n
= 0; n
< rank
; n
++)
169 sstride
[n
] = array
->dim
[n
].stride
;
170 mstride
[n
] = mask
->dim
[n
].stride
;
171 extent
[n
] = array
->dim
[n
].ubound
+ 1 - array
->dim
[n
].lbound
;
175 /* Set the return value. */
176 for (n
= 0; n
< rank
; n
++)
177 dest
[n
* dstride
] = 0;
185 if (GFC_DESCRIPTOR_SIZE (mask
) != 4)
187 /* This allows the same loop to be used for all logical types. */
188 assert (GFC_DESCRIPTOR_SIZE (mask
) == 8);
189 for (n
= 0; n
< rank
; n
++)
191 mbase
= (GFOR_POINTER_L8_TO_L4 (mbase
));
195 /* Initialize the return value. */
196 for (n
= 0; n
< rank
; n
++)
197 dest
[n
* dstride
] = 1;
202 minval
= GFC_REAL_4_HUGE
;
207 /* Implementation start. */
209 if (*mbase
&& *base
< minval
)
212 for (n
= 0; n
< rank
; n
++)
213 dest
[n
* dstride
] = count
[n
] + 1;
215 /* Implementation end. */
217 /* Advance to the next element. */
222 while (count
[n
] == extent
[n
])
224 /* When we get to the end of a dimension, reset it and increment
225 the next dimension. */
227 /* We could precalculate these products, but this is a less
228 frequently used path so proabably not worth it. */
229 base
-= sstride
[n
] * extent
[n
];
230 mbase
-= mstride
[n
] * extent
[n
];
234 /* Break out of the loop. */