1 `/* Implementation of the EOSHIFT intrinsic
2 Copyright 2002 Free Software Foundation, Inc.
3 Contributed by Paul Brook <paul@nowt.org>
5 This file is part of the GNU Fortran 95 runtime library (libgfor).
7 Libgfor is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 Ligbfor 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 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with libgfor; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
26 #include "libgfortran.h"'
28 define(htype_kind, regexp(file, `_\([0-9]+\)\.', `\1'))dnl
29 define(htype_code,`i'rtype_name)dnl
30 define(htype,get_arraytype(i,htype_kind))dnl
31 define(htype_name, get_typename(i,htype_kind))dnl
33 static const char zeros[16] =
34 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
37 `__eoshift1_'htype_kind (const gfc_array_char * ret, const gfc_array_char * array,
38 const htype * h, const char * pbound, const htype_name * pwhich)
40 /* r.* indicates the return array. */
41 index_type rstride[GFC_MAX_DIMENSIONS - 1];
46 /* s.* indicates the source array. */
47 index_type sstride[GFC_MAX_DIMENSIONS - 1];
52 ` /* h.* indicates the shift array. */'
53 index_type hstride[GFC_MAX_DIMENSIONS - 1];
55 const htype_name *hptr;
57 index_type count[GFC_MAX_DIMENSIONS - 1];
58 index_type extent[GFC_MAX_DIMENSIONS - 1];
75 size = GFC_DESCRIPTOR_SIZE (ret);
79 size = GFC_DESCRIPTOR_SIZE (array);
81 for (dim = 0; dim < GFC_DESCRIPTOR_RANK (array); dim++)
85 roffset = ret->dim[dim].stride * size;
88 soffset = array->dim[dim].stride * size;
91 len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
96 extent[n] = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
97 rstride[n] = ret->dim[dim].stride * size;
98 sstride[n] = array->dim[dim].stride * size;
100 hstride[n] = h->dim[n].stride;
111 dim = GFC_DESCRIPTOR_RANK (array);
112 rstride0 = rstride[0];
113 sstride0 = sstride[0];
114 hstride0 = hstride[0];
121 ` /* Do the shift for this dimension. */'
123 delta = (sh >= 0) ? sh: -sh;
126 src = &sptr[delta * soffset];
132 dest = &rptr[delta * roffset];
134 for (n = 0; n < len - delta; n++)
136 memcpy (dest, src, size);
146 memcpy (dest, pbound, size);
150 /* Advance to the next section. */
156 while (count[n] == extent[n])
158 /* When we get to the end of a dimension, reset it and increment
159 the next dimension. */
161 /* We could precalculate these products, but this is a less
162 frequently used path so proabably not worth it. */
163 rptr -= rstride[n] * extent[n];
164 sptr -= sstride[n] * extent[n];
165 hptr -= hstride[n] * extent[n];
169 /* Break out of the loop. */