2 * memcopy.c -- subroutines for memory copy functions.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; either version 2 of the License, or (at your option)
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
12 * Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 * The code is derived from the GNU C Library.
19 * Copyright (C) 1991, 1992, 1993, 1997, 2004 Free Software Foundation, Inc.
22 /* BE VERY CAREFUL IF YOU CHANGE THIS CODE...! */
24 #include <linux/memcopy.h>
27 * _wordcopy_fwd_aligned -- Copy block beginning at SRCP to block beginning
28 * at DSTP with LEN `op_t' words (not LEN bytes!).
29 * Both SRCP and DSTP should be aligned for memory operations on `op_t's.
31 void _wordcopy_fwd_aligned (long int dstp
, long int srcp
, size_t len
)
37 a0
= ((op_t
*) srcp
)[0];
43 a1
= ((op_t
*) srcp
)[0];
49 a0
= ((op_t
*) srcp
)[0];
55 a1
= ((op_t
*) srcp
)[0];
61 a0
= ((op_t
*) srcp
)[0];
67 a1
= ((op_t
*) srcp
)[0];
73 if (OP_T_THRESHOLD
<= 3 * OPSIZ
&& len
== 0)
75 a0
= ((op_t
*) srcp
)[0];
80 a1
= ((op_t
*) srcp
)[0];
84 if (OP_T_THRESHOLD
<= 3 * OPSIZ
&& len
== 0)
86 goto do8
; /* No-op. */
91 a0
= ((op_t
*) srcp
)[0];
92 ((op_t
*) dstp
)[0] = a1
;
94 a1
= ((op_t
*) srcp
)[1];
95 ((op_t
*) dstp
)[1] = a0
;
97 a0
= ((op_t
*) srcp
)[2];
98 ((op_t
*) dstp
)[2] = a1
;
100 a1
= ((op_t
*) srcp
)[3];
101 ((op_t
*) dstp
)[3] = a0
;
103 a0
= ((op_t
*) srcp
)[4];
104 ((op_t
*) dstp
)[4] = a1
;
106 a1
= ((op_t
*) srcp
)[5];
107 ((op_t
*) dstp
)[5] = a0
;
109 a0
= ((op_t
*) srcp
)[6];
110 ((op_t
*) dstp
)[6] = a1
;
112 a1
= ((op_t
*) srcp
)[7];
113 ((op_t
*) dstp
)[7] = a0
;
121 * This is the right position for do0. Please don't move it into
125 ((op_t
*) dstp
)[0] = a1
;
129 * _wordcopy_fwd_dest_aligned -- Copy block beginning at SRCP to block
130 * beginning at DSTP with LEN `op_t' words (not LEN bytes!). DSTP should
131 * be aligned for memory operations on `op_t's, but SRCP must *not* be aligned.
134 void _wordcopy_fwd_dest_aligned (long int dstp
, long int srcp
, size_t len
)
140 * Calculate how to shift a word read at the memory operation aligned
141 * srcp to make it aligned for copy.
143 sh_1
= 8 * (srcp
% OPSIZ
);
144 sh_2
= 8 * OPSIZ
- sh_1
;
147 * Make SRCP aligned by rounding it down to the beginning of the `op_t'
148 * it points in the middle of.
154 a1
= ((op_t
*) srcp
)[0];
155 a2
= ((op_t
*) srcp
)[1];
161 a0
= ((op_t
*) srcp
)[0];
162 a1
= ((op_t
*) srcp
)[1];
168 if (OP_T_THRESHOLD
<= 3 * OPSIZ
&& len
== 0)
170 a3
= ((op_t
*) srcp
)[0];
171 a0
= ((op_t
*) srcp
)[1];
177 a2
= ((op_t
*) srcp
)[0];
178 a3
= ((op_t
*) srcp
)[1];
182 if (OP_T_THRESHOLD
<= 3 * OPSIZ
&& len
== 0)
184 goto do4
; /* No-op. */
189 a0
= ((op_t
*) srcp
)[0];
190 ((op_t
*) dstp
)[0] = MERGE (a2
, sh_1
, a3
, sh_2
);
192 a1
= ((op_t
*) srcp
)[1];
193 ((op_t
*) dstp
)[1] = MERGE (a3
, sh_1
, a0
, sh_2
);
195 a2
= ((op_t
*) srcp
)[2];
196 ((op_t
*) dstp
)[2] = MERGE (a0
, sh_1
, a1
, sh_2
);
198 a3
= ((op_t
*) srcp
)[3];
199 ((op_t
*) dstp
)[3] = MERGE (a1
, sh_1
, a2
, sh_2
);
207 * This is the right position for do0. Please don't move it into
211 ((op_t
*) dstp
)[0] = MERGE (a2
, sh_1
, a3
, sh_2
);
215 * _wordcopy_bwd_aligned -- Copy block finishing right before
216 * SRCP to block finishing right before DSTP with LEN `op_t' words (not LEN
217 * bytes!). Both SRCP and DSTP should be aligned for memory operations
220 void _wordcopy_bwd_aligned (long int dstp
, long int srcp
, size_t len
)
228 a0
= ((op_t
*) srcp
)[1];
234 a1
= ((op_t
*) srcp
)[2];
240 a0
= ((op_t
*) srcp
)[3];
246 a1
= ((op_t
*) srcp
)[4];
252 a0
= ((op_t
*) srcp
)[5];
258 a1
= ((op_t
*) srcp
)[6];
262 if (OP_T_THRESHOLD
<= 3 * OPSIZ
&& len
== 0)
266 a0
= ((op_t
*) srcp
)[7];
271 a1
= ((op_t
*) srcp
)[8];
273 if (OP_T_THRESHOLD
<= 3 * OPSIZ
&& len
== 0)
275 goto do8
; /* No-op. */
280 a0
= ((op_t
*) srcp
)[7];
281 ((op_t
*) dstp
)[7] = a1
;
283 a1
= ((op_t
*) srcp
)[6];
284 ((op_t
*) dstp
)[6] = a0
;
286 a0
= ((op_t
*) srcp
)[5];
287 ((op_t
*) dstp
)[5] = a1
;
289 a1
= ((op_t
*) srcp
)[4];
290 ((op_t
*) dstp
)[4] = a0
;
292 a0
= ((op_t
*) srcp
)[3];
293 ((op_t
*) dstp
)[3] = a1
;
295 a1
= ((op_t
*) srcp
)[2];
296 ((op_t
*) dstp
)[2] = a0
;
298 a0
= ((op_t
*) srcp
)[1];
299 ((op_t
*) dstp
)[1] = a1
;
301 a1
= ((op_t
*) srcp
)[0];
302 ((op_t
*) dstp
)[0] = a0
;
310 * This is the right position for do0. Please don't move it into
314 ((op_t
*) dstp
)[7] = a1
;
318 * _wordcopy_bwd_dest_aligned -- Copy block finishing right before SRCP to
319 * block finishing right before DSTP with LEN `op_t' words (not LEN bytes!).
320 * DSTP should be aligned for memory operations on `op_t', but SRCP must *not*
323 void _wordcopy_bwd_dest_aligned (long int dstp
, long int srcp
, size_t len
)
329 * Calculate how to shift a word read at the memory operation aligned
330 * srcp to make it aligned for copy.
333 sh_1
= 8 * (srcp
% OPSIZ
);
334 sh_2
= 8 * OPSIZ
- sh_1
;
337 * Make srcp aligned by rounding it down to the beginning of the op_t
338 * it points in the middle of.
347 a2
= ((op_t
*) srcp
)[2];
348 a1
= ((op_t
*) srcp
)[1];
354 a3
= ((op_t
*) srcp
)[3];
355 a2
= ((op_t
*) srcp
)[2];
359 if (OP_T_THRESHOLD
<= 3 * OPSIZ
&& len
== 0)
363 a0
= ((op_t
*) srcp
)[4];
364 a3
= ((op_t
*) srcp
)[3];
369 a1
= ((op_t
*) srcp
)[5];
370 a0
= ((op_t
*) srcp
)[4];
372 if (OP_T_THRESHOLD
<= 3 * OPSIZ
&& len
== 0)
374 goto do4
; /* No-op. */
379 a3
= ((op_t
*) srcp
)[3];
380 ((op_t
*) dstp
)[3] = MERGE (a0
, sh_1
, a1
, sh_2
);
382 a2
= ((op_t
*) srcp
)[2];
383 ((op_t
*) dstp
)[2] = MERGE (a3
, sh_1
, a0
, sh_2
);
385 a1
= ((op_t
*) srcp
)[1];
386 ((op_t
*) dstp
)[1] = MERGE (a2
, sh_1
, a3
, sh_2
);
388 a0
= ((op_t
*) srcp
)[0];
389 ((op_t
*) dstp
)[0] = MERGE (a1
, sh_1
, a2
, sh_2
);
397 * This is the right position for do0. Please don't move it into
401 ((op_t
*) dstp
)[3] = MERGE (a0
, sh_1
, a1
, sh_2
);