1 /* _memcopy.c -- subroutines for memory copy functions.
2 Copyright (C) 1991-2014 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Torbjorn Granlund (tege@sics.se).
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 /* BE VERY CAREFUL IF YOU CHANGE THIS CODE...! */
25 /* _wordcopy_fwd_aligned -- Copy block beginning at SRCP to
26 block beginning at DSTP with LEN `op_t' words (not LEN bytes!).
27 Both SRCP and DSTP should be aligned for memory operations on `op_t's. */
29 #ifndef WORDCOPY_FWD_ALIGNED
30 # define WORDCOPY_FWD_ALIGNED _wordcopy_fwd_aligned
34 WORDCOPY_FWD_ALIGNED (long int dstp
, long int srcp
, size_t len
)
41 a0
= ((op_t
*) srcp
)[0];
47 a1
= ((op_t
*) srcp
)[0];
53 a0
= ((op_t
*) srcp
)[0];
59 a1
= ((op_t
*) srcp
)[0];
65 a0
= ((op_t
*) srcp
)[0];
71 a1
= ((op_t
*) srcp
)[0];
78 if (OP_T_THRES
<= 3 * OPSIZ
&& len
== 0)
80 a0
= ((op_t
*) srcp
)[0];
85 a1
= ((op_t
*) srcp
)[0];
89 if (OP_T_THRES
<= 3 * OPSIZ
&& len
== 0)
91 goto do8
; /* No-op. */
97 a0
= ((op_t
*) srcp
)[0];
98 ((op_t
*) dstp
)[0] = a1
;
100 a1
= ((op_t
*) srcp
)[1];
101 ((op_t
*) dstp
)[1] = a0
;
103 a0
= ((op_t
*) srcp
)[2];
104 ((op_t
*) dstp
)[2] = a1
;
106 a1
= ((op_t
*) srcp
)[3];
107 ((op_t
*) dstp
)[3] = a0
;
109 a0
= ((op_t
*) srcp
)[4];
110 ((op_t
*) dstp
)[4] = a1
;
112 a1
= ((op_t
*) srcp
)[5];
113 ((op_t
*) dstp
)[5] = a0
;
115 a0
= ((op_t
*) srcp
)[6];
116 ((op_t
*) dstp
)[6] = a1
;
118 a1
= ((op_t
*) srcp
)[7];
119 ((op_t
*) dstp
)[7] = a0
;
127 /* This is the right position for do0. Please don't move
130 ((op_t
*) dstp
)[0] = a1
;
133 /* _wordcopy_fwd_dest_aligned -- Copy block beginning at SRCP to
134 block beginning at DSTP with LEN `op_t' words (not LEN bytes!).
135 DSTP should be aligned for memory operations on `op_t's, but SRCP must
138 #ifndef WORDCOPY_FWD_DEST_ALIGNED
139 # define WORDCOPY_FWD_DEST_ALIGNED _wordcopy_fwd_dest_aligned
143 WORDCOPY_FWD_DEST_ALIGNED (long int dstp
, long int srcp
, size_t len
)
148 /* Calculate how to shift a word read at the memory operation
149 aligned srcp to make it aligned for copy. */
151 sh_1
= 8 * (srcp
% OPSIZ
);
152 sh_2
= 8 * OPSIZ
- sh_1
;
154 /* Make SRCP aligned by rounding it down to the beginning of the `op_t'
155 it points in the middle of. */
161 a1
= ((op_t
*) srcp
)[0];
162 a2
= ((op_t
*) srcp
)[1];
168 a0
= ((op_t
*) srcp
)[0];
169 a1
= ((op_t
*) srcp
)[1];
175 if (OP_T_THRES
<= 3 * OPSIZ
&& len
== 0)
177 a3
= ((op_t
*) srcp
)[0];
178 a0
= ((op_t
*) srcp
)[1];
184 a2
= ((op_t
*) srcp
)[0];
185 a3
= ((op_t
*) srcp
)[1];
189 if (OP_T_THRES
<= 3 * OPSIZ
&& len
== 0)
191 goto do4
; /* No-op. */
197 a0
= ((op_t
*) srcp
)[0];
198 ((op_t
*) dstp
)[0] = MERGE (a2
, sh_1
, a3
, sh_2
);
200 a1
= ((op_t
*) srcp
)[1];
201 ((op_t
*) dstp
)[1] = MERGE (a3
, sh_1
, a0
, sh_2
);
203 a2
= ((op_t
*) srcp
)[2];
204 ((op_t
*) dstp
)[2] = MERGE (a0
, sh_1
, a1
, sh_2
);
206 a3
= ((op_t
*) srcp
)[3];
207 ((op_t
*) dstp
)[3] = MERGE (a1
, sh_1
, a2
, sh_2
);
215 /* This is the right position for do0. Please don't move
218 ((op_t
*) dstp
)[0] = MERGE (a2
, sh_1
, a3
, sh_2
);
221 /* _wordcopy_bwd_aligned -- Copy block finishing right before
222 SRCP to block finishing right before DSTP with LEN `op_t' words
223 (not LEN bytes!). Both SRCP and DSTP should be aligned for memory
224 operations on `op_t's. */
226 #ifndef WORDCOPY_BWD_ALIGNED
227 # define WORDCOPY_BWD_ALIGNED _wordcopy_bwd_aligned
231 WORDCOPY_BWD_ALIGNED (long int dstp
, long int srcp
, size_t len
)
240 a0
= ((op_t
*) srcp
)[1];
246 a1
= ((op_t
*) srcp
)[2];
252 a0
= ((op_t
*) srcp
)[3];
258 a1
= ((op_t
*) srcp
)[4];
264 a0
= ((op_t
*) srcp
)[5];
270 a1
= ((op_t
*) srcp
)[6];
275 if (OP_T_THRES
<= 3 * OPSIZ
&& len
== 0)
279 a0
= ((op_t
*) srcp
)[7];
284 a1
= ((op_t
*) srcp
)[8];
286 if (OP_T_THRES
<= 3 * OPSIZ
&& len
== 0)
288 goto do8
; /* No-op. */
294 a0
= ((op_t
*) srcp
)[7];
295 ((op_t
*) dstp
)[7] = a1
;
297 a1
= ((op_t
*) srcp
)[6];
298 ((op_t
*) dstp
)[6] = a0
;
300 a0
= ((op_t
*) srcp
)[5];
301 ((op_t
*) dstp
)[5] = a1
;
303 a1
= ((op_t
*) srcp
)[4];
304 ((op_t
*) dstp
)[4] = a0
;
306 a0
= ((op_t
*) srcp
)[3];
307 ((op_t
*) dstp
)[3] = a1
;
309 a1
= ((op_t
*) srcp
)[2];
310 ((op_t
*) dstp
)[2] = a0
;
312 a0
= ((op_t
*) srcp
)[1];
313 ((op_t
*) dstp
)[1] = a1
;
315 a1
= ((op_t
*) srcp
)[0];
316 ((op_t
*) dstp
)[0] = a0
;
324 /* This is the right position for do0. Please don't move
327 ((op_t
*) dstp
)[7] = a1
;
330 /* _wordcopy_bwd_dest_aligned -- Copy block finishing right
331 before SRCP to block finishing right before DSTP with LEN `op_t'
332 words (not LEN bytes!). DSTP should be aligned for memory
333 operations on `op_t', but SRCP must *not* be aligned. */
335 #ifndef WORDCOPY_BWD_DEST_ALIGNED
336 # define WORDCOPY_BWD_DEST_ALIGNED _wordcopy_bwd_dest_aligned
340 WORDCOPY_BWD_DEST_ALIGNED (long int dstp
, long int srcp
, size_t len
)
345 /* Calculate how to shift a word read at the memory operation
346 aligned srcp to make it aligned for copy. */
348 sh_1
= 8 * (srcp
% OPSIZ
);
349 sh_2
= 8 * OPSIZ
- sh_1
;
351 /* Make srcp aligned by rounding it down to the beginning of the op_t
352 it points in the middle of. */
361 a2
= ((op_t
*) srcp
)[2];
362 a1
= ((op_t
*) srcp
)[1];
368 a3
= ((op_t
*) srcp
)[3];
369 a2
= ((op_t
*) srcp
)[2];
373 if (OP_T_THRES
<= 3 * OPSIZ
&& len
== 0)
377 a0
= ((op_t
*) srcp
)[4];
378 a3
= ((op_t
*) srcp
)[3];
383 a1
= ((op_t
*) srcp
)[5];
384 a0
= ((op_t
*) srcp
)[4];
386 if (OP_T_THRES
<= 3 * OPSIZ
&& len
== 0)
388 goto do4
; /* No-op. */
394 a3
= ((op_t
*) srcp
)[3];
395 ((op_t
*) dstp
)[3] = MERGE (a0
, sh_1
, a1
, sh_2
);
397 a2
= ((op_t
*) srcp
)[2];
398 ((op_t
*) dstp
)[2] = MERGE (a3
, sh_1
, a0
, sh_2
);
400 a1
= ((op_t
*) srcp
)[1];
401 ((op_t
*) dstp
)[1] = MERGE (a2
, sh_1
, a3
, sh_2
);
403 a0
= ((op_t
*) srcp
)[0];
404 ((op_t
*) dstp
)[0] = MERGE (a1
, sh_1
, a2
, sh_2
);
412 /* This is the right position for do0. Please don't move
415 ((op_t
*) dstp
)[3] = MERGE (a0
, sh_1
, a1
, sh_2
);