1 /* _memcopy.c -- subroutines for memory copy functions.
2 Copyright (C) 1991-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 /* BE VERY CAREFUL IF YOU CHANGE THIS CODE...! */
24 /* _wordcopy_fwd_aligned -- Copy block beginning at SRCP to
25 block beginning at DSTP with LEN `op_t' words (not LEN bytes!).
26 Both SRCP and DSTP should be aligned for memory operations on `op_t's. */
28 #ifndef WORDCOPY_FWD_ALIGNED
29 # define WORDCOPY_FWD_ALIGNED _wordcopy_fwd_aligned
33 WORDCOPY_FWD_ALIGNED (long int dstp
, long int srcp
, size_t len
)
40 a0
= ((op_t
*) srcp
)[0];
46 a1
= ((op_t
*) srcp
)[0];
52 a0
= ((op_t
*) srcp
)[0];
58 a1
= ((op_t
*) srcp
)[0];
64 a0
= ((op_t
*) srcp
)[0];
70 a1
= ((op_t
*) srcp
)[0];
77 if (OP_T_THRES
<= 3 * OPSIZ
&& len
== 0)
79 a0
= ((op_t
*) srcp
)[0];
84 a1
= ((op_t
*) srcp
)[0];
88 if (OP_T_THRES
<= 3 * OPSIZ
&& len
== 0)
90 goto do8
; /* No-op. */
96 a0
= ((op_t
*) srcp
)[0];
97 ((op_t
*) dstp
)[0] = a1
;
99 a1
= ((op_t
*) srcp
)[1];
100 ((op_t
*) dstp
)[1] = a0
;
102 a0
= ((op_t
*) srcp
)[2];
103 ((op_t
*) dstp
)[2] = a1
;
105 a1
= ((op_t
*) srcp
)[3];
106 ((op_t
*) dstp
)[3] = a0
;
108 a0
= ((op_t
*) srcp
)[4];
109 ((op_t
*) dstp
)[4] = a1
;
111 a1
= ((op_t
*) srcp
)[5];
112 ((op_t
*) dstp
)[5] = a0
;
114 a0
= ((op_t
*) srcp
)[6];
115 ((op_t
*) dstp
)[6] = a1
;
117 a1
= ((op_t
*) srcp
)[7];
118 ((op_t
*) dstp
)[7] = a0
;
126 /* This is the right position for do0. Please don't move
129 ((op_t
*) dstp
)[0] = a1
;
132 /* _wordcopy_fwd_dest_aligned -- Copy block beginning at SRCP to
133 block beginning at DSTP with LEN `op_t' words (not LEN bytes!).
134 DSTP should be aligned for memory operations on `op_t's, but SRCP must
137 #ifndef WORDCOPY_FWD_DEST_ALIGNED
138 # define WORDCOPY_FWD_DEST_ALIGNED _wordcopy_fwd_dest_aligned
142 WORDCOPY_FWD_DEST_ALIGNED (long int dstp
, long int srcp
, size_t len
)
147 /* Calculate how to shift a word read at the memory operation
148 aligned srcp to make it aligned for copy. */
150 sh_1
= 8 * (srcp
% OPSIZ
);
151 sh_2
= 8 * OPSIZ
- sh_1
;
153 /* Make SRCP aligned by rounding it down to the beginning of the `op_t'
154 it points in the middle of. */
160 a1
= ((op_t
*) srcp
)[0];
161 a2
= ((op_t
*) srcp
)[1];
167 a0
= ((op_t
*) srcp
)[0];
168 a1
= ((op_t
*) srcp
)[1];
174 if (OP_T_THRES
<= 3 * OPSIZ
&& len
== 0)
176 a3
= ((op_t
*) srcp
)[0];
177 a0
= ((op_t
*) srcp
)[1];
183 a2
= ((op_t
*) srcp
)[0];
184 a3
= ((op_t
*) srcp
)[1];
188 if (OP_T_THRES
<= 3 * OPSIZ
&& len
== 0)
190 goto do4
; /* No-op. */
196 a0
= ((op_t
*) srcp
)[0];
197 ((op_t
*) dstp
)[0] = MERGE (a2
, sh_1
, a3
, sh_2
);
199 a1
= ((op_t
*) srcp
)[1];
200 ((op_t
*) dstp
)[1] = MERGE (a3
, sh_1
, a0
, sh_2
);
202 a2
= ((op_t
*) srcp
)[2];
203 ((op_t
*) dstp
)[2] = MERGE (a0
, sh_1
, a1
, sh_2
);
205 a3
= ((op_t
*) srcp
)[3];
206 ((op_t
*) dstp
)[3] = MERGE (a1
, sh_1
, a2
, sh_2
);
214 /* This is the right position for do0. Please don't move
217 ((op_t
*) dstp
)[0] = MERGE (a2
, sh_1
, a3
, sh_2
);
220 /* _wordcopy_bwd_aligned -- Copy block finishing right before
221 SRCP to block finishing right before DSTP with LEN `op_t' words
222 (not LEN bytes!). Both SRCP and DSTP should be aligned for memory
223 operations on `op_t's. */
225 #ifndef WORDCOPY_BWD_ALIGNED
226 # define WORDCOPY_BWD_ALIGNED _wordcopy_bwd_aligned
230 WORDCOPY_BWD_ALIGNED (long int dstp
, long int srcp
, size_t len
)
239 a0
= ((op_t
*) srcp
)[1];
245 a1
= ((op_t
*) srcp
)[2];
251 a0
= ((op_t
*) srcp
)[3];
257 a1
= ((op_t
*) srcp
)[4];
263 a0
= ((op_t
*) srcp
)[5];
269 a1
= ((op_t
*) srcp
)[6];
274 if (OP_T_THRES
<= 3 * OPSIZ
&& len
== 0)
278 a0
= ((op_t
*) srcp
)[7];
283 a1
= ((op_t
*) srcp
)[8];
285 if (OP_T_THRES
<= 3 * OPSIZ
&& len
== 0)
287 goto do8
; /* No-op. */
293 a0
= ((op_t
*) srcp
)[7];
294 ((op_t
*) dstp
)[7] = a1
;
296 a1
= ((op_t
*) srcp
)[6];
297 ((op_t
*) dstp
)[6] = a0
;
299 a0
= ((op_t
*) srcp
)[5];
300 ((op_t
*) dstp
)[5] = a1
;
302 a1
= ((op_t
*) srcp
)[4];
303 ((op_t
*) dstp
)[4] = a0
;
305 a0
= ((op_t
*) srcp
)[3];
306 ((op_t
*) dstp
)[3] = a1
;
308 a1
= ((op_t
*) srcp
)[2];
309 ((op_t
*) dstp
)[2] = a0
;
311 a0
= ((op_t
*) srcp
)[1];
312 ((op_t
*) dstp
)[1] = a1
;
314 a1
= ((op_t
*) srcp
)[0];
315 ((op_t
*) dstp
)[0] = a0
;
323 /* This is the right position for do0. Please don't move
326 ((op_t
*) dstp
)[7] = a1
;
329 /* _wordcopy_bwd_dest_aligned -- Copy block finishing right
330 before SRCP to block finishing right before DSTP with LEN `op_t'
331 words (not LEN bytes!). DSTP should be aligned for memory
332 operations on `op_t', but SRCP must *not* be aligned. */
334 #ifndef WORDCOPY_BWD_DEST_ALIGNED
335 # define WORDCOPY_BWD_DEST_ALIGNED _wordcopy_bwd_dest_aligned
339 WORDCOPY_BWD_DEST_ALIGNED (long int dstp
, long int srcp
, size_t len
)
344 /* Calculate how to shift a word read at the memory operation
345 aligned srcp to make it aligned for copy. */
347 sh_1
= 8 * (srcp
% OPSIZ
);
348 sh_2
= 8 * OPSIZ
- sh_1
;
350 /* Make srcp aligned by rounding it down to the beginning of the op_t
351 it points in the middle of. */
360 a2
= ((op_t
*) srcp
)[2];
361 a1
= ((op_t
*) srcp
)[1];
367 a3
= ((op_t
*) srcp
)[3];
368 a2
= ((op_t
*) srcp
)[2];
372 if (OP_T_THRES
<= 3 * OPSIZ
&& len
== 0)
376 a0
= ((op_t
*) srcp
)[4];
377 a3
= ((op_t
*) srcp
)[3];
382 a1
= ((op_t
*) srcp
)[5];
383 a0
= ((op_t
*) srcp
)[4];
385 if (OP_T_THRES
<= 3 * OPSIZ
&& len
== 0)
387 goto do4
; /* No-op. */
393 a3
= ((op_t
*) srcp
)[3];
394 ((op_t
*) dstp
)[3] = MERGE (a0
, sh_1
, a1
, sh_2
);
396 a2
= ((op_t
*) srcp
)[2];
397 ((op_t
*) dstp
)[2] = MERGE (a3
, sh_1
, a0
, sh_2
);
399 a1
= ((op_t
*) srcp
)[1];
400 ((op_t
*) dstp
)[1] = MERGE (a2
, sh_1
, a3
, sh_2
);
402 a0
= ((op_t
*) srcp
)[0];
403 ((op_t
*) dstp
)[0] = MERGE (a1
, sh_1
, a2
, sh_2
);
411 /* This is the right position for do0. Please don't move
414 ((op_t
*) dstp
)[3] = MERGE (a0
, sh_1
, a1
, sh_2
);