]>
Commit | Line | Data |
---|---|---|
4ee9c684 | 1 | /* Implementation of the MINLOC intrinsic |
f1717362 | 2 | Copyright (C) 2002-2016 Free Software Foundation, Inc. |
4ee9c684 | 3 | Contributed by Paul Brook <paul@nowt.org> |
4 | ||
b4ba8232 | 5 | This file is part of the GNU Fortran runtime library (libgfortran). |
4ee9c684 | 6 | |
7 | Libgfortran is free software; you can redistribute it and/or | |
b417ea8c | 8 | modify it under the terms of the GNU General Public |
4ee9c684 | 9 | License as published by the Free Software Foundation; either |
6bc9506f | 10 | version 3 of the License, or (at your option) any later version. |
4ee9c684 | 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 | |
b417ea8c | 15 | GNU General Public License for more details. |
4ee9c684 | 16 | |
6bc9506f | 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/>. */ | |
4ee9c684 | 25 | |
41f2d5e8 | 26 | #include "libgfortran.h" |
4ee9c684 | 27 | #include <stdlib.h> |
28 | #include <assert.h> | |
4ee9c684 | 29 | #include <limits.h> |
4ee9c684 | 30 | |
7b6cb5bd | 31 | |
920e54ef | 32 | #if defined (HAVE_GFC_INTEGER_8) && defined (HAVE_GFC_INTEGER_8) |
33 | ||
34 | ||
b4cafd67 | 35 | extern void minloc1_8_i8 (gfc_array_i8 * const restrict, |
36 | gfc_array_i8 * const restrict, const index_type * const restrict); | |
820b4fbd | 37 | export_proto(minloc1_8_i8); |
7b6cb5bd | 38 | |
4ee9c684 | 39 | void |
b4cafd67 | 40 | minloc1_8_i8 (gfc_array_i8 * const restrict retarray, |
41 | gfc_array_i8 * const restrict array, | |
42 | const index_type * const restrict pdim) | |
4ee9c684 | 43 | { |
9130521e | 44 | index_type count[GFC_MAX_DIMENSIONS]; |
45 | index_type extent[GFC_MAX_DIMENSIONS]; | |
46 | index_type sstride[GFC_MAX_DIMENSIONS]; | |
47 | index_type dstride[GFC_MAX_DIMENSIONS]; | |
b4cafd67 | 48 | const GFC_INTEGER_8 * restrict base; |
49 | GFC_INTEGER_8 * restrict dest; | |
4ee9c684 | 50 | index_type rank; |
51 | index_type n; | |
52 | index_type len; | |
53 | index_type delta; | |
54 | index_type dim; | |
393a1b6c | 55 | int continue_loop; |
4ee9c684 | 56 | |
57 | /* Make dim zero based to avoid confusion. */ | |
58 | dim = (*pdim) - 1; | |
59 | rank = GFC_DESCRIPTOR_RANK (array) - 1; | |
9130521e | 60 | |
827aef63 | 61 | len = GFC_DESCRIPTOR_EXTENT(array,dim); |
393a1b6c | 62 | if (len < 0) |
63 | len = 0; | |
827aef63 | 64 | delta = GFC_DESCRIPTOR_STRIDE(array,dim); |
4ee9c684 | 65 | |
66 | for (n = 0; n < dim; n++) | |
67 | { | |
827aef63 | 68 | sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n); |
69 | extent[n] = GFC_DESCRIPTOR_EXTENT(array,n); | |
a14c06e9 | 70 | |
71 | if (extent[n] < 0) | |
72 | extent[n] = 0; | |
4ee9c684 | 73 | } |
74 | for (n = dim; n < rank; n++) | |
75 | { | |
827aef63 | 76 | sstride[n] = GFC_DESCRIPTOR_STRIDE(array, n + 1); |
77 | extent[n] = GFC_DESCRIPTOR_EXTENT(array, n + 1); | |
a14c06e9 | 78 | |
79 | if (extent[n] < 0) | |
80 | extent[n] = 0; | |
4ee9c684 | 81 | } |
82 | ||
553877d9 | 83 | if (retarray->base_addr == NULL) |
5fcc57ce | 84 | { |
827aef63 | 85 | size_t alloc_size, str; |
a14c06e9 | 86 | |
5fcc57ce | 87 | for (n = 0; n < rank; n++) |
7ebee933 | 88 | { |
89 | if (n == 0) | |
827aef63 | 90 | str = 1; |
7ebee933 | 91 | else |
92 | str = GFC_DESCRIPTOR_STRIDE(retarray,n-1) * extent[n-1]; | |
827aef63 | 93 | |
94 | GFC_DIMENSION_SET(retarray->dim[n], 0, extent[n] - 1, str); | |
95 | ||
7ebee933 | 96 | } |
5fcc57ce | 97 | |
93830de1 | 98 | retarray->offset = 0; |
07ea8faa | 99 | retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; |
a14c06e9 | 100 | |
af1e9051 | 101 | alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1]; |
a14c06e9 | 102 | |
af1e9051 | 103 | retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8)); |
a14c06e9 | 104 | if (alloc_size == 0) |
105 | { | |
106 | /* Make sure we have a zero-sized array. */ | |
827aef63 | 107 | GFC_DIMENSION_SET(retarray->dim[0], 0, -1, 1); |
a14c06e9 | 108 | return; |
827aef63 | 109 | |
a14c06e9 | 110 | } |
5fcc57ce | 111 | } |
07ea8faa | 112 | else |
113 | { | |
07ea8faa | 114 | if (rank != GFC_DESCRIPTOR_RANK (retarray)) |
8dec97a0 | 115 | runtime_error ("rank of return array incorrect in" |
ae66f8f3 | 116 | " MINLOC intrinsic: is %ld, should be %ld", |
117 | (long int) (GFC_DESCRIPTOR_RANK (retarray)), | |
118 | (long int) rank); | |
8dec97a0 | 119 | |
c7fb575f | 120 | if (unlikely (compile_options.bounds_check)) |
5d04d450 | 121 | bounds_ifunction_return ((array_t *) retarray, extent, |
122 | "return value", "MINLOC"); | |
07ea8faa | 123 | } |
124 | ||
4ee9c684 | 125 | for (n = 0; n < rank; n++) |
126 | { | |
127 | count[n] = 0; | |
827aef63 | 128 | dstride[n] = GFC_DESCRIPTOR_STRIDE(retarray,n); |
4ee9c684 | 129 | if (extent[n] <= 0) |
7cbf86e5 | 130 | return; |
4ee9c684 | 131 | } |
132 | ||
553877d9 | 133 | base = array->base_addr; |
134 | dest = retarray->base_addr; | |
4ee9c684 | 135 | |
393a1b6c | 136 | continue_loop = 1; |
137 | while (continue_loop) | |
4ee9c684 | 138 | { |
b4cafd67 | 139 | const GFC_INTEGER_8 * restrict src; |
4ee9c684 | 140 | GFC_INTEGER_8 result; |
141 | src = base; | |
142 | { | |
143 | ||
7ebee933 | 144 | GFC_INTEGER_8 minval; |
145 | #if defined (GFC_INTEGER_8_INFINITY) | |
146 | minval = GFC_INTEGER_8_INFINITY; | |
147 | #else | |
148 | minval = GFC_INTEGER_8_HUGE; | |
149 | #endif | |
150 | result = 1; | |
151 | if (len <= 0) | |
4ee9c684 | 152 | *dest = 0; |
153 | else | |
154 | { | |
155 | for (n = 0; n < len; n++, src += delta) | |
156 | { | |
157 | ||
7ebee933 | 158 | #if defined (GFC_INTEGER_8_QUIET_NAN) |
159 | if (*src <= minval) | |
160 | { | |
161 | minval = *src; | |
162 | result = (GFC_INTEGER_8)n + 1; | |
163 | break; | |
164 | } | |
165 | } | |
166 | for (; n < len; n++, src += delta) | |
167 | { | |
168 | #endif | |
169 | if (*src < minval) | |
170 | { | |
171 | minval = *src; | |
172 | result = (GFC_INTEGER_8)n + 1; | |
173 | } | |
174 | } | |
b4ba8232 | 175 | |
4ee9c684 | 176 | *dest = result; |
177 | } | |
178 | } | |
179 | /* Advance to the next element. */ | |
180 | count[0]++; | |
181 | base += sstride[0]; | |
182 | dest += dstride[0]; | |
183 | n = 0; | |
184 | while (count[n] == extent[n]) | |
7ebee933 | 185 | { |
186 | /* When we get to the end of a dimension, reset it and increment | |
187 | the next dimension. */ | |
188 | count[n] = 0; | |
189 | /* We could precalculate these products, but this is a less | |
190 | frequently used path so probably not worth it. */ | |
191 | base -= sstride[n] * extent[n]; | |
192 | dest -= dstride[n] * extent[n]; | |
193 | n++; | |
194 | if (n == rank) | |
195 | { | |
196 | /* Break out of the look. */ | |
393a1b6c | 197 | continue_loop = 0; |
198 | break; | |
7ebee933 | 199 | } |
200 | else | |
201 | { | |
202 | count[n]++; | |
203 | base += sstride[n]; | |
204 | dest += dstride[n]; | |
205 | } | |
206 | } | |
4ee9c684 | 207 | } |
208 | } | |
209 | ||
7b6cb5bd | 210 | |
b4cafd67 | 211 | extern void mminloc1_8_i8 (gfc_array_i8 * const restrict, |
212 | gfc_array_i8 * const restrict, const index_type * const restrict, | |
7ed8f627 | 213 | gfc_array_l1 * const restrict); |
820b4fbd | 214 | export_proto(mminloc1_8_i8); |
7b6cb5bd | 215 | |
4ee9c684 | 216 | void |
b4cafd67 | 217 | mminloc1_8_i8 (gfc_array_i8 * const restrict retarray, |
218 | gfc_array_i8 * const restrict array, | |
219 | const index_type * const restrict pdim, | |
7ed8f627 | 220 | gfc_array_l1 * const restrict mask) |
4ee9c684 | 221 | { |
9130521e | 222 | index_type count[GFC_MAX_DIMENSIONS]; |
223 | index_type extent[GFC_MAX_DIMENSIONS]; | |
224 | index_type sstride[GFC_MAX_DIMENSIONS]; | |
225 | index_type dstride[GFC_MAX_DIMENSIONS]; | |
226 | index_type mstride[GFC_MAX_DIMENSIONS]; | |
b4cafd67 | 227 | GFC_INTEGER_8 * restrict dest; |
228 | const GFC_INTEGER_8 * restrict base; | |
7ed8f627 | 229 | const GFC_LOGICAL_1 * restrict mbase; |
4ee9c684 | 230 | int rank; |
231 | int dim; | |
232 | index_type n; | |
233 | index_type len; | |
234 | index_type delta; | |
235 | index_type mdelta; | |
7ed8f627 | 236 | int mask_kind; |
4ee9c684 | 237 | |
238 | dim = (*pdim) - 1; | |
239 | rank = GFC_DESCRIPTOR_RANK (array) - 1; | |
9130521e | 240 | |
827aef63 | 241 | len = GFC_DESCRIPTOR_EXTENT(array,dim); |
4ee9c684 | 242 | if (len <= 0) |
243 | return; | |
7ed8f627 | 244 | |
553877d9 | 245 | mbase = mask->base_addr; |
7ed8f627 | 246 | |
247 | mask_kind = GFC_DESCRIPTOR_SIZE (mask); | |
248 | ||
249 | if (mask_kind == 1 || mask_kind == 2 || mask_kind == 4 || mask_kind == 8 | |
250 | #ifdef HAVE_GFC_LOGICAL_16 | |
251 | || mask_kind == 16 | |
252 | #endif | |
253 | ) | |
254 | mbase = GFOR_POINTER_TO_L1 (mbase, mask_kind); | |
255 | else | |
256 | runtime_error ("Funny sized logical array"); | |
257 | ||
827aef63 | 258 | delta = GFC_DESCRIPTOR_STRIDE(array,dim); |
259 | mdelta = GFC_DESCRIPTOR_STRIDE_BYTES(mask,dim); | |
4ee9c684 | 260 | |
261 | for (n = 0; n < dim; n++) | |
262 | { | |
827aef63 | 263 | sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n); |
264 | mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n); | |
265 | extent[n] = GFC_DESCRIPTOR_EXTENT(array,n); | |
a14c06e9 | 266 | |
267 | if (extent[n] < 0) | |
268 | extent[n] = 0; | |
269 | ||
4ee9c684 | 270 | } |
271 | for (n = dim; n < rank; n++) | |
272 | { | |
827aef63 | 273 | sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n + 1); |
274 | mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask, n + 1); | |
275 | extent[n] = GFC_DESCRIPTOR_EXTENT(array, n + 1); | |
a14c06e9 | 276 | |
277 | if (extent[n] < 0) | |
278 | extent[n] = 0; | |
4ee9c684 | 279 | } |
280 | ||
553877d9 | 281 | if (retarray->base_addr == NULL) |
07ea8faa | 282 | { |
827aef63 | 283 | size_t alloc_size, str; |
a14c06e9 | 284 | |
07ea8faa | 285 | for (n = 0; n < rank; n++) |
7ebee933 | 286 | { |
287 | if (n == 0) | |
288 | str = 1; | |
289 | else | |
290 | str= GFC_DESCRIPTOR_STRIDE(retarray,n-1) * extent[n-1]; | |
827aef63 | 291 | |
292 | GFC_DIMENSION_SET(retarray->dim[n], 0, extent[n] - 1, str); | |
293 | ||
7ebee933 | 294 | } |
07ea8faa | 295 | |
af1e9051 | 296 | alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1]; |
a14c06e9 | 297 | |
93830de1 | 298 | retarray->offset = 0; |
07ea8faa | 299 | retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; |
a14c06e9 | 300 | |
301 | if (alloc_size == 0) | |
302 | { | |
303 | /* Make sure we have a zero-sized array. */ | |
827aef63 | 304 | GFC_DIMENSION_SET(retarray->dim[0], 0, -1, 1); |
a14c06e9 | 305 | return; |
306 | } | |
307 | else | |
af1e9051 | 308 | retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8)); |
a14c06e9 | 309 | |
07ea8faa | 310 | } |
311 | else | |
312 | { | |
07ea8faa | 313 | if (rank != GFC_DESCRIPTOR_RANK (retarray)) |
8dec97a0 | 314 | runtime_error ("rank of return array incorrect in MINLOC intrinsic"); |
315 | ||
c7fb575f | 316 | if (unlikely (compile_options.bounds_check)) |
8dec97a0 | 317 | { |
5d04d450 | 318 | bounds_ifunction_return ((array_t *) retarray, extent, |
319 | "return value", "MINLOC"); | |
320 | bounds_equal_extents ((array_t *) mask, (array_t *) array, | |
321 | "MASK argument", "MINLOC"); | |
8dec97a0 | 322 | } |
07ea8faa | 323 | } |
324 | ||
4ee9c684 | 325 | for (n = 0; n < rank; n++) |
326 | { | |
327 | count[n] = 0; | |
827aef63 | 328 | dstride[n] = GFC_DESCRIPTOR_STRIDE(retarray,n); |
4ee9c684 | 329 | if (extent[n] <= 0) |
7ebee933 | 330 | return; |
4ee9c684 | 331 | } |
332 | ||
553877d9 | 333 | dest = retarray->base_addr; |
334 | base = array->base_addr; | |
4ee9c684 | 335 | |
336 | while (base) | |
337 | { | |
b4cafd67 | 338 | const GFC_INTEGER_8 * restrict src; |
7ed8f627 | 339 | const GFC_LOGICAL_1 * restrict msrc; |
4ee9c684 | 340 | GFC_INTEGER_8 result; |
341 | src = base; | |
342 | msrc = mbase; | |
343 | { | |
344 | ||
7ebee933 | 345 | GFC_INTEGER_8 minval; |
346 | #if defined (GFC_INTEGER_8_INFINITY) | |
347 | minval = GFC_INTEGER_8_INFINITY; | |
348 | #else | |
349 | minval = GFC_INTEGER_8_HUGE; | |
350 | #endif | |
351 | #if defined (GFC_INTEGER_8_QUIET_NAN) | |
352 | GFC_INTEGER_8 result2 = 0; | |
353 | #endif | |
354 | result = 0; | |
08e1eb56 | 355 | for (n = 0; n < len; n++, src += delta, msrc += mdelta) |
4ee9c684 | 356 | { |
4ee9c684 | 357 | |
7ebee933 | 358 | if (*msrc) |
359 | { | |
360 | #if defined (GFC_INTEGER_8_QUIET_NAN) | |
361 | if (!result2) | |
362 | result2 = (GFC_INTEGER_8)n + 1; | |
363 | if (*src <= minval) | |
364 | #endif | |
365 | { | |
366 | minval = *src; | |
367 | result = (GFC_INTEGER_8)n + 1; | |
368 | break; | |
369 | } | |
370 | } | |
371 | } | |
372 | #if defined (GFC_INTEGER_8_QUIET_NAN) | |
373 | if (unlikely (n >= len)) | |
374 | result = result2; | |
375 | else | |
376 | #endif | |
377 | for (; n < len; n++, src += delta, msrc += mdelta) | |
378 | { | |
379 | if (*msrc && *src < minval) | |
380 | { | |
381 | minval = *src; | |
382 | result = (GFC_INTEGER_8)n + 1; | |
383 | } | |
4ee9c684 | 384 | } |
08e1eb56 | 385 | *dest = result; |
4ee9c684 | 386 | } |
387 | /* Advance to the next element. */ | |
388 | count[0]++; | |
389 | base += sstride[0]; | |
390 | mbase += mstride[0]; | |
391 | dest += dstride[0]; | |
392 | n = 0; | |
393 | while (count[n] == extent[n]) | |
7ebee933 | 394 | { |
395 | /* When we get to the end of a dimension, reset it and increment | |
396 | the next dimension. */ | |
397 | count[n] = 0; | |
398 | /* We could precalculate these products, but this is a less | |
399 | frequently used path so probably not worth it. */ | |
400 | base -= sstride[n] * extent[n]; | |
401 | mbase -= mstride[n] * extent[n]; | |
402 | dest -= dstride[n] * extent[n]; | |
403 | n++; | |
404 | if (n == rank) | |
405 | { | |
406 | /* Break out of the look. */ | |
407 | base = NULL; | |
408 | break; | |
409 | } | |
410 | else | |
411 | { | |
412 | count[n]++; | |
413 | base += sstride[n]; | |
414 | mbase += mstride[n]; | |
415 | dest += dstride[n]; | |
416 | } | |
417 | } | |
4ee9c684 | 418 | } |
419 | } | |
420 | ||
4292b27d | 421 | |
422 | extern void sminloc1_8_i8 (gfc_array_i8 * const restrict, | |
423 | gfc_array_i8 * const restrict, const index_type * const restrict, | |
424 | GFC_LOGICAL_4 *); | |
425 | export_proto(sminloc1_8_i8); | |
426 | ||
427 | void | |
428 | sminloc1_8_i8 (gfc_array_i8 * const restrict retarray, | |
429 | gfc_array_i8 * const restrict array, | |
430 | const index_type * const restrict pdim, | |
431 | GFC_LOGICAL_4 * mask) | |
432 | { | |
f955bfc4 | 433 | index_type count[GFC_MAX_DIMENSIONS]; |
434 | index_type extent[GFC_MAX_DIMENSIONS]; | |
f955bfc4 | 435 | index_type dstride[GFC_MAX_DIMENSIONS]; |
436 | GFC_INTEGER_8 * restrict dest; | |
4292b27d | 437 | index_type rank; |
438 | index_type n; | |
f955bfc4 | 439 | index_type dim; |
440 | ||
4292b27d | 441 | |
442 | if (*mask) | |
443 | { | |
444 | minloc1_8_i8 (retarray, array, pdim); | |
445 | return; | |
446 | } | |
f955bfc4 | 447 | /* Make dim zero based to avoid confusion. */ |
448 | dim = (*pdim) - 1; | |
449 | rank = GFC_DESCRIPTOR_RANK (array) - 1; | |
450 | ||
451 | for (n = 0; n < dim; n++) | |
452 | { | |
827aef63 | 453 | extent[n] = GFC_DESCRIPTOR_EXTENT(array,n); |
f955bfc4 | 454 | |
455 | if (extent[n] <= 0) | |
456 | extent[n] = 0; | |
457 | } | |
458 | ||
459 | for (n = dim; n < rank; n++) | |
460 | { | |
f955bfc4 | 461 | extent[n] = |
7ebee933 | 462 | GFC_DESCRIPTOR_EXTENT(array,n + 1); |
f955bfc4 | 463 | |
464 | if (extent[n] <= 0) | |
7ebee933 | 465 | extent[n] = 0; |
f955bfc4 | 466 | } |
4292b27d | 467 | |
553877d9 | 468 | if (retarray->base_addr == NULL) |
4292b27d | 469 | { |
827aef63 | 470 | size_t alloc_size, str; |
f955bfc4 | 471 | |
472 | for (n = 0; n < rank; n++) | |
7ebee933 | 473 | { |
474 | if (n == 0) | |
475 | str = 1; | |
476 | else | |
477 | str = GFC_DESCRIPTOR_STRIDE(retarray,n-1) * extent[n-1]; | |
827aef63 | 478 | |
479 | GFC_DIMENSION_SET(retarray->dim[n], 0, extent[n] - 1, str); | |
480 | ||
7ebee933 | 481 | } |
f955bfc4 | 482 | |
4292b27d | 483 | retarray->offset = 0; |
f955bfc4 | 484 | retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank; |
485 | ||
af1e9051 | 486 | alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1]; |
f955bfc4 | 487 | |
488 | if (alloc_size == 0) | |
489 | { | |
490 | /* Make sure we have a zero-sized array. */ | |
827aef63 | 491 | GFC_DIMENSION_SET(retarray->dim[0], 0, -1, 1); |
f955bfc4 | 492 | return; |
493 | } | |
494 | else | |
af1e9051 | 495 | retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8)); |
4292b27d | 496 | } |
497 | else | |
498 | { | |
f955bfc4 | 499 | if (rank != GFC_DESCRIPTOR_RANK (retarray)) |
500 | runtime_error ("rank of return array incorrect in" | |
501 | " MINLOC intrinsic: is %ld, should be %ld", | |
502 | (long int) (GFC_DESCRIPTOR_RANK (retarray)), | |
503 | (long int) rank); | |
504 | ||
c7fb575f | 505 | if (unlikely (compile_options.bounds_check)) |
8dec97a0 | 506 | { |
f955bfc4 | 507 | for (n=0; n < rank; n++) |
508 | { | |
509 | index_type ret_extent; | |
4292b27d | 510 | |
827aef63 | 511 | ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,n); |
f955bfc4 | 512 | if (extent[n] != ret_extent) |
513 | runtime_error ("Incorrect extent in return value of" | |
514 | " MINLOC intrinsic in dimension %ld:" | |
515 | " is %ld, should be %ld", (long int) n + 1, | |
516 | (long int) ret_extent, (long int) extent[n]); | |
517 | } | |
8dec97a0 | 518 | } |
519 | } | |
4292b27d | 520 | |
f955bfc4 | 521 | for (n = 0; n < rank; n++) |
522 | { | |
523 | count[n] = 0; | |
827aef63 | 524 | dstride[n] = GFC_DESCRIPTOR_STRIDE(retarray,n); |
f955bfc4 | 525 | } |
526 | ||
553877d9 | 527 | dest = retarray->base_addr; |
f955bfc4 | 528 | |
529 | while(1) | |
530 | { | |
531 | *dest = 0; | |
532 | count[0]++; | |
533 | dest += dstride[0]; | |
534 | n = 0; | |
535 | while (count[n] == extent[n]) | |
7ebee933 | 536 | { |
f955bfc4 | 537 | /* When we get to the end of a dimension, reset it and increment |
7ebee933 | 538 | the next dimension. */ |
539 | count[n] = 0; | |
540 | /* We could precalculate these products, but this is a less | |
541 | frequently used path so probably not worth it. */ | |
542 | dest -= dstride[n] * extent[n]; | |
543 | n++; | |
544 | if (n == rank) | |
f955bfc4 | 545 | return; |
7ebee933 | 546 | else |
547 | { | |
548 | count[n]++; | |
549 | dest += dstride[n]; | |
550 | } | |
f955bfc4 | 551 | } |
552 | } | |
4292b27d | 553 | } |
554 | ||
920e54ef | 555 | #endif |