1 `/* Implementation of the MINLOC intrinsic
2 Copyright (C) 2017-2018 Free Software Foundation, Inc.
3 Contributed by Thomas Koenig
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"
32 `#if defined (HAVE_'atype_name`) && defined (HAVE_'rtype_name`)
35 compare_fcn (const 'atype_name` *a, const 'atype_name` *b, gfc_charlen_type n)
37 if (sizeof ('atype_name`) == 1)
38 return memcmp (a, b, n);
40 return memcmp_char4 (a, b, n);
43 extern 'rtype_name` 'name`'rtype_qual`_'atype_code` ('atype` * const restrict'back_arg`,
45 export_proto('name`'rtype_qual`_'atype_code`);
48 'name`'rtype_qual`_'atype_code` ('atype` * const restrict array'back_arg`,
54 const 'atype_name` *src;
55 const 'atype_name` *maxval;
59 extent = GFC_DESCRIPTOR_EXTENT(array,0);
63 sstride = GFC_DESCRIPTOR_STRIDE(array,0) * len;
66 src = array->base_addr;
68 for (i=2; i<=extent; i++)
71 if (compare_fcn (src, maxval, len) < 0)
80 extern 'rtype_name` m'name`'rtype_qual`_'atype_code` ('atype` * const restrict,
81 gfc_array_l1 *const restrict mask'back_arg`,
83 export_proto(m'name`'rtype_qual`_'atype_code`);
86 m'name`'rtype_qual`_'atype_code` ('atype` * const restrict array,
87 gfc_array_l1 * const restrict mask'back_arg`,
93 const 'atype_name` *src;
94 const 'atype_name` *maxval;
101 extent = GFC_DESCRIPTOR_EXTENT(array,0);
105 sstride = GFC_DESCRIPTOR_STRIDE(array,0) * len;
107 mask_kind = GFC_DESCRIPTOR_SIZE (mask);
108 mbase = mask->base_addr;
110 if (mask_kind == 1 || mask_kind == 2 || mask_kind == 4 || mask_kind == 8
111 #ifdef HAVE_GFC_LOGICAL_16
115 mbase = GFOR_POINTER_TO_L1 (mbase, mask_kind);
117 internal_error (NULL, "Funny sized logical array");
119 mstride = GFC_DESCRIPTOR_STRIDE_BYTES(mask,0);
121 /* Search for the first occurrence of a true element in mask. */
122 for (j=0; j<extent; j++)
133 src = array->base_addr + j * sstride;
136 for (i=j+1; i<=extent; i++)
138 if (*mbase && compare_fcn (src, maxval, len) < 0)
149 extern 'rtype_name` s'name`'rtype_qual`_'atype_code` ('atype` * const restrict,
150 GFC_LOGICAL_4 *mask'back_arg`, gfc_charlen_type);
151 export_proto(s'name`'rtype_qual`_'atype_code`);
154 s'name`'rtype_qual`_'atype_code` ('atype` * const restrict array,
155 GFC_LOGICAL_4 *mask'back_arg`, gfc_charlen_type len)
158 return 'name`'rtype_qual`_'atype_code` (array, len, back);