1 /* Helper function for cshift functions.
2 Copyright 2008 Free Software Foundation, Inc.
3 Contributed by Thomas Koenig <tkoenig@gcc.gnu.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. */
31 #include "libgfortran.h"
37 #if defined (HAVE_GFC_INTEGER_8)
40 cshift0_i8 (gfc_array_i8
*ret
, const gfc_array_i8
*array
, ssize_t shift
,
43 /* r.* indicates the return array. */
44 index_type rstride
[GFC_MAX_DIMENSIONS
];
49 /* s.* indicates the source array. */
50 index_type sstride
[GFC_MAX_DIMENSIONS
];
53 const GFC_INTEGER_8
*sptr
;
55 index_type count
[GFC_MAX_DIMENSIONS
];
56 index_type extent
[GFC_MAX_DIMENSIONS
];
68 /* Initialized for avoiding compiler warnings. */
73 for (dim
= 0; dim
< GFC_DESCRIPTOR_RANK (array
); dim
++)
77 roffset
= ret
->dim
[dim
].stride
;
80 soffset
= array
->dim
[dim
].stride
;
83 len
= array
->dim
[dim
].ubound
+ 1 - array
->dim
[dim
].lbound
;
88 extent
[n
] = array
->dim
[dim
].ubound
+ 1 - array
->dim
[dim
].lbound
;
89 rstride
[n
] = ret
->dim
[dim
].stride
;
90 sstride
[n
] = array
->dim
[dim
].stride
;
99 dim
= GFC_DESCRIPTOR_RANK (array
);
100 rstride0
= rstride
[0];
101 sstride0
= sstride
[0];
105 shift
= len
== 0 ? 0 : shift
% (ssize_t
)len
;
111 /* Do the shift for this dimension. */
113 /* If elements are contiguous, perform the operation
114 in two block moves. */
115 if (soffset
== 1 && roffset
== 1)
117 size_t len1
= shift
* sizeof (GFC_INTEGER_8
);
118 size_t len2
= (len
- shift
) * sizeof (GFC_INTEGER_8
);
119 memcpy (rptr
, sptr
+ shift
, len2
);
120 memcpy (rptr
+ (len
- shift
), sptr
, len1
);
124 /* Otherwise, we will have to perform the copy one element at
126 GFC_INTEGER_8
*dest
= rptr
;
127 const GFC_INTEGER_8
*src
= &sptr
[shift
* soffset
];
129 for (n
= 0; n
< len
- shift
; n
++)
135 for (src
= sptr
, n
= 0; n
< shift
; n
++)
143 /* Advance to the next section. */
148 while (count
[n
] == extent
[n
])
150 /* When we get to the end of a dimension, reset it and increment
151 the next dimension. */
153 /* We could precalculate these products, but this is a less
154 frequently used path so probably not worth it. */
155 rptr
-= rstride
[n
] * extent
[n
];
156 sptr
-= sstride
[n
] * extent
[n
];
160 /* Break out of the loop. */