]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libgfortran/generated/reshape_i4.c
1 /* Implementation of the RESHAPE
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. */
25 #include "libgfortran.h"
27 typedef GFC_ARRAY_DESCRIPTOR(1, index_type
) shape_type
;
29 /* The shape parameter is ignored. We can currently deduce the shape from the
32 __reshape_4 (gfc_array_i4
* ret
, gfc_array_i4
* source
, shape_type
* shape
,
33 gfc_array_i4
* pad
, shape_type
* order
)
35 /* r.* indicates the return array. */
36 index_type rcount
[GFC_MAX_DIMENSIONS
- 1];
37 index_type rextent
[GFC_MAX_DIMENSIONS
- 1];
38 index_type rstride
[GFC_MAX_DIMENSIONS
- 1];
43 /* s.* indicates the source array. */
44 index_type scount
[GFC_MAX_DIMENSIONS
- 1];
45 index_type sextent
[GFC_MAX_DIMENSIONS
- 1];
46 index_type sstride
[GFC_MAX_DIMENSIONS
- 1];
50 const GFC_INTEGER_4
*sptr
;
51 /* p.* indicates the pad array. */
52 index_type pcount
[GFC_MAX_DIMENSIONS
- 1];
53 index_type pextent
[GFC_MAX_DIMENSIONS
- 1];
54 index_type pstride
[GFC_MAX_DIMENSIONS
- 1];
57 const GFC_INTEGER_4
*pptr
;
59 const GFC_INTEGER_4
*src
;
63 if (ret
->dim
[0].stride
== 0)
64 ret
->dim
[0].stride
= 1;
65 if (source
->dim
[0].stride
== 0)
66 source
->dim
[0].stride
= 1;
67 if (shape
->dim
[0].stride
== 0)
68 shape
->dim
[0].stride
= 1;
69 if (pad
&& pad
->dim
[0].stride
== 0)
70 pad
->dim
[0].stride
= 1;
71 if (order
&& order
->dim
[0].stride
== 0)
72 order
->dim
[0].stride
= 1;
74 rdim
= GFC_DESCRIPTOR_RANK (ret
);
76 for (n
= 0; n
< rdim
; n
++)
79 dim
= order
->data
[n
* order
->dim
[0].stride
] - 1;
84 rstride
[n
] = ret
->dim
[dim
].stride
;
85 rextent
[n
] = ret
->dim
[dim
].ubound
+ 1 - ret
->dim
[dim
].lbound
;
87 if (rextent
[n
] != shape
->data
[dim
* shape
->dim
[0].stride
])
88 runtime_error ("shape and target do not conform");
90 if (rsize
== rstride
[n
])
94 if (rextent
[dim
] <= 0)
98 sdim
= GFC_DESCRIPTOR_RANK (source
);
100 for (n
= 0; n
< sdim
; n
++)
103 sstride
[n
] = source
->dim
[n
].stride
;
104 sextent
[n
] = source
->dim
[n
].ubound
+ 1 - source
->dim
[n
].lbound
;
108 if (ssize
== sstride
[n
])
116 if (pad
->dim
[0].stride
== 0)
117 pad
->dim
[0].stride
= 1;
118 pdim
= GFC_DESCRIPTOR_RANK (pad
);
120 for (n
= 0; n
< pdim
; n
++)
123 pstride
[n
] = pad
->dim
[n
].stride
;
124 pextent
[n
] = pad
->dim
[n
].ubound
+ 1 - pad
->dim
[n
].lbound
;
127 if (psize
== pstride
[n
])
141 if (rsize
!= 0 && ssize
!= 0 && psize
!= 0)
146 reshape_packed ((char *)ret
->data
, rsize
, (char *)source
->data
,
147 ssize
, pad
? (char *)pad
->data
: NULL
, psize
);
151 src
= sptr
= source
->data
;
152 rstride0
= rstride
[0];
153 sstride0
= sstride
[0];
157 /* Select between the source and pad arrays. */
159 /* Advance to the next element. */
164 /* Advance to the next destination element. */
166 while (rcount
[n
] == rextent
[n
])
168 /* When we get to the end of a dimension, reset it and increment
169 the next dimension. */
171 /* We could precalculate these products, but this is a less
172 frequently used path so proabably not worth it. */
173 rptr
-= rstride
[n
] * rextent
[n
];
177 /* Break out of the loop. */
187 /* Advance to the next source element. */
189 while (scount
[n
] == sextent
[n
])
191 /* When we get to the end of a dimension, reset it and increment
192 the next dimension. */
194 /* We could precalculate these products, but this is a less
195 frequently used path so proabably not worth it. */
196 src
-= sstride
[n
] * sextent
[n
];
202 /* Switch to the pad array. */
205 for (dim
= 0; dim
< pdim
; dim
++)
207 scount
[dim
] = pcount
[dim
];
208 sextent
[dim
] = pextent
[dim
];
209 sstride
[dim
] = pstride
[dim
];
210 sstride0
= sstride
[0];
213 /* We now start again from the beginning of the pad array. */