]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libgfortran/generated/maxloc1_8_i16.c
1 /* Implementation of the MAXLOC 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_INTEGER_16) && defined (HAVE_GFC_INTEGER_8)
33 extern void maxloc1_8_i16 (gfc_array_i8
* const restrict
,
34 gfc_array_i16
* const restrict
, const index_type
* const restrict
);
35 export_proto(maxloc1_8_i16
);
38 maxloc1_8_i16 (gfc_array_i8
* const restrict retarray
,
39 gfc_array_i16
* 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_INTEGER_16
* restrict base
;
47 GFC_INTEGER_8
* 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_INTEGER_8
));
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 " MAXLOC 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", "MAXLOC");
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_INTEGER_16
* restrict src
;
138 GFC_INTEGER_8 result
;
142 GFC_INTEGER_16 maxval
;
143 #if defined (GFC_INTEGER_16_INFINITY)
144 maxval
= -GFC_INTEGER_16_INFINITY
;
146 maxval
= (-GFC_INTEGER_16_HUGE
-1);
153 for (n
= 0; n
< len
; n
++, src
+= delta
)
156 #if defined (GFC_INTEGER_16_QUIET_NAN)
160 result
= (GFC_INTEGER_8
)n
+ 1;
164 for (; n
< len
; n
++, src
+= delta
)
170 result
= (GFC_INTEGER_8
)n
+ 1;
177 /* Advance to the next element. */
182 while (count
[n
] == extent
[n
])
184 /* When we get to the end of a dimension, reset it and increment
185 the next dimension. */
187 /* We could precalculate these products, but this is a less
188 frequently used path so probably not worth it. */
189 base
-= sstride
[n
] * extent
[n
];
190 dest
-= dstride
[n
] * extent
[n
];
194 /* Break out of the look. */
209 extern void mmaxloc1_8_i16 (gfc_array_i8
* const restrict
,
210 gfc_array_i16
* const restrict
, const index_type
* const restrict
,
211 gfc_array_l1
* const restrict
);
212 export_proto(mmaxloc1_8_i16
);
215 mmaxloc1_8_i16 (gfc_array_i8
* const restrict retarray
,
216 gfc_array_i16
* const restrict array
,
217 const index_type
* const restrict pdim
,
218 gfc_array_l1
* const restrict mask
)
220 index_type count
[GFC_MAX_DIMENSIONS
];
221 index_type extent
[GFC_MAX_DIMENSIONS
];
222 index_type sstride
[GFC_MAX_DIMENSIONS
];
223 index_type dstride
[GFC_MAX_DIMENSIONS
];
224 index_type mstride
[GFC_MAX_DIMENSIONS
];
225 GFC_INTEGER_8
* restrict dest
;
226 const GFC_INTEGER_16
* restrict base
;
227 const GFC_LOGICAL_1
* restrict mbase
;
237 rank
= GFC_DESCRIPTOR_RANK (array
) - 1;
239 len
= GFC_DESCRIPTOR_EXTENT(array
,dim
);
243 mbase
= mask
->base_addr
;
245 mask_kind
= GFC_DESCRIPTOR_SIZE (mask
);
247 if (mask_kind
== 1 || mask_kind
== 2 || mask_kind
== 4 || mask_kind
== 8
248 #ifdef HAVE_GFC_LOGICAL_16
252 mbase
= GFOR_POINTER_TO_L1 (mbase
, mask_kind
);
254 runtime_error ("Funny sized logical array");
256 delta
= GFC_DESCRIPTOR_STRIDE(array
,dim
);
257 mdelta
= GFC_DESCRIPTOR_STRIDE_BYTES(mask
,dim
);
259 for (n
= 0; n
< dim
; n
++)
261 sstride
[n
] = GFC_DESCRIPTOR_STRIDE(array
,n
);
262 mstride
[n
] = GFC_DESCRIPTOR_STRIDE_BYTES(mask
,n
);
263 extent
[n
] = GFC_DESCRIPTOR_EXTENT(array
,n
);
269 for (n
= dim
; n
< rank
; n
++)
271 sstride
[n
] = GFC_DESCRIPTOR_STRIDE(array
,n
+ 1);
272 mstride
[n
] = GFC_DESCRIPTOR_STRIDE_BYTES(mask
, n
+ 1);
273 extent
[n
] = GFC_DESCRIPTOR_EXTENT(array
, n
+ 1);
279 if (retarray
->base_addr
== NULL
)
281 size_t alloc_size
, str
;
283 for (n
= 0; n
< rank
; n
++)
288 str
= GFC_DESCRIPTOR_STRIDE(retarray
,n
-1) * extent
[n
-1];
290 GFC_DIMENSION_SET(retarray
->dim
[n
], 0, extent
[n
] - 1, str
);
294 alloc_size
= GFC_DESCRIPTOR_STRIDE(retarray
,rank
-1) * extent
[rank
-1];
296 retarray
->offset
= 0;
297 retarray
->dtype
= (array
->dtype
& ~GFC_DTYPE_RANK_MASK
) | rank
;
301 /* Make sure we have a zero-sized array. */
302 GFC_DIMENSION_SET(retarray
->dim
[0], 0, -1, 1);
306 retarray
->base_addr
= xmallocarray (alloc_size
, sizeof (GFC_INTEGER_8
));
311 if (rank
!= GFC_DESCRIPTOR_RANK (retarray
))
312 runtime_error ("rank of return array incorrect in MAXLOC intrinsic");
314 if (unlikely (compile_options
.bounds_check
))
316 bounds_ifunction_return ((array_t
*) retarray
, extent
,
317 "return value", "MAXLOC");
318 bounds_equal_extents ((array_t
*) mask
, (array_t
*) array
,
319 "MASK argument", "MAXLOC");
323 for (n
= 0; n
< rank
; n
++)
326 dstride
[n
] = GFC_DESCRIPTOR_STRIDE(retarray
,n
);
331 dest
= retarray
->base_addr
;
332 base
= array
->base_addr
;
336 const GFC_INTEGER_16
* restrict src
;
337 const GFC_LOGICAL_1
* restrict msrc
;
338 GFC_INTEGER_8 result
;
343 GFC_INTEGER_16 maxval
;
344 #if defined (GFC_INTEGER_16_INFINITY)
345 maxval
= -GFC_INTEGER_16_INFINITY
;
347 maxval
= (-GFC_INTEGER_16_HUGE
-1);
349 #if defined (GFC_INTEGER_16_QUIET_NAN)
350 GFC_INTEGER_8 result2
= 0;
353 for (n
= 0; n
< len
; n
++, src
+= delta
, msrc
+= mdelta
)
358 #if defined (GFC_INTEGER_16_QUIET_NAN)
360 result2
= (GFC_INTEGER_8
)n
+ 1;
365 result
= (GFC_INTEGER_8
)n
+ 1;
370 #if defined (GFC_INTEGER_16_QUIET_NAN)
371 if (unlikely (n
>= len
))
375 for (; n
< len
; n
++, src
+= delta
, msrc
+= mdelta
)
377 if (*msrc
&& *src
> maxval
)
380 result
= (GFC_INTEGER_8
)n
+ 1;
385 /* Advance to the next element. */
391 while (count
[n
] == extent
[n
])
393 /* When we get to the end of a dimension, reset it and increment
394 the next dimension. */
396 /* We could precalculate these products, but this is a less
397 frequently used path so probably not worth it. */
398 base
-= sstride
[n
] * extent
[n
];
399 mbase
-= mstride
[n
] * extent
[n
];
400 dest
-= dstride
[n
] * extent
[n
];
404 /* Break out of the look. */
420 extern void smaxloc1_8_i16 (gfc_array_i8
* const restrict
,
421 gfc_array_i16
* const restrict
, const index_type
* const restrict
,
423 export_proto(smaxloc1_8_i16
);
426 smaxloc1_8_i16 (gfc_array_i8
* const restrict retarray
,
427 gfc_array_i16
* const restrict array
,
428 const index_type
* const restrict pdim
,
429 GFC_LOGICAL_4
* mask
)
431 index_type count
[GFC_MAX_DIMENSIONS
];
432 index_type extent
[GFC_MAX_DIMENSIONS
];
433 index_type dstride
[GFC_MAX_DIMENSIONS
];
434 GFC_INTEGER_8
* restrict dest
;
442 maxloc1_8_i16 (retarray
, array
, pdim
);
445 /* Make dim zero based to avoid confusion. */
447 rank
= GFC_DESCRIPTOR_RANK (array
) - 1;
449 for (n
= 0; n
< dim
; n
++)
451 extent
[n
] = GFC_DESCRIPTOR_EXTENT(array
,n
);
457 for (n
= dim
; n
< rank
; n
++)
460 GFC_DESCRIPTOR_EXTENT(array
,n
+ 1);
466 if (retarray
->base_addr
== NULL
)
468 size_t alloc_size
, str
;
470 for (n
= 0; n
< rank
; n
++)
475 str
= GFC_DESCRIPTOR_STRIDE(retarray
,n
-1) * extent
[n
-1];
477 GFC_DIMENSION_SET(retarray
->dim
[n
], 0, extent
[n
] - 1, str
);
481 retarray
->offset
= 0;
482 retarray
->dtype
= (array
->dtype
& ~GFC_DTYPE_RANK_MASK
) | rank
;
484 alloc_size
= GFC_DESCRIPTOR_STRIDE(retarray
,rank
-1) * extent
[rank
-1];
488 /* Make sure we have a zero-sized array. */
489 GFC_DIMENSION_SET(retarray
->dim
[0], 0, -1, 1);
493 retarray
->base_addr
= xmallocarray (alloc_size
, sizeof (GFC_INTEGER_8
));
497 if (rank
!= GFC_DESCRIPTOR_RANK (retarray
))
498 runtime_error ("rank of return array incorrect in"
499 " MAXLOC intrinsic: is %ld, should be %ld",
500 (long int) (GFC_DESCRIPTOR_RANK (retarray
)),
503 if (unlikely (compile_options
.bounds_check
))
505 for (n
=0; n
< rank
; n
++)
507 index_type ret_extent
;
509 ret_extent
= GFC_DESCRIPTOR_EXTENT(retarray
,n
);
510 if (extent
[n
] != ret_extent
)
511 runtime_error ("Incorrect extent in return value of"
512 " MAXLOC intrinsic in dimension %ld:"
513 " is %ld, should be %ld", (long int) n
+ 1,
514 (long int) ret_extent
, (long int) extent
[n
]);
519 for (n
= 0; n
< rank
; n
++)
522 dstride
[n
] = GFC_DESCRIPTOR_STRIDE(retarray
,n
);
525 dest
= retarray
->base_addr
;
533 while (count
[n
] == extent
[n
])
535 /* When we get to the end of a dimension, reset it and increment
536 the next dimension. */
538 /* We could precalculate these products, but this is a less
539 frequently used path so probably not worth it. */
540 dest
-= dstride
[n
] * extent
[n
];