1 /* Generic 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 static const char zeros
[16] =
29 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
31 /* TODO: make this work for large shifts when
32 sizeof(int) < sizeof (index_type). */
35 __eoshift2 (gfc_array_char
* ret
, const gfc_array_char
* array
,
36 int shift
, const gfc_array_char
* bound
, int which
)
38 /* r.* indicates the return array. */
39 index_type rstride
[GFC_MAX_DIMENSIONS
- 1];
44 /* s.* indicates the source array. */
45 index_type sstride
[GFC_MAX_DIMENSIONS
- 1];
50 /* b.* indicates the bound array. */
51 index_type bstride
[GFC_MAX_DIMENSIONS
- 1];
55 index_type count
[GFC_MAX_DIMENSIONS
- 1];
56 index_type extent
[GFC_MAX_DIMENSIONS
- 1];
62 size
= GFC_DESCRIPTOR_SIZE (ret
);
64 if (ret
->data
== NULL
)
68 ret
->data
= internal_malloc (size
* size0 ((array_t
*)array
));
70 ret
->dtype
= array
->dtype
;
71 for (i
= 0; i
< GFC_DESCRIPTOR_RANK (array
); i
++)
73 ret
->dim
[i
].lbound
= 0;
74 ret
->dim
[i
].ubound
= array
->dim
[i
].ubound
- array
->dim
[i
].lbound
;
77 ret
->dim
[i
].stride
= 1;
79 ret
->dim
[i
].stride
= (ret
->dim
[i
-1].ubound
+ 1) * ret
->dim
[i
-1].stride
;
87 size
= GFC_DESCRIPTOR_SIZE (array
);
89 for (dim
= 0; dim
< GFC_DESCRIPTOR_RANK (array
); dim
++)
93 roffset
= ret
->dim
[dim
].stride
* size
;
96 soffset
= array
->dim
[dim
].stride
* size
;
99 len
= array
->dim
[dim
].ubound
+ 1 - array
->dim
[dim
].lbound
;
104 extent
[n
] = array
->dim
[dim
].ubound
+ 1 - array
->dim
[dim
].lbound
;
105 rstride
[n
] = ret
->dim
[dim
].stride
* size
;
106 sstride
[n
] = array
->dim
[dim
].stride
* size
;
108 bstride
[n
] = bound
->dim
[n
].stride
* size
;
118 if (bound
&& bstride
[0] == 0)
121 dim
= GFC_DESCRIPTOR_RANK (array
);
122 rstride0
= rstride
[0];
123 sstride0
= sstride
[0];
124 bstride0
= bstride
[0];
139 /* Do the shift for this dimension. */
142 src
= &sptr
[shift
* soffset
];
148 dest
= &rptr
[-shift
* roffset
];
150 for (n
= 0; n
< len
; n
++)
152 memcpy (dest
, src
, size
);
168 memcpy (dest
, bptr
, size
);
172 /* Advance to the next section. */
178 while (count
[n
] == extent
[n
])
180 /* When we get to the end of a dimension, reset it and increment
181 the next dimension. */
183 /* We could precalculate these products, but this is a less
184 frequently used path so proabably not worth it. */
185 rptr
-= rstride
[n
] * extent
[n
];
186 sptr
-= sstride
[n
] * extent
[n
];
187 bptr
-= bstride
[n
] * extent
[n
];
191 /* Break out of the loop. */
208 __eoshift2_4 (gfc_array_char
* ret
, const gfc_array_char
* array
,
209 const GFC_INTEGER_4
* pshift
, const gfc_array_char
* bound
,
210 const GFC_INTEGER_4
* pdim
)
212 __eoshift2 (ret
, array
, *pshift
, bound
, pdim
? *pdim
: 1);
217 __eoshift2_8 (gfc_array_char
* ret
, const gfc_array_char
* array
,
218 const GFC_INTEGER_8
* pshift
, const gfc_array_char
* bound
,
219 const GFC_INTEGER_8
* pdim
)
221 __eoshift2 (ret
, array
, *pshift
, bound
, pdim
? *pdim
: 1);