1 /* Implementation of the EOSHIFT intrinsic
2 Copyright 2002, 2005 Free Software Foundation, Inc.
3 Contributed by Paul Brook <paul@nowt.org>
5 This file is part of the GNU Fortran 95 runtime library (libgfortran).
7 Libgfortran is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 In addition to the permissions in the GNU General Public License, the
13 Free Software Foundation gives you unlimited permission to link the
14 compiled version of this file into combinations with other programs,
15 and to distribute those combinations without any restriction coming
16 from the use of this file. (The General Public License restrictions
17 do apply in other respects; for example, they cover modification of
18 the file, and distribution when not linked into a combine
21 Libgfortran is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public
27 License along with libgfortran; see the file COPYING. If not,
28 write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29 Boston, MA 02110-1301, USA. */
35 #include "libgfortran.h"
38 eoshift1 (gfc_array_char
*ret
, const gfc_array_char
*array
, const gfc_array_i8
*h
,
39 const char *pbound
, const GFC_INTEGER_8
*pwhich
, index_type size
,
42 /* r.* indicates the return array. */
43 index_type rstride
[GFC_MAX_DIMENSIONS
];
48 /* s.* indicates the source array. */
49 index_type sstride
[GFC_MAX_DIMENSIONS
];
54 /* h.* indicates the shift array. */
55 index_type hstride
[GFC_MAX_DIMENSIONS
];
57 const GFC_INTEGER_8
*hptr
;
59 index_type count
[GFC_MAX_DIMENSIONS
];
60 index_type extent
[GFC_MAX_DIMENSIONS
];
68 /* The compiler cannot figure out that these are set, initialize
69 them to avoid warnings. */
82 if (ret
->data
== NULL
)
86 ret
->data
= internal_malloc_size (size
* size0 ((array_t
*)array
));
88 ret
->dtype
= array
->dtype
;
89 for (i
= 0; i
< GFC_DESCRIPTOR_RANK (array
); i
++)
91 ret
->dim
[i
].lbound
= 0;
92 ret
->dim
[i
].ubound
= array
->dim
[i
].ubound
- array
->dim
[i
].lbound
;
95 ret
->dim
[i
].stride
= 1;
97 ret
->dim
[i
].stride
= (ret
->dim
[i
-1].ubound
+ 1) * ret
->dim
[i
-1].stride
;
102 for (dim
= 0; dim
< GFC_DESCRIPTOR_RANK (array
); dim
++)
106 roffset
= ret
->dim
[dim
].stride
* size
;
109 soffset
= array
->dim
[dim
].stride
* size
;
112 len
= array
->dim
[dim
].ubound
+ 1 - array
->dim
[dim
].lbound
;
117 extent
[n
] = array
->dim
[dim
].ubound
+ 1 - array
->dim
[dim
].lbound
;
118 rstride
[n
] = ret
->dim
[dim
].stride
* size
;
119 sstride
[n
] = array
->dim
[dim
].stride
* size
;
121 hstride
[n
] = h
->dim
[n
].stride
;
132 dim
= GFC_DESCRIPTOR_RANK (array
);
133 rstride0
= rstride
[0];
134 sstride0
= sstride
[0];
135 hstride0
= hstride
[0];
142 /* Do the shift for this dimension. */
144 if (( sh
>= 0 ? sh
: -sh
) > len
)
150 delta
= (sh
>= 0) ? sh
: -sh
;
154 src
= &sptr
[delta
* soffset
];
160 dest
= &rptr
[delta
* roffset
];
162 for (n
= 0; n
< len
- delta
; n
++)
164 memcpy (dest
, src
, size
);
175 memcpy (dest
, pbound
, size
);
181 memset (dest
, filler
, size
);
185 /* Advance to the next section. */
191 while (count
[n
] == extent
[n
])
193 /* When we get to the end of a dimension, reset it and increment
194 the next dimension. */
196 /* We could precalculate these products, but this is a less
197 frequently used path so proabably not worth it. */
198 rptr
-= rstride
[n
] * extent
[n
];
199 sptr
-= sstride
[n
] * extent
[n
];
200 hptr
-= hstride
[n
] * extent
[n
];
204 /* Break out of the loop. */
219 void eoshift1_8 (gfc_array_char
*, const gfc_array_char
*,
220 const gfc_array_i8
*, const char *, const GFC_INTEGER_8
*);
221 export_proto(eoshift1_8
);
224 eoshift1_8 (gfc_array_char
*ret
, const gfc_array_char
*array
,
225 const gfc_array_i8
*h
, const char *pbound
,
226 const GFC_INTEGER_8
*pwhich
)
228 eoshift1 (ret
, array
, h
, pbound
, pwhich
, GFC_DESCRIPTOR_SIZE (array
), 0);
231 void eoshift1_8_char (gfc_array_char
*, GFC_INTEGER_4
,
232 const gfc_array_char
*, const gfc_array_i8
*,
233 const char *, const GFC_INTEGER_8
*,
234 GFC_INTEGER_4
, GFC_INTEGER_4
);
235 export_proto(eoshift1_8_char
);
238 eoshift1_8_char (gfc_array_char
*ret
,
239 GFC_INTEGER_4 ret_length
__attribute__((unused
)),
240 const gfc_array_char
*array
, const gfc_array_i8
*h
,
241 const char *pbound
, const GFC_INTEGER_8
*pwhich
,
242 GFC_INTEGER_4 array_length
,
243 GFC_INTEGER_4 bound_length
244 __attribute__((unused
)))
246 eoshift1 (ret
, array
, h
, pbound
, pwhich
, array_length
, ' ');