]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libgfortran/generated/maxval_r8.c
1 /* Implementation of the MAXVAL intrinsic
2 Copyright 2002, 2007, 2009 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 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"
31 #if defined (HAVE_GFC_REAL_8) && defined (HAVE_GFC_REAL_8)
34 extern void maxval_r8 (gfc_array_r8
* const restrict
,
35 gfc_array_r8
* const restrict
, const index_type
* const restrict
);
36 export_proto(maxval_r8
);
39 maxval_r8 (gfc_array_r8
* const restrict retarray
,
40 gfc_array_r8
* const restrict array
,
41 const index_type
* const restrict pdim
)
43 index_type count
[GFC_MAX_DIMENSIONS
];
44 index_type extent
[GFC_MAX_DIMENSIONS
];
45 index_type sstride
[GFC_MAX_DIMENSIONS
];
46 index_type dstride
[GFC_MAX_DIMENSIONS
];
47 const GFC_REAL_8
* restrict base
;
48 GFC_REAL_8
* restrict dest
;
56 /* Make dim zero based to avoid confusion. */
58 rank
= GFC_DESCRIPTOR_RANK (array
) - 1;
60 len
= GFC_DESCRIPTOR_EXTENT(array
,dim
);
63 delta
= GFC_DESCRIPTOR_STRIDE(array
,dim
);
65 for (n
= 0; n
< dim
; n
++)
67 sstride
[n
] = GFC_DESCRIPTOR_STRIDE(array
,n
);
68 extent
[n
] = GFC_DESCRIPTOR_EXTENT(array
,n
);
73 for (n
= dim
; n
< rank
; n
++)
75 sstride
[n
] = GFC_DESCRIPTOR_STRIDE(array
, n
+ 1);
76 extent
[n
] = GFC_DESCRIPTOR_EXTENT(array
, n
+ 1);
82 if (retarray
->data
== NULL
)
84 size_t alloc_size
, str
;
86 for (n
= 0; n
< rank
; n
++)
91 str
= GFC_DESCRIPTOR_STRIDE(retarray
,n
-1) * extent
[n
-1];
93 GFC_DIMENSION_SET(retarray
->dim
[n
], 0, extent
[n
] - 1, str
);
98 retarray
->dtype
= (array
->dtype
& ~GFC_DTYPE_RANK_MASK
) | rank
;
100 alloc_size
= sizeof (GFC_REAL_8
) * GFC_DESCRIPTOR_STRIDE(retarray
,rank
-1)
105 /* Make sure we have a zero-sized array. */
106 GFC_DIMENSION_SET(retarray
->dim
[0], 0, -1, 1);
111 retarray
->data
= internal_malloc_size (alloc_size
);
115 if (rank
!= GFC_DESCRIPTOR_RANK (retarray
))
116 runtime_error ("rank of return array incorrect in"
117 " MAXVAL intrinsic: is %ld, should be %ld",
118 (long int) (GFC_DESCRIPTOR_RANK (retarray
)),
121 if (unlikely (compile_options
.bounds_check
))
122 bounds_ifunction_return ((array_t
*) retarray
, extent
,
123 "return value", "MAXVAL");
126 for (n
= 0; n
< rank
; n
++)
129 dstride
[n
] = GFC_DESCRIPTOR_STRIDE(retarray
,n
);
135 dest
= retarray
->data
;
138 while (continue_loop
)
140 const GFC_REAL_8
* restrict src
;
145 result
= -GFC_REAL_8_HUGE
;
147 *dest
= -GFC_REAL_8_HUGE
;
150 for (n
= 0; n
< len
; n
++, src
+= delta
)
159 /* Advance to the next element. */
164 while (count
[n
] == extent
[n
])
166 /* When we get to the end of a dimension, reset it and increment
167 the next dimension. */
169 /* We could precalculate these products, but this is a less
170 frequently used path so probably not worth it. */
171 base
-= sstride
[n
] * extent
[n
];
172 dest
-= dstride
[n
] * extent
[n
];
176 /* Break out of the look. */
191 extern void mmaxval_r8 (gfc_array_r8
* const restrict
,
192 gfc_array_r8
* const restrict
, const index_type
* const restrict
,
193 gfc_array_l1
* const restrict
);
194 export_proto(mmaxval_r8
);
197 mmaxval_r8 (gfc_array_r8
* const restrict retarray
,
198 gfc_array_r8
* const restrict array
,
199 const index_type
* const restrict pdim
,
200 gfc_array_l1
* const restrict mask
)
202 index_type count
[GFC_MAX_DIMENSIONS
];
203 index_type extent
[GFC_MAX_DIMENSIONS
];
204 index_type sstride
[GFC_MAX_DIMENSIONS
];
205 index_type dstride
[GFC_MAX_DIMENSIONS
];
206 index_type mstride
[GFC_MAX_DIMENSIONS
];
207 GFC_REAL_8
* restrict dest
;
208 const GFC_REAL_8
* restrict base
;
209 const GFC_LOGICAL_1
* restrict mbase
;
219 rank
= GFC_DESCRIPTOR_RANK (array
) - 1;
221 len
= GFC_DESCRIPTOR_EXTENT(array
,dim
);
227 mask_kind
= GFC_DESCRIPTOR_SIZE (mask
);
229 if (mask_kind
== 1 || mask_kind
== 2 || mask_kind
== 4 || mask_kind
== 8
230 #ifdef HAVE_GFC_LOGICAL_16
234 mbase
= GFOR_POINTER_TO_L1 (mbase
, mask_kind
);
236 runtime_error ("Funny sized logical array");
238 delta
= GFC_DESCRIPTOR_STRIDE(array
,dim
);
239 mdelta
= GFC_DESCRIPTOR_STRIDE_BYTES(mask
,dim
);
241 for (n
= 0; n
< dim
; n
++)
243 sstride
[n
] = GFC_DESCRIPTOR_STRIDE(array
,n
);
244 mstride
[n
] = GFC_DESCRIPTOR_STRIDE_BYTES(mask
,n
);
245 extent
[n
] = GFC_DESCRIPTOR_EXTENT(array
,n
);
251 for (n
= dim
; n
< rank
; n
++)
253 sstride
[n
] = GFC_DESCRIPTOR_STRIDE(array
,n
+ 1);
254 mstride
[n
] = GFC_DESCRIPTOR_STRIDE_BYTES(mask
, n
+ 1);
255 extent
[n
] = GFC_DESCRIPTOR_EXTENT(array
, n
+ 1);
261 if (retarray
->data
== NULL
)
263 size_t alloc_size
, str
;
265 for (n
= 0; n
< rank
; n
++)
270 str
= GFC_DESCRIPTOR_STRIDE(retarray
,n
-1) * extent
[n
-1];
272 GFC_DIMENSION_SET(retarray
->dim
[n
], 0, extent
[n
] - 1, str
);
276 alloc_size
= sizeof (GFC_REAL_8
) * GFC_DESCRIPTOR_STRIDE(retarray
,rank
-1)
279 retarray
->offset
= 0;
280 retarray
->dtype
= (array
->dtype
& ~GFC_DTYPE_RANK_MASK
) | rank
;
284 /* Make sure we have a zero-sized array. */
285 GFC_DIMENSION_SET(retarray
->dim
[0], 0, -1, 1);
289 retarray
->data
= internal_malloc_size (alloc_size
);
294 if (rank
!= GFC_DESCRIPTOR_RANK (retarray
))
295 runtime_error ("rank of return array incorrect in MAXVAL intrinsic");
297 if (unlikely (compile_options
.bounds_check
))
299 bounds_ifunction_return ((array_t
*) retarray
, extent
,
300 "return value", "MAXVAL");
301 bounds_equal_extents ((array_t
*) mask
, (array_t
*) array
,
302 "MASK argument", "MAXVAL");
306 for (n
= 0; n
< rank
; n
++)
309 dstride
[n
] = GFC_DESCRIPTOR_STRIDE(retarray
,n
);
314 dest
= retarray
->data
;
319 const GFC_REAL_8
* restrict src
;
320 const GFC_LOGICAL_1
* restrict msrc
;
326 result
= -GFC_REAL_8_HUGE
;
328 *dest
= -GFC_REAL_8_HUGE
;
331 for (n
= 0; n
< len
; n
++, src
+= delta
, msrc
+= mdelta
)
334 if (*msrc
&& *src
> result
)
340 /* Advance to the next element. */
346 while (count
[n
] == extent
[n
])
348 /* When we get to the end of a dimension, reset it and increment
349 the next dimension. */
351 /* We could precalculate these products, but this is a less
352 frequently used path so probably not worth it. */
353 base
-= sstride
[n
] * extent
[n
];
354 mbase
-= mstride
[n
] * extent
[n
];
355 dest
-= dstride
[n
] * extent
[n
];
359 /* Break out of the look. */
375 extern void smaxval_r8 (gfc_array_r8
* const restrict
,
376 gfc_array_r8
* const restrict
, const index_type
* const restrict
,
378 export_proto(smaxval_r8
);
381 smaxval_r8 (gfc_array_r8
* const restrict retarray
,
382 gfc_array_r8
* const restrict array
,
383 const index_type
* const restrict pdim
,
384 GFC_LOGICAL_4
* mask
)
386 index_type count
[GFC_MAX_DIMENSIONS
];
387 index_type extent
[GFC_MAX_DIMENSIONS
];
388 index_type sstride
[GFC_MAX_DIMENSIONS
];
389 index_type dstride
[GFC_MAX_DIMENSIONS
];
390 GFC_REAL_8
* restrict dest
;
398 maxval_r8 (retarray
, array
, pdim
);
401 /* Make dim zero based to avoid confusion. */
403 rank
= GFC_DESCRIPTOR_RANK (array
) - 1;
405 for (n
= 0; n
< dim
; n
++)
407 sstride
[n
] = GFC_DESCRIPTOR_STRIDE(array
,n
);
408 extent
[n
] = GFC_DESCRIPTOR_EXTENT(array
,n
);
414 for (n
= dim
; n
< rank
; n
++)
416 sstride
[n
] = GFC_DESCRIPTOR_STRIDE(array
,n
+ 1);
418 GFC_DESCRIPTOR_EXTENT(array
,n
+ 1);
424 if (retarray
->data
== NULL
)
426 size_t alloc_size
, str
;
428 for (n
= 0; n
< rank
; n
++)
433 str
= GFC_DESCRIPTOR_STRIDE(retarray
,n
-1) * extent
[n
-1];
435 GFC_DIMENSION_SET(retarray
->dim
[n
], 0, extent
[n
] - 1, str
);
439 retarray
->offset
= 0;
440 retarray
->dtype
= (array
->dtype
& ~GFC_DTYPE_RANK_MASK
) | rank
;
442 alloc_size
= sizeof (GFC_REAL_8
) * GFC_DESCRIPTOR_STRIDE(retarray
,rank
-1)
447 /* Make sure we have a zero-sized array. */
448 GFC_DIMENSION_SET(retarray
->dim
[0], 0, -1, 1);
452 retarray
->data
= internal_malloc_size (alloc_size
);
456 if (rank
!= GFC_DESCRIPTOR_RANK (retarray
))
457 runtime_error ("rank of return array incorrect in"
458 " MAXVAL intrinsic: is %ld, should be %ld",
459 (long int) (GFC_DESCRIPTOR_RANK (retarray
)),
462 if (unlikely (compile_options
.bounds_check
))
464 for (n
=0; n
< rank
; n
++)
466 index_type ret_extent
;
468 ret_extent
= GFC_DESCRIPTOR_EXTENT(retarray
,n
);
469 if (extent
[n
] != ret_extent
)
470 runtime_error ("Incorrect extent in return value of"
471 " MAXVAL intrinsic in dimension %ld:"
472 " is %ld, should be %ld", (long int) n
+ 1,
473 (long int) ret_extent
, (long int) extent
[n
]);
478 for (n
= 0; n
< rank
; n
++)
481 dstride
[n
] = GFC_DESCRIPTOR_STRIDE(retarray
,n
);
484 dest
= retarray
->data
;
488 *dest
= -GFC_REAL_8_HUGE
;
492 while (count
[n
] == extent
[n
])
494 /* When we get to the end of a dimension, reset it and increment
495 the next dimension. */
497 /* We could precalculate these products, but this is a less
498 frequently used path so probably not worth it. */
499 dest
-= dstride
[n
] * extent
[n
];