annotate libgfortran/generated/eoshift1_16.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Implementation of the EOSHIFT intrinsic
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2002-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 Contributed by Paul Brook <paul@nowt.org>
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 This file is part of the GNU Fortran runtime library (libgfortran).
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 Libgfortran is free software; you can redistribute it and/or
kono
parents:
diff changeset
8 modify it under the terms of the GNU General Public
kono
parents:
diff changeset
9 License as published by the Free Software Foundation; either
kono
parents:
diff changeset
10 version 3 of the License, or (at your option) any later version.
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 Libgfortran is distributed in the hope that it will be useful,
kono
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
15 GNU General Public License for more details.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
18 permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
19 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
22 a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
24 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 #include "libgfortran.h"
kono
parents:
diff changeset
27 #include <string.h>
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 #if defined (HAVE_GFC_INTEGER_16)
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 static void
kono
parents:
diff changeset
33 eoshift1 (gfc_array_char * const restrict ret,
kono
parents:
diff changeset
34 const gfc_array_char * const restrict array,
kono
parents:
diff changeset
35 const gfc_array_i16 * const restrict h,
kono
parents:
diff changeset
36 const char * const restrict pbound,
kono
parents:
diff changeset
37 const GFC_INTEGER_16 * const restrict pwhich,
kono
parents:
diff changeset
38 const char * filler, index_type filler_len)
kono
parents:
diff changeset
39 {
kono
parents:
diff changeset
40 /* r.* indicates the return array. */
kono
parents:
diff changeset
41 index_type rstride[GFC_MAX_DIMENSIONS];
kono
parents:
diff changeset
42 index_type rstride0;
kono
parents:
diff changeset
43 index_type roffset;
kono
parents:
diff changeset
44 char *rptr;
kono
parents:
diff changeset
45 char * restrict dest;
kono
parents:
diff changeset
46 /* s.* indicates the source array. */
kono
parents:
diff changeset
47 index_type sstride[GFC_MAX_DIMENSIONS];
kono
parents:
diff changeset
48 index_type sstride0;
kono
parents:
diff changeset
49 index_type soffset;
kono
parents:
diff changeset
50 const char *sptr;
kono
parents:
diff changeset
51 const char *src;
kono
parents:
diff changeset
52 /* h.* indicates the shift array. */
kono
parents:
diff changeset
53 index_type hstride[GFC_MAX_DIMENSIONS];
kono
parents:
diff changeset
54 index_type hstride0;
kono
parents:
diff changeset
55 const GFC_INTEGER_16 *hptr;
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 index_type count[GFC_MAX_DIMENSIONS];
kono
parents:
diff changeset
58 index_type extent[GFC_MAX_DIMENSIONS];
kono
parents:
diff changeset
59 index_type dim;
kono
parents:
diff changeset
60 index_type len;
kono
parents:
diff changeset
61 index_type n;
kono
parents:
diff changeset
62 index_type size;
kono
parents:
diff changeset
63 index_type arraysize;
kono
parents:
diff changeset
64 int which;
kono
parents:
diff changeset
65 GFC_INTEGER_16 sh;
kono
parents:
diff changeset
66 GFC_INTEGER_16 delta;
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 /* The compiler cannot figure out that these are set, initialize
kono
parents:
diff changeset
69 them to avoid warnings. */
kono
parents:
diff changeset
70 len = 0;
kono
parents:
diff changeset
71 soffset = 0;
kono
parents:
diff changeset
72 roffset = 0;
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 size = GFC_DESCRIPTOR_SIZE(array);
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 if (pwhich)
kono
parents:
diff changeset
77 which = *pwhich - 1;
kono
parents:
diff changeset
78 else
kono
parents:
diff changeset
79 which = 0;
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 extent[0] = 1;
kono
parents:
diff changeset
82 count[0] = 0;
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 arraysize = size0 ((array_t *) array);
kono
parents:
diff changeset
85 if (ret->base_addr == NULL)
kono
parents:
diff changeset
86 {
kono
parents:
diff changeset
87 ret->offset = 0;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
88 GFC_DTYPE_COPY(ret,array);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
89 for (index_type i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
111
kono
parents:
diff changeset
90 {
kono
parents:
diff changeset
91 index_type ub, str;
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 ub = GFC_DESCRIPTOR_EXTENT(array,i) - 1;
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 if (i == 0)
kono
parents:
diff changeset
96 str = 1;
kono
parents:
diff changeset
97 else
kono
parents:
diff changeset
98 str = GFC_DESCRIPTOR_EXTENT(ret,i-1)
kono
parents:
diff changeset
99 * GFC_DESCRIPTOR_STRIDE(ret,i-1);
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 GFC_DIMENSION_SET(ret->dim[i], 0, ub, str);
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 }
kono
parents:
diff changeset
104 /* xmallocarray allocates a single byte for zero size. */
kono
parents:
diff changeset
105 ret->base_addr = xmallocarray (arraysize, size);
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 }
kono
parents:
diff changeset
108 else if (unlikely (compile_options.bounds_check))
kono
parents:
diff changeset
109 {
kono
parents:
diff changeset
110 bounds_equal_extents ((array_t *) ret, (array_t *) array,
kono
parents:
diff changeset
111 "return value", "EOSHIFT");
kono
parents:
diff changeset
112 }
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 if (unlikely (compile_options.bounds_check))
kono
parents:
diff changeset
115 {
kono
parents:
diff changeset
116 bounds_reduced_extents ((array_t *) h, (array_t *) array, which,
kono
parents:
diff changeset
117 "SHIFT argument", "EOSHIFT");
kono
parents:
diff changeset
118 }
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 if (arraysize == 0)
kono
parents:
diff changeset
121 return;
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 n = 0;
kono
parents:
diff changeset
124 for (dim = 0; dim < GFC_DESCRIPTOR_RANK (array); dim++)
kono
parents:
diff changeset
125 {
kono
parents:
diff changeset
126 if (dim == which)
kono
parents:
diff changeset
127 {
kono
parents:
diff changeset
128 roffset = GFC_DESCRIPTOR_STRIDE_BYTES(ret,dim);
kono
parents:
diff changeset
129 if (roffset == 0)
kono
parents:
diff changeset
130 roffset = size;
kono
parents:
diff changeset
131 soffset = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim);
kono
parents:
diff changeset
132 if (soffset == 0)
kono
parents:
diff changeset
133 soffset = size;
kono
parents:
diff changeset
134 len = GFC_DESCRIPTOR_EXTENT(array,dim);
kono
parents:
diff changeset
135 }
kono
parents:
diff changeset
136 else
kono
parents:
diff changeset
137 {
kono
parents:
diff changeset
138 count[n] = 0;
kono
parents:
diff changeset
139 extent[n] = GFC_DESCRIPTOR_EXTENT(array,dim);
kono
parents:
diff changeset
140 rstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(ret,dim);
kono
parents:
diff changeset
141 sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim);
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 hstride[n] = GFC_DESCRIPTOR_STRIDE(h,n);
kono
parents:
diff changeset
144 n++;
kono
parents:
diff changeset
145 }
kono
parents:
diff changeset
146 }
kono
parents:
diff changeset
147 if (sstride[0] == 0)
kono
parents:
diff changeset
148 sstride[0] = size;
kono
parents:
diff changeset
149 if (rstride[0] == 0)
kono
parents:
diff changeset
150 rstride[0] = size;
kono
parents:
diff changeset
151 if (hstride[0] == 0)
kono
parents:
diff changeset
152 hstride[0] = 1;
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 dim = GFC_DESCRIPTOR_RANK (array);
kono
parents:
diff changeset
155 rstride0 = rstride[0];
kono
parents:
diff changeset
156 sstride0 = sstride[0];
kono
parents:
diff changeset
157 hstride0 = hstride[0];
kono
parents:
diff changeset
158 rptr = ret->base_addr;
kono
parents:
diff changeset
159 sptr = array->base_addr;
kono
parents:
diff changeset
160 hptr = h->base_addr;
kono
parents:
diff changeset
161
kono
parents:
diff changeset
162 while (rptr)
kono
parents:
diff changeset
163 {
kono
parents:
diff changeset
164 /* Do the shift for this dimension. */
kono
parents:
diff changeset
165 sh = *hptr;
kono
parents:
diff changeset
166 if (( sh >= 0 ? sh : -sh ) > len)
kono
parents:
diff changeset
167 {
kono
parents:
diff changeset
168 delta = len;
kono
parents:
diff changeset
169 sh = len;
kono
parents:
diff changeset
170 }
kono
parents:
diff changeset
171 else
kono
parents:
diff changeset
172 delta = (sh >= 0) ? sh: -sh;
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 if (sh > 0)
kono
parents:
diff changeset
175 {
kono
parents:
diff changeset
176 src = &sptr[delta * soffset];
kono
parents:
diff changeset
177 dest = rptr;
kono
parents:
diff changeset
178 }
kono
parents:
diff changeset
179 else
kono
parents:
diff changeset
180 {
kono
parents:
diff changeset
181 src = sptr;
kono
parents:
diff changeset
182 dest = &rptr[delta * roffset];
kono
parents:
diff changeset
183 }
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 /* If the elements are contiguous, perform a single block move. */
kono
parents:
diff changeset
186 if (soffset == size && roffset == size)
kono
parents:
diff changeset
187 {
kono
parents:
diff changeset
188 size_t chunk = size * (len - delta);
kono
parents:
diff changeset
189 memcpy (dest, src, chunk);
kono
parents:
diff changeset
190 dest += chunk;
kono
parents:
diff changeset
191 }
kono
parents:
diff changeset
192 else
kono
parents:
diff changeset
193 {
kono
parents:
diff changeset
194 for (n = 0; n < len - delta; n++)
kono
parents:
diff changeset
195 {
kono
parents:
diff changeset
196 memcpy (dest, src, size);
kono
parents:
diff changeset
197 dest += roffset;
kono
parents:
diff changeset
198 src += soffset;
kono
parents:
diff changeset
199 }
kono
parents:
diff changeset
200 }
kono
parents:
diff changeset
201 if (sh < 0)
kono
parents:
diff changeset
202 dest = rptr;
kono
parents:
diff changeset
203 n = delta;
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 if (pbound)
kono
parents:
diff changeset
206 while (n--)
kono
parents:
diff changeset
207 {
kono
parents:
diff changeset
208 memcpy (dest, pbound, size);
kono
parents:
diff changeset
209 dest += roffset;
kono
parents:
diff changeset
210 }
kono
parents:
diff changeset
211 else
kono
parents:
diff changeset
212 while (n--)
kono
parents:
diff changeset
213 {
kono
parents:
diff changeset
214 index_type i;
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 if (filler_len == 1)
kono
parents:
diff changeset
217 memset (dest, filler[0], size);
kono
parents:
diff changeset
218 else
kono
parents:
diff changeset
219 for (i = 0; i < size; i += filler_len)
kono
parents:
diff changeset
220 memcpy (&dest[i], filler, filler_len);
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 dest += roffset;
kono
parents:
diff changeset
223 }
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225 /* Advance to the next section. */
kono
parents:
diff changeset
226 rptr += rstride0;
kono
parents:
diff changeset
227 sptr += sstride0;
kono
parents:
diff changeset
228 hptr += hstride0;
kono
parents:
diff changeset
229 count[0]++;
kono
parents:
diff changeset
230 n = 0;
kono
parents:
diff changeset
231 while (count[n] == extent[n])
kono
parents:
diff changeset
232 {
kono
parents:
diff changeset
233 /* When we get to the end of a dimension, reset it and increment
kono
parents:
diff changeset
234 the next dimension. */
kono
parents:
diff changeset
235 count[n] = 0;
kono
parents:
diff changeset
236 /* We could precalculate these products, but this is a less
kono
parents:
diff changeset
237 frequently used path so probably not worth it. */
kono
parents:
diff changeset
238 rptr -= rstride[n] * extent[n];
kono
parents:
diff changeset
239 sptr -= sstride[n] * extent[n];
kono
parents:
diff changeset
240 hptr -= hstride[n] * extent[n];
kono
parents:
diff changeset
241 n++;
kono
parents:
diff changeset
242 if (n >= dim - 1)
kono
parents:
diff changeset
243 {
kono
parents:
diff changeset
244 /* Break out of the loop. */
kono
parents:
diff changeset
245 rptr = NULL;
kono
parents:
diff changeset
246 break;
kono
parents:
diff changeset
247 }
kono
parents:
diff changeset
248 else
kono
parents:
diff changeset
249 {
kono
parents:
diff changeset
250 count[n]++;
kono
parents:
diff changeset
251 rptr += rstride[n];
kono
parents:
diff changeset
252 sptr += sstride[n];
kono
parents:
diff changeset
253 hptr += hstride[n];
kono
parents:
diff changeset
254 }
kono
parents:
diff changeset
255 }
kono
parents:
diff changeset
256 }
kono
parents:
diff changeset
257 }
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259 void eoshift1_16 (gfc_array_char * const restrict,
kono
parents:
diff changeset
260 const gfc_array_char * const restrict,
kono
parents:
diff changeset
261 const gfc_array_i16 * const restrict, const char * const restrict,
kono
parents:
diff changeset
262 const GFC_INTEGER_16 * const restrict);
kono
parents:
diff changeset
263 export_proto(eoshift1_16);
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 void
kono
parents:
diff changeset
266 eoshift1_16 (gfc_array_char * const restrict ret,
kono
parents:
diff changeset
267 const gfc_array_char * const restrict array,
kono
parents:
diff changeset
268 const gfc_array_i16 * const restrict h,
kono
parents:
diff changeset
269 const char * const restrict pbound,
kono
parents:
diff changeset
270 const GFC_INTEGER_16 * const restrict pwhich)
kono
parents:
diff changeset
271 {
kono
parents:
diff changeset
272 eoshift1 (ret, array, h, pbound, pwhich, "\0", 1);
kono
parents:
diff changeset
273 }
kono
parents:
diff changeset
274
kono
parents:
diff changeset
275
kono
parents:
diff changeset
276 void eoshift1_16_char (gfc_array_char * const restrict,
kono
parents:
diff changeset
277 GFC_INTEGER_4,
kono
parents:
diff changeset
278 const gfc_array_char * const restrict,
kono
parents:
diff changeset
279 const gfc_array_i16 * const restrict,
kono
parents:
diff changeset
280 const char * const restrict,
kono
parents:
diff changeset
281 const GFC_INTEGER_16 * const restrict,
kono
parents:
diff changeset
282 GFC_INTEGER_4, GFC_INTEGER_4);
kono
parents:
diff changeset
283 export_proto(eoshift1_16_char);
kono
parents:
diff changeset
284
kono
parents:
diff changeset
285 void
kono
parents:
diff changeset
286 eoshift1_16_char (gfc_array_char * const restrict ret,
kono
parents:
diff changeset
287 GFC_INTEGER_4 ret_length __attribute__((unused)),
kono
parents:
diff changeset
288 const gfc_array_char * const restrict array,
kono
parents:
diff changeset
289 const gfc_array_i16 * const restrict h,
kono
parents:
diff changeset
290 const char * const restrict pbound,
kono
parents:
diff changeset
291 const GFC_INTEGER_16 * const restrict pwhich,
kono
parents:
diff changeset
292 GFC_INTEGER_4 array_length __attribute__((unused)),
kono
parents:
diff changeset
293 GFC_INTEGER_4 bound_length __attribute__((unused)))
kono
parents:
diff changeset
294 {
kono
parents:
diff changeset
295 eoshift1 (ret, array, h, pbound, pwhich, " ", 1);
kono
parents:
diff changeset
296 }
kono
parents:
diff changeset
297
kono
parents:
diff changeset
298
kono
parents:
diff changeset
299 void eoshift1_16_char4 (gfc_array_char * const restrict,
kono
parents:
diff changeset
300 GFC_INTEGER_4,
kono
parents:
diff changeset
301 const gfc_array_char * const restrict,
kono
parents:
diff changeset
302 const gfc_array_i16 * const restrict,
kono
parents:
diff changeset
303 const char * const restrict,
kono
parents:
diff changeset
304 const GFC_INTEGER_16 * const restrict,
kono
parents:
diff changeset
305 GFC_INTEGER_4, GFC_INTEGER_4);
kono
parents:
diff changeset
306 export_proto(eoshift1_16_char4);
kono
parents:
diff changeset
307
kono
parents:
diff changeset
308 void
kono
parents:
diff changeset
309 eoshift1_16_char4 (gfc_array_char * const restrict ret,
kono
parents:
diff changeset
310 GFC_INTEGER_4 ret_length __attribute__((unused)),
kono
parents:
diff changeset
311 const gfc_array_char * const restrict array,
kono
parents:
diff changeset
312 const gfc_array_i16 * const restrict h,
kono
parents:
diff changeset
313 const char * const restrict pbound,
kono
parents:
diff changeset
314 const GFC_INTEGER_16 * const restrict pwhich,
kono
parents:
diff changeset
315 GFC_INTEGER_4 array_length __attribute__((unused)),
kono
parents:
diff changeset
316 GFC_INTEGER_4 bound_length __attribute__((unused)))
kono
parents:
diff changeset
317 {
kono
parents:
diff changeset
318 static const gfc_char4_t space = (unsigned char) ' ';
kono
parents:
diff changeset
319 eoshift1 (ret, array, h, pbound, pwhich,
kono
parents:
diff changeset
320 (const char *) &space, sizeof (gfc_char4_t));
kono
parents:
diff changeset
321 }
kono
parents:
diff changeset
322
kono
parents:
diff changeset
323 #endif