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