annotate libgfortran/generated/cshift1_16_i1.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 CSHIFT intrinsic.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2017-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 Contributed by Thomas Koenig <tkoenig@gcc.gnu.org>
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 This file is part of the GNU Fortran 95 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 #if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_16)
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 void
kono
parents:
diff changeset
32 cshift1_16_i1 (gfc_array_i1 * const restrict ret,
kono
parents:
diff changeset
33 const gfc_array_i1 * const restrict array,
kono
parents:
diff changeset
34 const gfc_array_i16 * const restrict h,
kono
parents:
diff changeset
35 const GFC_INTEGER_16 * const restrict pwhich)
kono
parents:
diff changeset
36 {
kono
parents:
diff changeset
37 /* r.* indicates the return array. */
kono
parents:
diff changeset
38 index_type rstride[GFC_MAX_DIMENSIONS];
kono
parents:
diff changeset
39 index_type rstride0;
kono
parents:
diff changeset
40 index_type roffset;
kono
parents:
diff changeset
41 GFC_INTEGER_1 *rptr;
kono
parents:
diff changeset
42 GFC_INTEGER_1 *dest;
kono
parents:
diff changeset
43 /* s.* indicates the source array. */
kono
parents:
diff changeset
44 index_type sstride[GFC_MAX_DIMENSIONS];
kono
parents:
diff changeset
45 index_type sstride0;
kono
parents:
diff changeset
46 index_type soffset;
kono
parents:
diff changeset
47 const GFC_INTEGER_1 *sptr;
kono
parents:
diff changeset
48 const GFC_INTEGER_1 *src;
kono
parents:
diff changeset
49 /* h.* indicates the shift array. */
kono
parents:
diff changeset
50 index_type hstride[GFC_MAX_DIMENSIONS];
kono
parents:
diff changeset
51 index_type hstride0;
kono
parents:
diff changeset
52 const GFC_INTEGER_16 *hptr;
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 index_type count[GFC_MAX_DIMENSIONS];
kono
parents:
diff changeset
55 index_type extent[GFC_MAX_DIMENSIONS];
kono
parents:
diff changeset
56 index_type rs_ex[GFC_MAX_DIMENSIONS];
kono
parents:
diff changeset
57 index_type ss_ex[GFC_MAX_DIMENSIONS];
kono
parents:
diff changeset
58 index_type hs_ex[GFC_MAX_DIMENSIONS];
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 index_type dim;
kono
parents:
diff changeset
61 index_type len;
kono
parents:
diff changeset
62 index_type n;
kono
parents:
diff changeset
63 int which;
kono
parents:
diff changeset
64 GFC_INTEGER_16 sh;
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 /* Bounds checking etc is already done by the caller. */
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 if (pwhich)
kono
parents:
diff changeset
69 which = *pwhich - 1;
kono
parents:
diff changeset
70 else
kono
parents:
diff changeset
71 which = 0;
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 extent[0] = 1;
kono
parents:
diff changeset
74 count[0] = 0;
kono
parents:
diff changeset
75 n = 0;
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 /* Initialized for avoiding compiler warnings. */
kono
parents:
diff changeset
78 roffset = 1;
kono
parents:
diff changeset
79 soffset = 1;
kono
parents:
diff changeset
80 len = 0;
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 for (dim = 0; dim < GFC_DESCRIPTOR_RANK (array); dim++)
kono
parents:
diff changeset
83 {
kono
parents:
diff changeset
84 if (dim == which)
kono
parents:
diff changeset
85 {
kono
parents:
diff changeset
86 roffset = GFC_DESCRIPTOR_STRIDE(ret,dim);
kono
parents:
diff changeset
87 if (roffset == 0)
kono
parents:
diff changeset
88 roffset = 1;
kono
parents:
diff changeset
89 soffset = GFC_DESCRIPTOR_STRIDE(array,dim);
kono
parents:
diff changeset
90 if (soffset == 0)
kono
parents:
diff changeset
91 soffset = 1;
kono
parents:
diff changeset
92 len = GFC_DESCRIPTOR_EXTENT(array,dim);
kono
parents:
diff changeset
93 }
kono
parents:
diff changeset
94 else
kono
parents:
diff changeset
95 {
kono
parents:
diff changeset
96 count[n] = 0;
kono
parents:
diff changeset
97 extent[n] = GFC_DESCRIPTOR_EXTENT(array,dim);
kono
parents:
diff changeset
98 rstride[n] = GFC_DESCRIPTOR_STRIDE(ret,dim);
kono
parents:
diff changeset
99 sstride[n] = GFC_DESCRIPTOR_STRIDE(array,dim);
kono
parents:
diff changeset
100 hstride[n] = GFC_DESCRIPTOR_STRIDE(h,n);
kono
parents:
diff changeset
101 rs_ex[n] = rstride[n] * extent[n];
kono
parents:
diff changeset
102 ss_ex[n] = sstride[n] * extent[n];
kono
parents:
diff changeset
103 hs_ex[n] = hstride[n] * extent[n];
kono
parents:
diff changeset
104 n++;
kono
parents:
diff changeset
105 }
kono
parents:
diff changeset
106 }
kono
parents:
diff changeset
107 if (sstride[0] == 0)
kono
parents:
diff changeset
108 sstride[0] = 1;
kono
parents:
diff changeset
109 if (rstride[0] == 0)
kono
parents:
diff changeset
110 rstride[0] = 1;
kono
parents:
diff changeset
111 if (hstride[0] == 0)
kono
parents:
diff changeset
112 hstride[0] = 1;
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 dim = GFC_DESCRIPTOR_RANK (array);
kono
parents:
diff changeset
115 rstride0 = rstride[0];
kono
parents:
diff changeset
116 sstride0 = sstride[0];
kono
parents:
diff changeset
117 hstride0 = hstride[0];
kono
parents:
diff changeset
118 rptr = ret->base_addr;
kono
parents:
diff changeset
119 sptr = array->base_addr;
kono
parents:
diff changeset
120 hptr = h->base_addr;
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122 while (rptr)
kono
parents:
diff changeset
123 {
kono
parents:
diff changeset
124 /* Do the shift for this dimension. */
kono
parents:
diff changeset
125 sh = *hptr;
kono
parents:
diff changeset
126 /* Normal case should be -len < sh < len; try to
kono
parents:
diff changeset
127 avoid the expensive remainder operation if possible. */
kono
parents:
diff changeset
128 if (sh < 0)
kono
parents:
diff changeset
129 sh += len;
kono
parents:
diff changeset
130 if (unlikely(sh >= len || sh < 0))
kono
parents:
diff changeset
131 {
kono
parents:
diff changeset
132 sh = sh % len;
kono
parents:
diff changeset
133 if (sh < 0)
kono
parents:
diff changeset
134 sh += len;
kono
parents:
diff changeset
135 }
kono
parents:
diff changeset
136 src = &sptr[sh * soffset];
kono
parents:
diff changeset
137 dest = rptr;
kono
parents:
diff changeset
138 if (soffset == 1 && roffset == 1)
kono
parents:
diff changeset
139 {
kono
parents:
diff changeset
140 size_t len1 = sh * sizeof (GFC_INTEGER_1);
kono
parents:
diff changeset
141 size_t len2 = (len - sh) * sizeof (GFC_INTEGER_1);
kono
parents:
diff changeset
142 memcpy (rptr, sptr + sh, len2);
kono
parents:
diff changeset
143 memcpy (rptr + (len - sh), sptr, len1);
kono
parents:
diff changeset
144 }
kono
parents:
diff changeset
145 else
kono
parents:
diff changeset
146 {
kono
parents:
diff changeset
147 for (n = 0; n < len - sh; n++)
kono
parents:
diff changeset
148 {
kono
parents:
diff changeset
149 *dest = *src;
kono
parents:
diff changeset
150 dest += roffset;
kono
parents:
diff changeset
151 src += soffset;
kono
parents:
diff changeset
152 }
kono
parents:
diff changeset
153 for (src = sptr, n = 0; n < sh; n++)
kono
parents:
diff changeset
154 {
kono
parents:
diff changeset
155 *dest = *src;
kono
parents:
diff changeset
156 dest += roffset;
kono
parents:
diff changeset
157 src += soffset;
kono
parents:
diff changeset
158 }
kono
parents:
diff changeset
159 }
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 /* Advance to the next section. */
kono
parents:
diff changeset
162 rptr += rstride0;
kono
parents:
diff changeset
163 sptr += sstride0;
kono
parents:
diff changeset
164 hptr += hstride0;
kono
parents:
diff changeset
165 count[0]++;
kono
parents:
diff changeset
166 n = 0;
kono
parents:
diff changeset
167 while (count[n] == extent[n])
kono
parents:
diff changeset
168 {
kono
parents:
diff changeset
169 /* When we get to the end of a dimension, reset it and increment
kono
parents:
diff changeset
170 the next dimension. */
kono
parents:
diff changeset
171 count[n] = 0;
kono
parents:
diff changeset
172 rptr -= rs_ex[n];
kono
parents:
diff changeset
173 sptr -= ss_ex[n];
kono
parents:
diff changeset
174 hptr -= hs_ex[n];
kono
parents:
diff changeset
175 n++;
kono
parents:
diff changeset
176 if (n >= dim - 1)
kono
parents:
diff changeset
177 {
kono
parents:
diff changeset
178 /* Break out of the loop. */
kono
parents:
diff changeset
179 rptr = NULL;
kono
parents:
diff changeset
180 break;
kono
parents:
diff changeset
181 }
kono
parents:
diff changeset
182 else
kono
parents:
diff changeset
183 {
kono
parents:
diff changeset
184 count[n]++;
kono
parents:
diff changeset
185 rptr += rstride[n];
kono
parents:
diff changeset
186 sptr += sstride[n];
kono
parents:
diff changeset
187 hptr += hstride[n];
kono
parents:
diff changeset
188 }
kono
parents:
diff changeset
189 }
kono
parents:
diff changeset
190 }
kono
parents:
diff changeset
191 }
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 #endif