summaryrefslogtreecommitdiff
path: root/firmware/target/coldfire/memcpy-coldfire.S
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/coldfire/memcpy-coldfire.S')
-rwxr-xr-xfirmware/target/coldfire/memcpy-coldfire.S680
1 files changed, 680 insertions, 0 deletions
diff --git a/firmware/target/coldfire/memcpy-coldfire.S b/firmware/target/coldfire/memcpy-coldfire.S
new file mode 100755
index 0000000000..523e1f5ed9
--- /dev/null
+++ b/firmware/target/coldfire/memcpy-coldfire.S
@@ -0,0 +1,680 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2004-2005 by Jens Arnold
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "config.h"
20
21 .section .icode,"ax",@progbits
22
23#define FULLSPEED /* use burst writing for word aligned destinations */
24 .align 2
25 .global memcpy
26 .global __memcpy_fwd_entry
27 .type memcpy,@function
28
29/* Copies <length> bytes of data in memory from <source> to <dest>
30 * This version is optimized for speed
31 *
32 * arguments:
33 * (4,%sp) - destination address
34 * (8,%sp) - source address
35 * (12,%sp) - length
36 *
37 * return value:
38 * %d0 - destination address (like ANSI version)
39 *
40 * register usage:
41 * %a0 - current source address
42 * %a1 - current dest address
43 * %a2 - source end address (in line-copy loops)
44 * %d0 - data / scratch
45 * %d1 - source end address (byte and longword copy) / data / scratch
46 * %d2 - data / scratch
47 * %d3..%d7 - data
48 *
49 * For maximum speed this routine reads and writes whole lines using burst
50 * move (movem.l) where possible. For byte aligned destinations (long+1 and
51 * long+3) it writes longwords only. Same goes for word aligned destinations
52 * if FULLSPEED is undefined.
53 */
54memcpy:
55 move.l (4,%sp),%a1 /* Destination */
56 move.l (8,%sp),%a0 /* Source */
57 move.l (12,%sp),%d1 /* Length */
58
59__memcpy_fwd_entry:
60 add.l %a0,%d1 /* %d1 = source end */
61
62 move.l %a0,%d0
63 addq.l #7,%d0
64 and.l #0xFFFFFFFC,%d0 /* %d0 = first source long bound + 4 */
65 cmp.l %d0,%d1 /* at least one aligned longword to copy? */
66 blo.w .bytes2_start /* no, jump directly to trailing byte loop */
67
68 subq.l #4,%d0 /* %d0 = first source long bound */
69 cmp.l %a0,%d0 /* any bytes to copy? */
70 jls .bytes1_end /* no: skip byte loop */
71
72 /* leading byte loop: copies 0..3 bytes */
73.bytes1_loop:
74 move.b (%a0)+,(%a1)+ /* copy byte */
75 cmp.l %a0,%d0 /* runs %a0 up to first long bound */
76 jhi .bytes1_loop
77
78.bytes1_end:
79 moveq.l #31,%d0
80 add.l %a0,%d0
81 and.l #0xFFFFFFF0,%d0 /* %d0 = first source line bound + 16 */
82 cmp.l %d0,%d1 /* at least one aligned line to copy? */
83 blo.w .long_start /* no: jump to longword copy loop */
84
85 lea.l (-28,%sp),%sp /* free up some registers */
86 movem.l %d2-%d7/%a2,(%sp)
87
88 moveq.l #16,%d2
89 sub.l %d2,%d0 /* %d0 = first source line bound */
90 move.l %d1,%a2 /* %a2 = end address */
91 lea.l (-15,%a2),%a2 /* adjust end address for loops doing 16 bytes/ pass */
92 move.l %a1,%d1
93 moveq.l #3,%d2 /* mask */
94 and.l %d2,%d1
95 jmp.l (2,%pc,%d1.l*4) /* switch (dest_addr & 3) */
96 bra.w .lines_do0_start
97 bra.w .lines_do1_start
98 bra.w .lines_do2_start
99 /* bra.w .lines_do3_start implicit */
100
101 /* byte aligned destination (long + 3): use line burst reads in main loop */
102.lines_do3_start:
103 moveq.l #24,%d1 /* shift count for shifting by 3 bytes */
104 cmp.l %a0,%d0 /* any leading longwords? */
105 jhi .lines_do3_head_start /* yes: leading longword copy */
106
107 movem.l (%a0),%d4-%d7 /* load first line */
108 lea.l (16,%a0),%a0
109 move.l %d4,%d2
110 lsr.l %d1,%d2 /* get high byte of first longword */
111 move.b %d2,(%a1)+ /* store byte */
112 jra .lines_do3_entry /* jump into main loop */
113
114.lines_do3_head_start:
115 move.l (%a0)+,%d7 /* load first longword */
116 move.l %d7,%d2
117 lsr.l %d1,%d2 /* get high byte */
118 move.b %d2,(%a1)+ /* store byte */
119 jra .lines_do3_head_entry /* jump into leading longword loop */
120
121.lines_do3_head_loop:
122 move.l %d7,%d6 /* move old longword away */
123 move.l (%a0)+,%d7 /* load new longword */
124 move.l %d7,%d2
125 lsr.l %d1,%d2 /* get high byte */
126 or.l %d2,%d6 /* combine with old lower 3 bytes */
127 move.l %d6,(%a1)+ /* store longword */
128.lines_do3_head_entry:
129 lsl.l #8,%d7 /* shift up lower 3 bytes */
130 cmp.l %a0,%d0 /* runs %a0 up to first line bound */
131 jhi .lines_do3_head_loop
132
133.lines_do3_loop:
134 move.l %d7,%d3 /* move last longword of old line away */
135 movem.l (%a0),%d4-%d7 /* load new line */
136 lea.l (16,%a0),%a0
137 move.l %d4,%d2
138 lsr.l %d1,%d2 /* get high byte of 1st longword */
139 or.l %d2,%d3 /* combine with old lower 3 bytes */
140 move.l %d3,(%a1)+ /* store longword */
141.lines_do3_entry:
142 lsl.l #8,%d4 /* shift up lower 3 bytes */
143 move.l %d5,%d2
144 lsr.l %d1,%d2 /* get high byte of 2nd longword */
145 or.l %d2,%d4 /* combine with 1st lower 3 bytes */
146 move.l %d4,(%a1)+ /* store longword */
147 lsl.l #8,%d5 /* shift up lower 3 bytes */
148 move.l %d6,%d2
149 lsr.l %d1,%d2 /* get high byte of 3rd longword */
150 or.l %d2,%d5 /* combine with 2nd lower 3 bytes */
151 move.l %d5,(%a1)+ /* store longword */
152 lsl.l #8,%d6 /* shift up lower 3 bytes */
153 move.l %d7,%d2
154 lsr.l %d1,%d2 /* get high byte of 4th longword */
155 or.l %d2,%d6 /* combine with 3rd lower 3 bytes */
156 move.l %d6,(%a1)+ /* store longword */
157 lsl.l #8,%d7 /* shift up lower 3 bytes */
158 cmp.l %a0,%a2 /* runs %a0 up to last line bound */
159 jhi .lines_do3_loop
160
161 lea.l (12,%a2),%a2 /* readjust end address for doing longwords */
162 cmp.l %a0,%a2 /* any trailing longwords? */
163 jls .lines_do3_tail_end /* no: just store last lower 3 bytes */
164
165.lines_do3_tail_loop:
166 move.l %d7,%d6 /* move old longword away */
167 move.l (%a0)+,%d7 /* load new longword */
168 move.l %d7,%d2
169 lsr.l %d1,%d2 /* get high byte */
170 or.l %d2,%d6 /* combine with old lower 3 bytes */
171 move.l %d6,(%a1)+ /* store longword */
172 lsl.l #8,%d7 /* shift up lower 3 bytes */
173 cmp.l %a0,%a2 /* runs %a0 up to last long bound */
174 jhi .lines_do3_tail_loop
175
176.lines_do3_tail_end:
177 swap %d7 /* get high word */
178 move.w %d7,(%a1)+ /* store word */
179 lsr.l %d1,%d7 /* get moved-up low byte */
180 move.b %d7,(%a1)+ /* store byte */
181 jra .lines_end
182
183 /* byte aligned destination (long + 1): use line burst reads in main loop */
184.lines_do1_start:
185 moveq.l #24,%d1 /* shift count for shifting by 3 bytes */
186 cmp.l %a0,%d0 /* any leading longwords? */
187 jhi .lines_do1_head_start /* yes: leading longword copy */
188
189 movem.l (%a0),%d4-%d7 /* load first line */
190 lea.l (16,%a0),%a0
191 move.l %d4,%d2 /* first longword, bytes 3210 */
192 lsr.l #8,%d2 /* first longword, bytes .321 */
193 swap %d2 /* first longword, bytes 21.3 */
194 move.b %d2,(%a1)+ /* store byte */
195 swap %d2 /* first longword, bytes .321 */
196 move.w %d2,(%a1)+ /* store word */
197 jra .lines_do1_entry
198
199.lines_do1_head_start:
200 move.l (%a0)+,%d7 /* load first longword */
201 move.l %d7,%d2 /* first longword, bytes 3210 */
202 lsr.l #8,%d2 /* first longword, bytes .321 */
203 swap %d2 /* first longword, bytes 21.3 */
204 move.b %d2,(%a1)+ /* store byte */
205 swap %d2 /* first longword, bytes .321 */
206 move.w %d2,(%a1)+ /* store word */
207 jra .lines_do1_head_entry
208
209.lines_do1_head_loop:
210 move.l %d7,%d6 /* move old longword away */
211 move.l (%a0)+,%d7 /* load new longword */
212 move.l %d7,%d2
213 lsr.l #8,%d2 /* get upper 3 bytes */
214 or.l %d2,%d6 /* combine with old low byte */
215 move.l %d6,(%a1)+ /* store longword */
216.lines_do1_head_entry:
217 lsl.l %d1,%d7 /* shift up low byte */
218 cmp.l %a0,%d0 /* runs %a0 up to first line bound */
219 jhi .lines_do1_head_loop
220
221.lines_do1_loop:
222 move.l %d7,%d3 /* move last longword of old line away */
223 movem.l (%a0),%d4-%d7 /* load new line */
224 lea.l (16,%a0),%a0
225 move.l %d4,%d2
226 lsr.l #8,%d2 /* get upper 3 bytes of 1st longword */
227 or.l %d2,%d3 /* combine with low byte of old longword */
228 move.l %d3,(%a1)+ /* store longword */
229.lines_do1_entry:
230 lsl.l %d1,%d4 /* shift up low byte */
231 move.l %d5,%d2
232 lsr.l #8,%d2 /* get upper 3 bytes of 2nd longword */
233 or.l %d2,%d4 /* combine with low byte of 1st longword */
234 move.l %d4,(%a1)+ /* store longword */
235 lsl.l %d1,%d5 /* shift up low byte */
236 move.l %d6,%d2
237 lsr.l #8,%d2 /* get upper 3 bytes of 3rd longword */
238 or.l %d2,%d5 /* combine with low byte of 2nd longword */
239 move.l %d5,(%a1)+ /* store longword */
240 lsl.l %d1,%d6 /* shift up low byte */
241 move.l %d7,%d2
242 lsr.l #8,%d2 /* get upper 3 bytes of 4th longword */
243 or.l %d2,%d6 /* combine with low byte of 4th longword */
244 move.l %d6,(%a1)+ /* store longword */
245 lsl.l %d1,%d7 /* shift up low byte */
246 cmp.l %a0,%a2 /* runs %a0 up to last line bound */
247 jhi .lines_do1_loop
248
249 lea.l (12,%a2),%a2 /* readjust end address for doing longwords */
250 cmp.l %a0,%a2 /* any trailing longwords? */
251 jls .lines_do1_tail_end /* no: just store last low byte */
252
253.lines_do1_tail_loop:
254 move.l %d7,%d6 /* move old longword away */
255 move.l (%a0)+,%d7 /* load new longword */
256 move.l %d7,%d2
257 lsr.l #8,%d2 /* get upper 3 bytes */
258 or.l %d2,%d6 /* combine with old low byte */
259 move.l %d6,(%a1)+ /* store longword */
260 lsl.l %d1,%d7 /* shift up low byte */
261 cmp.l %a0,%a2 /* runs %a0 up to last long bound */
262 jhi .lines_do1_tail_loop
263
264.lines_do1_tail_end:
265 lsr.l %d1,%d7 /* get shifted-up low byte */
266 move.b %d7,(%a1)+ /* store byte */
267 jra .lines_end
268
269 /* long aligned destination (line + 0/4/8/12): head */
270.lines_do0_head_loop:
271 move.l (%a0)+,(%a1)+ /* copy longword */
272.lines_do0_start:
273 cmp.l %a0,%d0 /* runs %a0 up to first line bound */
274 jhi .lines_do0_head_loop
275
276.lines_do0_head_end:
277 move.l %a1,%d1
278 lsr.l #2,%d1
279 moveq.l #3,%d0 /* mask */
280 and.l %d0,%d1
281 moveq.l #16,%d0 /* address increment for one main loop pass */
282 jmp.l (2,%pc,%d1.l*2) /* switch ((dest_addr >> 2) & 3) */
283 bra.b .lines_lo0_start
284 bra.b .lines_lo4_start
285 bra.b .lines_lo8_start
286 /* bra.b .lines_lo12_start implicit */
287
288 /* long aligned destination (line + 12): use line bursts in the loop */
289.lines_lo12_start:
290 movem.l (%a0),%d4-%d7 /* load first line */
291 add.l %d0,%a0
292 move.l %d4,(%a1)+ /* store 1st longword */
293 cmp.l %a0,%a2 /* any full lines? */
294 jls .lines_lo12_end /* no: skip main loop */
295
296.lines_lo12_loop:
297 move.l %d5,%d1 /* move last 3 longwords of old line away */
298 move.l %d6,%d2
299 move.l %d7,%d3
300 movem.l (%a0),%d4-%d7 /* load new line */
301 add.l %d0,%a0
302 movem.l %d1-%d4,(%a1) /* store line (3 old + 1 new longwords) */
303 add.l %d0,%a1
304 cmp.l %a0,%a2 /* runs %a0 up to last line bound */
305 jhi .lines_lo12_loop
306
307 /* long aligned destination (line + 0/4/8/12): tail */
308.lines_lo12_end:
309 move.l %d5,(%a1)+ /* store 3rd last longword */
310.lines_lo8_end:
311 move.l %d6,(%a1)+ /* store 2nd last longword */
312.lines_lo4_end:
313 move.l %d7,(%a1)+ /* store last longword */
314.lines_lo0_end:
315 lea.l (12,%a2),%a2 /* readjust end address for doing longwords */
316 cmp.l %a0,%a2 /* any trailing longwords? */
317 jls .lines_end /* no: get outta here */
318
319.lines_do0_tail_loop:
320 move.l (%a0)+,(%a1)+ /* copy longword */
321 cmp.l %a0,%a2 /* runs %a0 up to last long bound */
322 jhi .lines_do0_tail_loop
323
324 jra .lines_end
325
326 /* line aligned destination: use line bursts in the loop */
327.lines_lo0_start:
328.lines_lo0_loop:
329 movem.l (%a0),%d4-%d7 /* load line */
330 add.l %d0,%a0
331 movem.l %d4-%d7,(%a1) /* store line */
332 add.l %d0,%a1
333 cmp.l %a0,%a2 /* runs %a0 up to last line bound */
334 jhi .lines_lo0_loop
335
336 jra .lines_lo0_end /* handle trailing longwords */
337
338 /* long aligned destination (line + 4): use line bursts in the loop */
339.lines_lo4_start:
340 movem.l (%a0),%d4-%d7 /* load first line */
341 add.l %d0,%a0
342 move.l %d4,(%a1)+ /* store 1st longword */
343 move.l %d5,(%a1)+ /* store 2nd longword */
344 move.l %d6,(%a1)+ /* store 3rd longword */
345 cmp.l %a0,%a2 /* any full lines? */
346 jls .lines_lo4_end /* no: skip main loop */
347
348.lines_lo4_loop:
349 move.l %d7,%d3 /* move last longword of old line away */
350 movem.l (%a0),%d4-%d7 /* load new line */
351 add.l %d0,%a0
352 movem.l %d3-%d6,(%a1) /* store line (1 old + 3 new longwords) */
353 add.l %d0,%a1
354 cmp.l %a0,%a2 /* runs %a0 up to last line bound */
355 jhi .lines_lo4_loop
356
357 jra .lines_lo4_end /* handle trailing longwords */
358
359 /* long aligned destination (line + 8): use line bursts in the loop */
360.lines_lo8_start:
361 movem.l (%a0),%d4-%d7 /* load first line */
362 add.l %d0,%a0
363 move.l %d4,(%a1)+ /* store 1st longword */
364 move.l %d5,(%a1)+ /* store 2nd longword */
365 cmp.l %a0,%a2
366 jls .lines_lo8_end
367
368.lines_lo8_loop:
369 move.l %d6,%d2 /* move last 2 longwords of old line away */
370 move.l %d7,%d3
371 movem.l (%a0),%d4-%d7 /* load new line */
372 add.l %d0,%a0
373 movem.l %d2-%d5,(%a1) /* store line (2 old + 2 new longwords) */
374 add.l %d0,%a1
375 cmp.l %a0,%a2 /* runs %a0 up to last line bound */
376 jhi .lines_lo8_loop
377
378 jra .lines_lo8_end /* handle trailing longwords */
379
380#ifdef FULLSPEED
381
382 /* word aligned destination (line + 2/6/10/14): head */
383.lines_do2_start:
384 cmp.l %a0,%d0 /* any leading longwords? */
385 jls .lines_do2_selector /* no: jump to mainloop selector */
386
387 move.l (%a0)+,%d7 /* load first longword */
388 swap %d7 /* swap words */
389 move.w %d7,(%a1)+ /* store high word */
390 cmp.l %a0,%d0 /* any more longword? */
391 jls .lines_do2_head_end /* no: skip head loop */
392
393.lines_do2_head_loop:
394 move.l %d7,%d6 /* move old longword away */
395 move.l (%a0)+,%d7 /* load new longword */
396 swap %d7 /* swap words */
397 move.w %d7,%d6 /* combine high word with old low word */
398 move.l %d6,(%a1)+ /* store longword */
399 cmp.l %a0,%d0 /* runs %a0 up to first line bound */
400 jhi .lines_do2_head_loop
401
402.lines_do2_head_end:
403 swap %d7 /* undo swap */
404 move.w %d7,(%a1)+ /* store word */
405
406.lines_do2_selector:
407 move.l %a1,%d1
408 lsr.l #2,%d1
409 moveq.l #3,%d0 /* mask */
410 and.l %d0,%d1
411 moveq.l #16,%d0 /* address increment for one main loop pass */
412 jmp.l (2,%pc,%d1.l*4) /* switch ((dest_addr >> 2) & 3) */
413 bra.w .lines_lo2_start
414 bra.w .lines_lo6_start
415 bra.w .lines_lo10_start
416 /* bra.w .lines_lo14_start implicit */
417
418 /* word aligned destination (line + 14): use line bursts in the loop */
419.lines_lo14_start:
420 movem.l (%a0),%d4-%d7 /* load first line */
421 add.l %d0,%a0
422 swap %d4 /* swap words of 1st long */
423 move.w %d4,(%a1)+ /* store word */
424 jra .lines_lo14_entry /* jump into main loop */
425
426.lines_lo14_loop:
427 move.l %d4,%d0 /* move old line away */
428 move.l %d5,%d1
429 move.l %d6,%d2
430 move.l %d7,%d3
431 movem.l (%a0),%d4-%d7 /* load new line */
432 lea.l (16,%a0),%a0
433 swap %d4 /* swap words of 1st long */
434 move.w %d4,%d3 /* combine 1st high word with old low word */
435 movem.l %d0-%d3,(%a1) /* store line */
436 lea.l (16,%a1),%a1
437.lines_lo14_entry:
438 swap %d5 /* swap words of 2nd long */
439 move.w %d5,%d4 /* combine 2nd high word with 1st low word */
440 swap %d6 /* swap words of 3rd long */
441 move.w %d6,%d5 /* combine 3rd high word with 2nd low word */
442 swap %d7 /* swap words of 4th long */
443 move.w %d7,%d6 /* combine 4th high word with 3rd low word */
444 cmp.l %a0,%a2 /* runs %a0 up to last line bound */
445 jhi .lines_lo14_loop
446
447 /* word aligned destination (line + 2/6/10/14): tail */
448.lines_lo14_end:
449 move.l %d4,(%a1)+ /* store third last longword */
450.lines_lo10_end:
451 move.l %d5,(%a1)+ /* store second last longword */
452.lines_lo6_end:
453 move.l %d6,(%a1)+ /* store last longword */
454.lines_lo2_end:
455 lea.l (12,%a2),%a2 /* readjust end address for doing longwords */
456 cmp.l %a0,%a2 /* any trailing longwords? */
457 jls .lines_do2_tail_end /* no: skip tail loop */
458
459.lines_do2_tail_loop:
460 move.l %d7,%d6 /* move old longword away */
461 move.l (%a0)+,%d7 /* load new longword */
462 swap %d7 /* swap words */
463 move.w %d7,%d6 /* combine high word with old low word */
464 move.l %d6,(%a1)+ /* store longword */
465 cmp.l %a0,%a2 /* runs %a0 up to last long bound */
466 jhi .lines_do2_tail_loop
467
468.lines_do2_tail_end:
469 swap %d7 /* undo swap */
470 move.w %d7,(%a1)+ /* store last word */
471 jra .lines_end
472
473 /* word aligned destination (line + 2): use line bursts in the loop */
474.lines_lo2_start:
475 movem.l (%a0),%d4-%d7 /* load first line */
476 add.l %d0,%a0
477 swap %d4 /* swap words of 1st long */
478 move.w %d4,(%a1)+ /* store high word */
479 swap %d5 /* swap words of 2nd long */
480 move.w %d5,%d4 /* combine 2nd high word with 1st low word */
481 swap %d6 /* swap words of 3rd long */
482 move.w %d6,%d5 /* combine 3nd high word with 2nd low word */
483 swap %d7 /* swap words of 4th long */
484 move.w %d7,%d6 /* combine 4th high word with 3rd low word */
485 move.l %d4,(%a1)+ /* store 1st longword */
486 move.l %d5,(%a1)+ /* store 2nd longword */
487 move.l %d6,(%a1)+ /* store 3rd longword */
488 cmp.l %a0,%a2 /* any full lines? */
489 jls .lines_lo2_end /* no: skip main loop */
490
491.lines_lo2_loop:
492 move.l %d7,%d3 /* move last longword of old line away */
493 movem.l (%a0),%d4-%d7 /* load line */
494 add.l %d0,%a0
495 swap %d4 /* swap words of 1st long */
496 move.w %d4,%d3 /* combine 1st high word with old low word */
497 swap %d5 /* swap words of 2nd long */
498 move.w %d5,%d4 /* combine 2nd high word with 1st low word */
499 swap %d6 /* swap words of 3rd long */
500 move.w %d6,%d5 /* combine 3rd high word with 2nd low word */
501 swap %d7 /* swap words of 4th long */
502 move.w %d7,%d6 /* combine 4th high word with 3rd low word */
503 movem.l %d3-%d6,(%a1) /* store line */
504 add.l %d0,%a1
505 cmp.l %a0,%a2 /* runs %a0 up to last line bound */
506 jhi .lines_lo2_loop
507
508 jra .lines_lo2_end /* handle trailing longwords */
509
510 /* word aligned destination (line + 6): use line bursts in the loop */
511.lines_lo6_start:
512 movem.l (%a0),%d4-%d7 /* load first line */
513 add.l %d0,%a0
514 swap %d4 /* swap words of 1st long */
515 move.w %d4,(%a1)+ /* store high word */
516 swap %d5 /* swap words of 2nd long */
517 move.w %d5,%d4 /* combine 2nd high word with 1st low word */
518 swap %d6 /* swap words of 3rd long */
519 move.w %d6,%d5 /* combine 3rd high word with 2nd low word */
520 move.l %d4,(%a1)+ /* store 1st longword */
521 move.l %d5,(%a1)+ /* store 2nd longword */
522 jra .lines_lo6_entry /* jump into main loop */
523
524.lines_lo6_loop:
525 move.l %d6,%d2 /* move last 2 longwords of old line away */
526 move.l %d7,%d3
527 movem.l (%a0),%d4-%d7 /* load line */
528 add.l %d0,%a0
529 swap %d4 /* swap words of 1st long */
530 move.w %d4,%d3 /* combine 1st high word with old low word */
531 swap %d5 /* swap words of 2nd long */
532 move.w %d5,%d4 /* combine 2nd high word with 1st low word */
533 swap %d6 /* swap words of 3rd long */
534 move.w %d6,%d5 /* combine 3rd high word with 2nd low word */
535 movem.l %d2-%d5,(%a1) /* store line */
536 add.l %d0,%a1
537.lines_lo6_entry:
538 swap %d7 /* swap words of 4th long */
539 move.w %d7,%d6 /* combine 4th high word with 3rd low word */
540 cmp.l %a0,%a2 /* runs %a0 up to last line bound */
541 jhi .lines_lo6_loop
542
543 jra .lines_lo6_end /* handle trailing longwords */
544
545 /* word aligned destination (line + 10): use line bursts in the loop */
546.lines_lo10_start:
547 movem.l (%a0),%d4-%d7 /* load first line */
548 add.l %d0,%a0
549 swap %d4 /* swap words of 1st long */
550 move.w %d4,(%a1)+ /* store high word */
551 swap %d5 /* swap words of 2nd long */
552 move.w %d5,%d4 /* combine 2nd high word with 1st low word */
553 move.l %d4,(%a1)+ /* store 1st longword */
554 jra .lines_lo10_entry /* jump into main loop */
555
556.lines_lo10_loop:
557 move.l %d5,%d1 /* move last 3 longwords of old line away */
558 move.l %d6,%d2
559 move.l %d7,%d3
560 movem.l (%a0),%d4-%d7 /* load line */
561 add.l %d0,%a0
562 swap %d4 /* swap words of 1st long */
563 move.w %d4,%d3 /* combine 1st high word with old low word */
564 swap %d5 /* swap words of 2nd long */
565 move.w %d5,%d4 /* combine 2nd high word with 1st low word */
566 movem.l %d1-%d4,(%a1) /* store line */
567 add.l %d0,%a1
568.lines_lo10_entry:
569 swap %d6 /* swap words of 3rd long */
570 move.w %d6,%d5 /* combine 3rd high word with 2nd low word */
571 swap %d7 /* swap words of 4th long */
572 move.w %d7,%d6 /* combine 4th high word with 3rd low word */
573 cmp.l %a0,%a2 /* runs %a0 up to last line bound */
574 jhi .lines_lo10_loop
575
576 jra .lines_lo10_end /* handle trailing longwords */
577
578#else /* !FULLSPEED */
579
580 /* word aligned destination (long + 2): use line burst reads in the loop */
581.lines_do2_start:
582 cmp.l %a0,%d0 /* any leading longwords? */
583 jhi .lines_do2_head_start /* yes: leading longword copy */
584
585 movem.l (%a0),%d4-%d7 /* load first line */
586 lea.l (16,%a0),%a0
587 swap %d4 /* swap words of 1st long */
588 move.w %d4,(%a1)+ /* store high word */
589 jra .lines_do2_entry /* jump into main loop */
590
591.lines_do2_head_start:
592 move.l (%a0)+,%d7 /* load first longword */
593 swap %d7 /* swap words */
594 move.w %d7,(%a1)+ /* store high word */
595 cmp.l %a0,%d0 /* any full longword? */
596 jls .lines_do2_loop /* no: skip head loop */
597
598.lines_do2_head_loop:
599 move.l %d7,%d6 /* move old longword away */
600 move.l (%a0)+,%d7 /* load new longword */
601 swap %d7 /* swap words */
602 move.w %d7,%d6 /* combine high word with old low word */
603 move.l %d6,(%a1)+ /* store longword */
604 cmp.l %a0,%d0 /* runs %a0 up to first line bound */
605 jhi .lines_do2_head_loop
606
607.lines_do2_loop:
608 move.l %d7,%d3 /* move last longword of old line away */
609 movem.l (%a0),%d4-%d7 /* load line */
610 lea.l (16,%a0),%a0
611 swap %d4 /* swap words of 1st long */
612 move.w %d4,%d3 /* combine 1st high word with old low word */
613 move.l %d3,(%a1)+ /* store 1st longword */
614.lines_do2_entry:
615 swap %d5 /* swap words of 2nd long */
616 move.w %d5,%d4 /* combine 2nd high word with 1st low word */
617 move.l %d4,(%a1)+ /* store 2nd longword */
618 swap %d6 /* swap words of 3rd long */
619 move.w %d6,%d5 /* combine 3rd high word with 2nd low word */
620 move.l %d5,(%a1)+ /* store 3rd longword */
621 swap %d7 /* swap words of 4th long */
622 move.w %d7,%d6 /* combine 4th high word with 3rd low word */
623 move.l %d6,(%a1)+ /* store 4th longword */
624 cmp.l %a0,%a2 /* runs %a0 up to last line bound */
625 jhi .lines_do2_loop
626
627.lines_do2_end:
628 lea.l (12,%a2),%a2 /* readjust end address for doing longwords */
629 cmp.l %a0,%a2 /* any trailing longwords? */
630 jls .lines_do2_tail_end /* no: skip tail loop */
631
632.lines_do2_tail_loop:
633 move.l %d7,%d6 /* move old longword away */
634 move.l (%a0)+,%d7 /* load new longword */
635 swap %d7 /* swap words */
636 move.w %d7,%d6 /* combine high word with old low word */
637 move.l %d6,(%a1)+ /* store longword */
638 cmp.l %a0,%a2 /* runs %a0 up to last long bound */
639 jhi .lines_do2_tail_loop
640
641.lines_do2_tail_end:
642 swap %d7 /* undo swap */
643 move.w %d7,(%a1)+ /* store last word */
644 /* jra .lines_end implicit */
645
646#endif /* !FULLSPEED */
647
648.lines_end:
649 addq.l #3,%a2 /* readjust end address */
650 move.l %a2,%d1 /* end address in %d1 again */
651 movem.l (%sp),%d2-%d7/%a2 /* restore registers */
652 lea.l (28,%sp),%sp
653 jra .bytes2_start /* jump to trailing byte loop */
654
655.long_start:
656 subq.l #3,%d1 /* adjust end address for doing 4 bytes/ pass */
657
658 /* longword copy loop - no lines */
659.long_loop:
660 move.l (%a0)+,(%a1)+ /* copy longword (write can be unaligned) */
661 cmp.l %a0,%d1 /* runs %a0 up to last long bound */
662 jhi .long_loop
663
664 addq.l #3,%d1 /* readjust end address */
665 cmp.l %a0,%d1 /* any bytes left? */
666 jls .bytes2_end /* no: skip trailing byte loop */
667
668 /* trailing byte loop */
669.bytes2_loop:
670 move.b (%a0)+,(%a1)+ /* copy byte */
671.bytes2_start:
672 cmp.l %a0,%d1 /* runs %a0 up to end address */
673 jhi .bytes2_loop
674
675.bytes2_end:
676 move.l (4,%sp),%d0 /* return destination */
677 rts
678
679.end:
680 .size memcpy,.end-memcpy