1 /* _memcopy.c -- subroutines for memory copy functions.
2 Copyright (C) 1991-2016 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Torbjorn Granlund (tege@sics.se).
5 Updated for POWER6 by Steven Munroe (sjmunroe@us.ibm.com).
7 The GNU C Library 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 The GNU C Library 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 GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, see
19 <http://www.gnu.org/licenses/>. */
21 /* BE VERY CAREFUL IF YOU CHANGE THIS CODE...! */
26 /* _wordcopy_fwd_aligned -- Copy block beginning at SRCP to
27 block beginning at DSTP with LEN `op_t' words (not LEN bytes!).
28 Both SRCP and DSTP should be aligned for memory operations on `op_t's. */
30 #ifndef WORDCOPY_FWD_ALIGNED
31 # define WORDCOPY_FWD_ALIGNED _wordcopy_fwd_aligned
35 WORDCOPY_FWD_ALIGNED (long int dstp
, long int srcp
, size_t len
)
41 ((op_t
*) dstp
)[0] = ((op_t
*) srcp
)[0];
52 a0
= ((op_t
*) srcp
)[0];
53 a1
= ((op_t
*) srcp
)[1];
54 ((op_t
*) dstp
)[0] = a0
;
55 ((op_t
*) dstp
)[1] = a1
;
64 /* _wordcopy_fwd_dest_aligned -- Copy block beginning at SRCP to
65 block beginning at DSTP with LEN `op_t' words (not LEN bytes!).
66 DSTP should be aligned for memory operations on `op_t's, but SRCP must
69 #define fwd_align_merge(align) \
72 a1 = ((op_t *) srcp)[1]; \
73 a2 = ((op_t *) srcp)[2]; \
74 ((op_t *) dstp)[0] = MERGE (a0, align*8, a1, (__WORDSIZE-align*8)); \
75 ((op_t *) dstp)[1] = MERGE (a1, align*8, a2, (__WORDSIZE-align*8)); \
83 #ifndef WORDCOPY_FWD_DEST_ALIGNED
84 # define WORDCOPY_FWD_DEST_ALIGNED _wordcopy_fwd_dest_aligned
88 WORDCOPY_FWD_DEST_ALIGNED (long int dstp
, long int srcp
, size_t len
)
94 /* Calculate how to shift a word read at the memory operation
95 aligned srcp to make it aligned for copy. */
98 sh_1
= 8 * (srcp
% OPSIZ
);
99 sh_2
= 8 * OPSIZ
- sh_1
;
101 /* Make SRCP aligned by rounding it down to the beginning of the `op_t'
102 it points in the middle of. */
104 a0
= ((op_t
*) srcp
)[0];
108 a1
= ((op_t
*) srcp
)[1];
109 ((op_t
*) dstp
)[0] = MERGE (a0
, sh_1
, a1
, sh_2
);
120 fwd_align_merge (align
);
124 /* _wordcopy_bwd_aligned -- Copy block finishing right before
125 SRCP to block finishing right before DSTP with LEN `op_t' words
126 (not LEN bytes!). Both SRCP and DSTP should be aligned for memory
127 operations on `op_t's. */
129 #ifndef WORDCOPY_BWD_ALIGNED
130 # define WORDCOPY_BWD_ALIGNED _wordcopy_bwd_aligned
134 WORDCOPY_BWD_ALIGNED (long int dstp
, long int srcp
, size_t len
)
142 ((op_t
*) dstp
)[0] = ((op_t
*) srcp
)[0];
154 a1
= ((op_t
*) srcp
)[1];
155 a0
= ((op_t
*) srcp
)[0];
156 ((op_t
*) dstp
)[1] = a1
;
157 ((op_t
*) dstp
)[0] = a0
;
164 #define bwd_align_merge(align) \
169 a1 = ((op_t *) srcp)[1]; \
170 a0 = ((op_t *) srcp)[0]; \
171 ((op_t *) dstp)[1] = MERGE (a1, align*8, a2, (__WORDSIZE-align*8)); \
172 ((op_t *) dstp)[0] = MERGE (a0, align*8, a1, (__WORDSIZE-align*8)); \
178 /* _wordcopy_bwd_dest_aligned -- Copy block finishing right
179 before SRCP to block finishing right before DSTP with LEN `op_t'
180 words (not LEN bytes!). DSTP should be aligned for memory
181 operations on `op_t', but SRCP must *not* be aligned. */
183 #ifndef WORDCOPY_BWD_DEST_ALIGNED
184 # define WORDCOPY_BWD_DEST_ALIGNED _wordcopy_bwd_dest_aligned
188 WORDCOPY_BWD_DEST_ALIGNED (long int dstp
, long int srcp
, size_t len
)
194 /* Calculate how to shift a word read at the memory operation
195 aligned srcp to make it aligned for copy. */
197 align
= srcp
% OPSIZ
;
198 sh_1
= 8 * (srcp
% OPSIZ
);
199 sh_2
= 8 * OPSIZ
- sh_1
;
201 /* Make srcp aligned by rounding it down to the beginning of the op_t
202 it points in the middle of. */
204 a2
= ((op_t
*) srcp
)[0];
210 a1
= ((op_t
*) srcp
)[0];
211 ((op_t
*) dstp
)[0] = MERGE (a1
, sh_1
, a2
, sh_2
);
220 bwd_align_merge (align
);