]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libgfortran/generated/minval_r10.c
1 /* Implementation of the MINVAL intrinsic
2 Copyright (C) 2002-2016 Free Software Foundation, Inc.
3 Contributed by Paul Brook <paul@nowt.org>
5 This file is part of the GNU Fortran 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"
30 #if defined (HAVE_GFC_REAL_10) && defined (HAVE_GFC_REAL_10)
33 extern void minval_r10 (gfc_array_r10
* const restrict
,
34 gfc_array_r10
* const restrict
, const index_type
* const restrict
);
35 export_proto(minval_r10
);
38 minval_r10 (gfc_array_r10
* const restrict retarray
,
39 gfc_array_r10
* const restrict array
,
40 const index_type
* const restrict pdim
)
42 index_type count
[GFC_MAX_DIMENSIONS
];
43 index_type extent
[GFC_MAX_DIMENSIONS
];
44 index_type sstride
[GFC_MAX_DIMENSIONS
];
45 index_type dstride
[GFC_MAX_DIMENSIONS
];
46 const GFC_REAL_10
* restrict base
;
47 GFC_REAL_10
* restrict dest
;
55 /* Make dim zero based to avoid confusion. */
57 rank
= GFC_DESCRIPTOR_RANK (array
) - 1;
59 len
= GFC_DESCRIPTOR_EXTENT(array
,dim
);
62 delta
= GFC_DESCRIPTOR_STRIDE(array
,dim
);
64 for (n
= 0; n
< dim
; n
++)
66 sstride
[n
] = GFC_DESCRIPTOR_STRIDE(array
,n
);
67 extent
[n
] = GFC_DESCRIPTOR_EXTENT(array
,n
);
72 for (n
= dim
; n
< rank
; n
++)
74 sstride
[n
] = GFC_DESCRIPTOR_STRIDE(array
, n
+ 1);
75 extent
[n
] = GFC_DESCRIPTOR_EXTENT(array
, n
+ 1);
81 if (retarray
->base_addr
== NULL
)
83 size_t alloc_size
, str
;
85 for (n
= 0; n
< rank
; n
++)
90 str
= GFC_DESCRIPTOR_STRIDE(retarray
,n
-1) * extent
[n
-1];
92 GFC_DIMENSION_SET(retarray
->dim
[n
], 0, extent
[n
] - 1, str
);
97 retarray
->dtype
= (array
->dtype
& ~GFC_DTYPE_RANK_MASK
) | rank
;
99 alloc_size
= GFC_DESCRIPTOR_STRIDE(retarray
,rank
-1) * extent
[rank
-1];
101 retarray
->base_addr
= xmallocarray (alloc_size
, sizeof (GFC_REAL_10
));
104 /* Make sure we have a zero-sized array. */
105 GFC_DIMENSION_SET(retarray
->dim
[0], 0, -1, 1);
112 if (rank
!= GFC_DESCRIPTOR_RANK (retarray
))
113 runtime_error ("rank of return array incorrect in"
114 " MINVAL intrinsic: is %ld, should be %ld",
115 (long int) (GFC_DESCRIPTOR_RANK (retarray
)),
118 if (unlikely (compile_options
.bounds_check
))
119 bounds_ifunction_return ((array_t
*) retarray
, extent
,
120 "return value", "MINVAL");
123 for (n
= 0; n
< rank
; n
++)
126 dstride
[n
] = GFC_DESCRIPTOR_STRIDE(retarray
,n
);
131 base
= array
->base_addr
;
132 dest
= retarray
->base_addr
;
135 while (continue_loop
)
137 const GFC_REAL_10
* restrict src
;
142 #if defined (GFC_REAL_10_INFINITY)
143 result
= GFC_REAL_10_INFINITY
;
145 result
= GFC_REAL_10_HUGE
;
148 *dest
= GFC_REAL_10_HUGE
;
151 for (n
= 0; n
< len
; n
++, src
+= delta
)
154 #if defined (GFC_REAL_10_QUIET_NAN)
158 if (unlikely (n
>= len
))
159 result
= GFC_REAL_10_QUIET_NAN
;
160 else for (; n
< len
; n
++, src
+= delta
)
170 /* Advance to the next element. */
175 while (count
[n
] == extent
[n
])
177 /* When we get to the end of a dimension, reset it and increment
178 the next dimension. */
180 /* We could precalculate these products, but this is a less
181 frequently used path so probably not worth it. */
182 base
-= sstride
[n
] * extent
[n
];
183 dest
-= dstride
[n
] * extent
[n
];
187 /* Break out of the look. */
202 extern void mminval_r10 (gfc_array_r10
* const restrict
,
203 gfc_array_r10
* const restrict
, const index_type
* const restrict
,
204 gfc_array_l1
* const restrict
);
205 export_proto(mminval_r10
);
208 mminval_r10 (gfc_array_r10
* const restrict retarray
,
209 gfc_array_r10
* const restrict array
,
210 const index_type
* const restrict pdim
,
211 gfc_array_l1
* const restrict mask
)
213 index_type count
[GFC_MAX_DIMENSIONS
];
214 index_type extent
[GFC_MAX_DIMENSIONS
];
215 index_type sstride
[GFC_MAX_DIMENSIONS
];
216 index_type dstride
[GFC_MAX_DIMENSIONS
];
217 index_type mstride
[GFC_MAX_DIMENSIONS
];
218 GFC_REAL_10
* restrict dest
;
219 const GFC_REAL_10
* restrict base
;
220 const GFC_LOGICAL_1
* restrict mbase
;
230 rank
= GFC_DESCRIPTOR_RANK (array
) - 1;
232 len
= GFC_DESCRIPTOR_EXTENT(array
,dim
);
236 mbase
= mask
->base_addr
;
238 mask_kind
= GFC_DESCRIPTOR_SIZE (mask
);
240 if (mask_kind
== 1 || mask_kind
== 2 || mask_kind
== 4 || mask_kind
== 8
241 #ifdef HAVE_GFC_LOGICAL_16
245 mbase
= GFOR_POINTER_TO_L1 (mbase
, mask_kind
);
247 runtime_error ("Funny sized logical array");
249 delta
= GFC_DESCRIPTOR_STRIDE(array
,dim
);
250 mdelta
= GFC_DESCRIPTOR_STRIDE_BYTES(mask
,dim
);
252 for (n
= 0; n
< dim
; n
++)
254 sstride
[n
] = GFC_DESCRIPTOR_STRIDE(array
,n
);
255 mstride
[n
] = GFC_DESCRIPTOR_STRIDE_BYTES(mask
,n
);
256 extent
[n
] = GFC_DESCRIPTOR_EXTENT(array
,n
);
262 for (n
= dim
; n
< rank
; n
++)
264 sstride
[n
] = GFC_DESCRIPTOR_STRIDE(array
,n
+ 1);
265 mstride
[n
] = GFC_DESCRIPTOR_STRIDE_BYTES(mask
, n
+ 1);
266 extent
[n
] = GFC_DESCRIPTOR_EXTENT(array
, n
+ 1);
272 if (retarray
->base_addr
== NULL
)
274 size_t alloc_size
, str
;
276 for (n
= 0; n
< rank
; n
++)
281 str
= GFC_DESCRIPTOR_STRIDE(retarray
,n
-1) * extent
[n
-1];
283 GFC_DIMENSION_SET(retarray
->dim
[n
], 0, extent
[n
] - 1, str
);
287 alloc_size
= GFC_DESCRIPTOR_STRIDE(retarray
,rank
-1) * extent
[rank
-1];
289 retarray
->offset
= 0;
290 retarray
->dtype
= (array
->dtype
& ~GFC_DTYPE_RANK_MASK
) | rank
;
294 /* Make sure we have a zero-sized array. */
295 GFC_DIMENSION_SET(retarray
->dim
[0], 0, -1, 1);
299 retarray
->base_addr
= xmallocarray (alloc_size
, sizeof (GFC_REAL_10
));
304 if (rank
!= GFC_DESCRIPTOR_RANK (retarray
))
305 runtime_error ("rank of return array incorrect in MINVAL intrinsic");
307 if (unlikely (compile_options
.bounds_check
))
309 bounds_ifunction_return ((array_t
*) retarray
, extent
,
310 "return value", "MINVAL");
311 bounds_equal_extents ((array_t
*) mask
, (array_t
*) array
,
312 "MASK argument", "MINVAL");
316 for (n
= 0; n
< rank
; n
++)
319 dstride
[n
] = GFC_DESCRIPTOR_STRIDE(retarray
,n
);
324 dest
= retarray
->base_addr
;
325 base
= array
->base_addr
;
329 const GFC_REAL_10
* restrict src
;
330 const GFC_LOGICAL_1
* restrict msrc
;
336 #if defined (GFC_REAL_10_INFINITY)
337 result
= GFC_REAL_10_INFINITY
;
339 result
= GFC_REAL_10_HUGE
;
341 #if defined (GFC_REAL_10_QUIET_NAN)
344 for (n
= 0; n
< len
; n
++, src
+= delta
, msrc
+= mdelta
)
347 #if defined (GFC_REAL_10_INFINITY) || defined (GFC_REAL_10_QUIET_NAN)
350 #if defined (GFC_REAL_10_QUIET_NAN)
357 if (unlikely (n
>= len
))
359 #if defined (GFC_REAL_10_QUIET_NAN)
360 result
= non_empty_p
? GFC_REAL_10_QUIET_NAN
: GFC_REAL_10_HUGE
;
362 result
= GFC_REAL_10_HUGE
;
365 else for (; n
< len
; n
++, src
+= delta
, msrc
+= mdelta
)
368 if (*msrc
&& *src
< result
)
373 /* Advance to the next element. */
379 while (count
[n
] == extent
[n
])
381 /* When we get to the end of a dimension, reset it and increment
382 the next dimension. */
384 /* We could precalculate these products, but this is a less
385 frequently used path so probably not worth it. */
386 base
-= sstride
[n
] * extent
[n
];
387 mbase
-= mstride
[n
] * extent
[n
];
388 dest
-= dstride
[n
] * extent
[n
];
392 /* Break out of the look. */
408 extern void sminval_r10 (gfc_array_r10
* const restrict
,
409 gfc_array_r10
* const restrict
, const index_type
* const restrict
,
411 export_proto(sminval_r10
);
414 sminval_r10 (gfc_array_r10
* const restrict retarray
,
415 gfc_array_r10
* const restrict array
,
416 const index_type
* const restrict pdim
,
417 GFC_LOGICAL_4
* mask
)
419 index_type count
[GFC_MAX_DIMENSIONS
];
420 index_type extent
[GFC_MAX_DIMENSIONS
];
421 index_type dstride
[GFC_MAX_DIMENSIONS
];
422 GFC_REAL_10
* restrict dest
;
430 minval_r10 (retarray
, array
, pdim
);
433 /* Make dim zero based to avoid confusion. */
435 rank
= GFC_DESCRIPTOR_RANK (array
) - 1;
437 for (n
= 0; n
< dim
; n
++)
439 extent
[n
] = GFC_DESCRIPTOR_EXTENT(array
,n
);
445 for (n
= dim
; n
< rank
; n
++)
448 GFC_DESCRIPTOR_EXTENT(array
,n
+ 1);
454 if (retarray
->base_addr
== NULL
)
456 size_t alloc_size
, str
;
458 for (n
= 0; n
< rank
; n
++)
463 str
= GFC_DESCRIPTOR_STRIDE(retarray
,n
-1) * extent
[n
-1];
465 GFC_DIMENSION_SET(retarray
->dim
[n
], 0, extent
[n
] - 1, str
);
469 retarray
->offset
= 0;
470 retarray
->dtype
= (array
->dtype
& ~GFC_DTYPE_RANK_MASK
) | rank
;
472 alloc_size
= GFC_DESCRIPTOR_STRIDE(retarray
,rank
-1) * extent
[rank
-1];
476 /* Make sure we have a zero-sized array. */
477 GFC_DIMENSION_SET(retarray
->dim
[0], 0, -1, 1);
481 retarray
->base_addr
= xmallocarray (alloc_size
, sizeof (GFC_REAL_10
));
485 if (rank
!= GFC_DESCRIPTOR_RANK (retarray
))
486 runtime_error ("rank of return array incorrect in"
487 " MINVAL intrinsic: is %ld, should be %ld",
488 (long int) (GFC_DESCRIPTOR_RANK (retarray
)),
491 if (unlikely (compile_options
.bounds_check
))
493 for (n
=0; n
< rank
; n
++)
495 index_type ret_extent
;
497 ret_extent
= GFC_DESCRIPTOR_EXTENT(retarray
,n
);
498 if (extent
[n
] != ret_extent
)
499 runtime_error ("Incorrect extent in return value of"
500 " MINVAL intrinsic in dimension %ld:"
501 " is %ld, should be %ld", (long int) n
+ 1,
502 (long int) ret_extent
, (long int) extent
[n
]);
507 for (n
= 0; n
< rank
; n
++)
510 dstride
[n
] = GFC_DESCRIPTOR_STRIDE(retarray
,n
);
513 dest
= retarray
->base_addr
;
517 *dest
= GFC_REAL_10_HUGE
;
521 while (count
[n
] == extent
[n
])
523 /* When we get to the end of a dimension, reset it and increment
524 the next dimension. */
526 /* We could precalculate these products, but this is a less
527 frequently used path so probably not worth it. */
528 dest
-= dstride
[n
] * extent
[n
];