annotate libgfortran/runtime/in_unpack_generic.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Generic helper function for repacking arrays.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2003-2018 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 extern void internal_unpack (gfc_array_char *, const void *);
kono
parents:
diff changeset
30 export_proto(internal_unpack);
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 void
kono
parents:
diff changeset
33 internal_unpack (gfc_array_char * d, const void * s)
kono
parents:
diff changeset
34 {
kono
parents:
diff changeset
35 index_type count[GFC_MAX_DIMENSIONS];
kono
parents:
diff changeset
36 index_type extent[GFC_MAX_DIMENSIONS];
kono
parents:
diff changeset
37 index_type stride[GFC_MAX_DIMENSIONS];
kono
parents:
diff changeset
38 index_type stride0;
kono
parents:
diff changeset
39 index_type dim;
kono
parents:
diff changeset
40 index_type dsize;
kono
parents:
diff changeset
41 char *dest;
kono
parents:
diff changeset
42 const char *src;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
43 index_type size;
111
kono
parents:
diff changeset
44 int type_size;
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 dest = d->base_addr;
kono
parents:
diff changeset
47 /* This check may be redundant, but do it anyway. */
kono
parents:
diff changeset
48 if (s == dest || !s)
kono
parents:
diff changeset
49 return;
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 type_size = GFC_DTYPE_TYPE_SIZE (d);
kono
parents:
diff changeset
52 switch (type_size)
kono
parents:
diff changeset
53 {
kono
parents:
diff changeset
54 case GFC_DTYPE_INTEGER_1:
kono
parents:
diff changeset
55 case GFC_DTYPE_LOGICAL_1:
kono
parents:
diff changeset
56 internal_unpack_1 ((gfc_array_i1 *) d, (const GFC_INTEGER_1 *) s);
kono
parents:
diff changeset
57 return;
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 case GFC_DTYPE_INTEGER_2:
kono
parents:
diff changeset
60 case GFC_DTYPE_LOGICAL_2:
kono
parents:
diff changeset
61 internal_unpack_2 ((gfc_array_i2 *) d, (const GFC_INTEGER_2 *) s);
kono
parents:
diff changeset
62 return;
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 case GFC_DTYPE_INTEGER_4:
kono
parents:
diff changeset
65 case GFC_DTYPE_LOGICAL_4:
kono
parents:
diff changeset
66 internal_unpack_4 ((gfc_array_i4 *) d, (const GFC_INTEGER_4 *) s);
kono
parents:
diff changeset
67 return;
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 case GFC_DTYPE_INTEGER_8:
kono
parents:
diff changeset
70 case GFC_DTYPE_LOGICAL_8:
kono
parents:
diff changeset
71 internal_unpack_8 ((gfc_array_i8 *) d, (const GFC_INTEGER_8 *) s);
kono
parents:
diff changeset
72 return;
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 #if defined (HAVE_GFC_INTEGER_16)
kono
parents:
diff changeset
75 case GFC_DTYPE_INTEGER_16:
kono
parents:
diff changeset
76 case GFC_DTYPE_LOGICAL_16:
kono
parents:
diff changeset
77 internal_unpack_16 ((gfc_array_i16 *) d, (const GFC_INTEGER_16 *) s);
kono
parents:
diff changeset
78 return;
kono
parents:
diff changeset
79 #endif
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 case GFC_DTYPE_REAL_4:
kono
parents:
diff changeset
82 internal_unpack_r4 ((gfc_array_r4 *) d, (const GFC_REAL_4 *) s);
kono
parents:
diff changeset
83 return;
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 case GFC_DTYPE_REAL_8:
kono
parents:
diff changeset
86 internal_unpack_r8 ((gfc_array_r8 *) d, (const GFC_REAL_8 *) s);
kono
parents:
diff changeset
87 return;
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 /* FIXME: This here is a hack, which will have to be removed when
kono
parents:
diff changeset
90 the array descriptor is reworked. Currently, we don't store the
kono
parents:
diff changeset
91 kind value for the type, but only the size. Because on targets with
kono
parents:
diff changeset
92 __float128, we have sizeof(logn double) == sizeof(__float128),
kono
parents:
diff changeset
93 we cannot discriminate here and have to fall back to the generic
kono
parents:
diff changeset
94 handling (which is suboptimal). */
kono
parents:
diff changeset
95 #if !defined(GFC_REAL_16_IS_FLOAT128)
kono
parents:
diff changeset
96 # if defined(HAVE_GFC_REAL_10)
kono
parents:
diff changeset
97 case GFC_DTYPE_REAL_10:
kono
parents:
diff changeset
98 internal_unpack_r10 ((gfc_array_r10 *) d, (const GFC_REAL_10 *) s);
kono
parents:
diff changeset
99 return;
kono
parents:
diff changeset
100 # endif
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 # if defined(HAVE_GFC_REAL_16)
kono
parents:
diff changeset
103 case GFC_DTYPE_REAL_16:
kono
parents:
diff changeset
104 internal_unpack_r16 ((gfc_array_r16 *) d, (const GFC_REAL_16 *) s);
kono
parents:
diff changeset
105 return;
kono
parents:
diff changeset
106 # endif
kono
parents:
diff changeset
107 #endif
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 case GFC_DTYPE_COMPLEX_4:
kono
parents:
diff changeset
110 internal_unpack_c4 ((gfc_array_c4 *)d, (const GFC_COMPLEX_4 *)s);
kono
parents:
diff changeset
111 return;
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 case GFC_DTYPE_COMPLEX_8:
kono
parents:
diff changeset
114 internal_unpack_c8 ((gfc_array_c8 *)d, (const GFC_COMPLEX_8 *)s);
kono
parents:
diff changeset
115 return;
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 /* FIXME: This here is a hack, which will have to be removed when
kono
parents:
diff changeset
118 the array descriptor is reworked. Currently, we don't store the
kono
parents:
diff changeset
119 kind value for the type, but only the size. Because on targets with
kono
parents:
diff changeset
120 __float128, we have sizeof(logn double) == sizeof(__float128),
kono
parents:
diff changeset
121 we cannot discriminate here and have to fall back to the generic
kono
parents:
diff changeset
122 handling (which is suboptimal). */
kono
parents:
diff changeset
123 #if !defined(GFC_REAL_16_IS_FLOAT128)
kono
parents:
diff changeset
124 # if defined(HAVE_GFC_COMPLEX_10)
kono
parents:
diff changeset
125 case GFC_DTYPE_COMPLEX_10:
kono
parents:
diff changeset
126 internal_unpack_c10 ((gfc_array_c10 *) d, (const GFC_COMPLEX_10 *) s);
kono
parents:
diff changeset
127 return;
kono
parents:
diff changeset
128 # endif
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 # if defined(HAVE_GFC_COMPLEX_16)
kono
parents:
diff changeset
131 case GFC_DTYPE_COMPLEX_16:
kono
parents:
diff changeset
132 internal_unpack_c16 ((gfc_array_c16 *) d, (const GFC_COMPLEX_16 *) s);
kono
parents:
diff changeset
133 return;
kono
parents:
diff changeset
134 # endif
kono
parents:
diff changeset
135 #endif
kono
parents:
diff changeset
136
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
137 default:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
138 break;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
139 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
140
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
141 switch (GFC_DESCRIPTOR_SIZE(d))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
142 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
143 case 1:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
144 internal_unpack_1 ((gfc_array_i1 *) d, (const GFC_INTEGER_1 *) s);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
145 return;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
146
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
147 case 2:
111
kono
parents:
diff changeset
148 if (GFC_UNALIGNED_2(d->base_addr) || GFC_UNALIGNED_2(s))
kono
parents:
diff changeset
149 break;
kono
parents:
diff changeset
150 else
kono
parents:
diff changeset
151 {
kono
parents:
diff changeset
152 internal_unpack_2 ((gfc_array_i2 *) d, (const GFC_INTEGER_2 *) s);
kono
parents:
diff changeset
153 return;
kono
parents:
diff changeset
154 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
155
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
156 case 4:
111
kono
parents:
diff changeset
157 if (GFC_UNALIGNED_4(d->base_addr) || GFC_UNALIGNED_4(s))
kono
parents:
diff changeset
158 break;
kono
parents:
diff changeset
159 else
kono
parents:
diff changeset
160 {
kono
parents:
diff changeset
161 internal_unpack_4 ((gfc_array_i4 *) d, (const GFC_INTEGER_4 *) s);
kono
parents:
diff changeset
162 return;
kono
parents:
diff changeset
163 }
kono
parents:
diff changeset
164
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
165 case 8:
111
kono
parents:
diff changeset
166 if (GFC_UNALIGNED_8(d->base_addr) || GFC_UNALIGNED_8(s))
kono
parents:
diff changeset
167 break;
kono
parents:
diff changeset
168 else
kono
parents:
diff changeset
169 {
kono
parents:
diff changeset
170 internal_unpack_8 ((gfc_array_i8 *) d, (const GFC_INTEGER_8 *) s);
kono
parents:
diff changeset
171 return;
kono
parents:
diff changeset
172 }
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 #ifdef HAVE_GFC_INTEGER_16
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
175 case 16:
111
kono
parents:
diff changeset
176 if (GFC_UNALIGNED_16(d->base_addr) || GFC_UNALIGNED_16(s))
kono
parents:
diff changeset
177 break;
kono
parents:
diff changeset
178 else
kono
parents:
diff changeset
179 {
kono
parents:
diff changeset
180 internal_unpack_16 ((gfc_array_i16 *) d, (const GFC_INTEGER_16 *) s);
kono
parents:
diff changeset
181 return;
kono
parents:
diff changeset
182 }
kono
parents:
diff changeset
183 #endif
kono
parents:
diff changeset
184 default:
kono
parents:
diff changeset
185 break;
kono
parents:
diff changeset
186 }
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 size = GFC_DESCRIPTOR_SIZE (d);
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 dim = GFC_DESCRIPTOR_RANK (d);
kono
parents:
diff changeset
191 dsize = 1;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
192 for (index_type n = 0; n < dim; n++)
111
kono
parents:
diff changeset
193 {
kono
parents:
diff changeset
194 count[n] = 0;
kono
parents:
diff changeset
195 stride[n] = GFC_DESCRIPTOR_STRIDE(d,n);
kono
parents:
diff changeset
196 extent[n] = GFC_DESCRIPTOR_EXTENT(d,n);
kono
parents:
diff changeset
197 if (extent[n] <= 0)
kono
parents:
diff changeset
198 return;
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 if (dsize == stride[n])
kono
parents:
diff changeset
201 dsize *= extent[n];
kono
parents:
diff changeset
202 else
kono
parents:
diff changeset
203 dsize = 0;
kono
parents:
diff changeset
204 }
kono
parents:
diff changeset
205
kono
parents:
diff changeset
206 src = s;
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 if (dsize != 0)
kono
parents:
diff changeset
209 {
kono
parents:
diff changeset
210 memcpy (dest, src, dsize * size);
kono
parents:
diff changeset
211 return;
kono
parents:
diff changeset
212 }
kono
parents:
diff changeset
213
kono
parents:
diff changeset
214 stride0 = stride[0] * size;
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 while (dest)
kono
parents:
diff changeset
217 {
kono
parents:
diff changeset
218 /* Copy the data. */
kono
parents:
diff changeset
219 memcpy (dest, src, size);
kono
parents:
diff changeset
220 /* Advance to the next element. */
kono
parents:
diff changeset
221 src += size;
kono
parents:
diff changeset
222 dest += stride0;
kono
parents:
diff changeset
223 count[0]++;
kono
parents:
diff changeset
224 /* Advance to the next source element. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
225 index_type n = 0;
111
kono
parents:
diff changeset
226 while (count[n] == extent[n])
kono
parents:
diff changeset
227 {
kono
parents:
diff changeset
228 /* When we get to the end of a dimension, reset it and increment
kono
parents:
diff changeset
229 the next dimension. */
kono
parents:
diff changeset
230 count[n] = 0;
kono
parents:
diff changeset
231 /* We could precalculate these products, but this is a less
kono
parents:
diff changeset
232 frequently used path so probably not worth it. */
kono
parents:
diff changeset
233 dest -= stride[n] * extent[n] * size;
kono
parents:
diff changeset
234 n++;
kono
parents:
diff changeset
235 if (n == dim)
kono
parents:
diff changeset
236 {
kono
parents:
diff changeset
237 dest = NULL;
kono
parents:
diff changeset
238 break;
kono
parents:
diff changeset
239 }
kono
parents:
diff changeset
240 else
kono
parents:
diff changeset
241 {
kono
parents:
diff changeset
242 count[n]++;
kono
parents:
diff changeset
243 dest += stride[n] * size;
kono
parents:
diff changeset
244 }
kono
parents:
diff changeset
245 }
kono
parents:
diff changeset
246 }
kono
parents:
diff changeset
247 }