]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libgfortran/generated/minloc0_8_r8.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 (libgfor).
7 Libgfortran is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 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 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with libgfor; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
27 #include "libgfortran.h"
31 extern void minloc0_8_r8 (gfc_array_i8
* retarray
, gfc_array_r8
*array
);
32 export_proto(minloc0_8_r8
);
35 minloc0_8_r8 (gfc_array_i8
* retarray
, gfc_array_r8
*array
)
37 index_type count
[GFC_MAX_DIMENSIONS
];
38 index_type extent
[GFC_MAX_DIMENSIONS
];
39 index_type sstride
[GFC_MAX_DIMENSIONS
];
46 rank
= GFC_DESCRIPTOR_RANK (array
);
48 assert (GFC_DESCRIPTOR_RANK (retarray
) == 1);
49 assert (retarray
->dim
[0].ubound
+ 1 - retarray
->dim
[0].lbound
== rank
);
50 if (array
->dim
[0].stride
== 0)
51 array
->dim
[0].stride
= 1;
52 if (retarray
->dim
[0].stride
== 0)
53 retarray
->dim
[0].stride
= 1;
55 dstride
= retarray
->dim
[0].stride
;
56 dest
= retarray
->data
;
57 for (n
= 0; n
< rank
; n
++)
59 sstride
[n
] = array
->dim
[n
].stride
;
60 extent
[n
] = array
->dim
[n
].ubound
+ 1 - array
->dim
[n
].lbound
;
64 /* Set the return value. */
65 for (n
= 0; n
< rank
; n
++)
66 dest
[n
* dstride
] = 0;
73 /* Initialize the return value. */
74 for (n
= 0; n
< rank
; n
++)
75 dest
[n
* dstride
] = 1;
80 minval
= GFC_REAL_8_HUGE
;
85 /* Implementation start. */
90 for (n
= 0; n
< rank
; n
++)
91 dest
[n
* dstride
] = count
[n
] + 1;
93 /* Implementation end. */
95 /* Advance to the next element. */
99 while (count
[n
] == extent
[n
])
101 /* When we get to the end of a dimension, reset it and increment
102 the next dimension. */
104 /* We could precalculate these products, but this is a less
105 frequently used path so proabably not worth it. */
106 base
-= sstride
[n
] * extent
[n
];
110 /* Break out of the loop. */
125 extern void mminloc0_8_r8 (gfc_array_i8
*, gfc_array_r8
*, gfc_array_l4
*);
126 export_proto(mminloc0_8_r8
);
129 mminloc0_8_r8 (gfc_array_i8
* retarray
, gfc_array_r8
*array
,
132 index_type count
[GFC_MAX_DIMENSIONS
];
133 index_type extent
[GFC_MAX_DIMENSIONS
];
134 index_type sstride
[GFC_MAX_DIMENSIONS
];
135 index_type mstride
[GFC_MAX_DIMENSIONS
];
139 GFC_LOGICAL_4
*mbase
;
143 rank
= GFC_DESCRIPTOR_RANK (array
);
145 assert (GFC_DESCRIPTOR_RANK (retarray
) == 1);
146 assert (retarray
->dim
[0].ubound
+ 1 - retarray
->dim
[0].lbound
== rank
);
147 assert (GFC_DESCRIPTOR_RANK (mask
) == rank
);
149 if (array
->dim
[0].stride
== 0)
150 array
->dim
[0].stride
= 1;
151 if (retarray
->dim
[0].stride
== 0)
152 retarray
->dim
[0].stride
= 1;
153 if (retarray
->dim
[0].stride
== 0)
154 retarray
->dim
[0].stride
= 1;
156 dstride
= retarray
->dim
[0].stride
;
157 dest
= retarray
->data
;
158 for (n
= 0; n
< rank
; n
++)
160 sstride
[n
] = array
->dim
[n
].stride
;
161 mstride
[n
] = mask
->dim
[n
].stride
;
162 extent
[n
] = array
->dim
[n
].ubound
+ 1 - array
->dim
[n
].lbound
;
166 /* Set the return value. */
167 for (n
= 0; n
< rank
; n
++)
168 dest
[n
* dstride
] = 0;
176 if (GFC_DESCRIPTOR_SIZE (mask
) != 4)
178 /* This allows the same loop to be used for all logical types. */
179 assert (GFC_DESCRIPTOR_SIZE (mask
) == 8);
180 for (n
= 0; n
< rank
; n
++)
182 mbase
= (GFOR_POINTER_L8_TO_L4 (mbase
));
186 /* Initialize the return value. */
187 for (n
= 0; n
< rank
; n
++)
188 dest
[n
* dstride
] = 1;
193 minval
= GFC_REAL_8_HUGE
;
198 /* Implementation start. */
200 if (*mbase
&& *base
< minval
)
203 for (n
= 0; n
< rank
; n
++)
204 dest
[n
* dstride
] = count
[n
] + 1;
206 /* Implementation end. */
208 /* Advance to the next element. */
213 while (count
[n
] == extent
[n
])
215 /* When we get to the end of a dimension, reset it and increment
216 the next dimension. */
218 /* We could precalculate these products, but this is a less
219 frequently used path so proabably not worth it. */
220 base
-= sstride
[n
] * extent
[n
];
221 mbase
-= mstride
[n
] * extent
[n
];
225 /* Break out of the loop. */