diff options
Diffstat (limited to 'firmware/target')
-rwxr-xr-x | firmware/target/arm/memset-arm.S | 96 | ||||
-rwxr-xr-x | firmware/target/coldfire/memcpy-coldfire.S | 680 | ||||
-rwxr-xr-x | firmware/target/coldfire/memmove-coldfire.S | 668 | ||||
-rwxr-xr-x | firmware/target/coldfire/memset-coldfire.S | 150 | ||||
-rwxr-xr-x | firmware/target/coldfire/memset16-coldfire.S | 144 | ||||
-rwxr-xr-x | firmware/target/sh/memcpy-sh.S | 217 | ||||
-rwxr-xr-x | firmware/target/sh/memmove-sh.S | 220 | ||||
-rwxr-xr-x | firmware/target/sh/memset-sh.S | 107 | ||||
-rwxr-xr-x | firmware/target/sh/strlen-sh.S | 94 |
9 files changed, 2376 insertions, 0 deletions
diff --git a/firmware/target/arm/memset-arm.S b/firmware/target/arm/memset-arm.S new file mode 100755 index 0000000000..b3faafcb37 --- /dev/null +++ b/firmware/target/arm/memset-arm.S | |||
@@ -0,0 +1,96 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2004 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 | .align 2 | ||
24 | |||
25 | /* The following code is based on code found in Linux kernel version 2.6.15.3 | ||
26 | * linux/arch/arm/lib/memset.S | ||
27 | * | ||
28 | * Copyright (C) 1995-2000 Russell King | ||
29 | */ | ||
30 | |||
31 | /* This code will align a pointer for memset, if needed */ | ||
32 | 1: cmp r2, #4 @ 1 do we have enough | ||
33 | blt 5f @ 1 bytes to align with? | ||
34 | cmp r3, #2 @ 1 | ||
35 | strgtb r1, [r0, #-1]! @ 1 | ||
36 | strgeb r1, [r0, #-1]! @ 1 | ||
37 | strb r1, [r0, #-1]! @ 1 | ||
38 | sub r2, r2, r3 @ 1 r2 = r2 - r3 | ||
39 | b 2f | ||
40 | |||
41 | .global memset | ||
42 | .type memset,%function | ||
43 | memset: | ||
44 | add r0, r0, r2 @ we'll write backwards in memory | ||
45 | ands r3, r0, #3 @ 1 unaligned? | ||
46 | bne 1b @ 1 | ||
47 | 2: | ||
48 | /* | ||
49 | * we know that the pointer in r0 is aligned to a word boundary. | ||
50 | */ | ||
51 | orr r1, r1, r1, lsl #8 | ||
52 | orr r1, r1, r1, lsl #16 | ||
53 | mov r3, r1 | ||
54 | cmp r2, #16 | ||
55 | blt 5f | ||
56 | /* | ||
57 | * We need an extra register for this loop - save the return address and | ||
58 | * use the LR | ||
59 | */ | ||
60 | str lr, [sp, #-4]! | ||
61 | mov ip, r1 | ||
62 | mov lr, r1 | ||
63 | |||
64 | 3: subs r2, r2, #64 | ||
65 | stmgedb r0!, {r1, r3, ip, lr} @ 64 bytes at a time. | ||
66 | stmgedb r0!, {r1, r3, ip, lr} | ||
67 | stmgedb r0!, {r1, r3, ip, lr} | ||
68 | stmgedb r0!, {r1, r3, ip, lr} | ||
69 | bgt 3b | ||
70 | ldmeqfd sp!, {pc} @ Now <64 bytes to go. | ||
71 | /* | ||
72 | * No need to correct the count; we're only testing bits from now on | ||
73 | */ | ||
74 | tst r2, #32 | ||
75 | stmnedb r0!, {r1, r3, ip, lr} | ||
76 | stmnedb r0!, {r1, r3, ip, lr} | ||
77 | tst r2, #16 | ||
78 | stmnedb r0!, {r1, r3, ip, lr} | ||
79 | ldr lr, [sp], #4 | ||
80 | |||
81 | 5: tst r2, #8 | ||
82 | stmnedb r0!, {r1, r3} | ||
83 | tst r2, #4 | ||
84 | strne r1, [r0, #-4]! | ||
85 | /* | ||
86 | * When we get here, we've got less than 4 bytes to zero. We | ||
87 | * may have an unaligned pointer as well. | ||
88 | */ | ||
89 | 6: tst r2, #2 | ||
90 | strneb r1, [r0, #-1]! | ||
91 | strneb r1, [r0, #-1]! | ||
92 | tst r2, #1 | ||
93 | strneb r1, [r0, #-1]! | ||
94 | mov pc, lr | ||
95 | end: | ||
96 | .size memset,.end-memset | ||
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 | */ | ||
54 | memcpy: | ||
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 | ||
diff --git a/firmware/target/coldfire/memmove-coldfire.S b/firmware/target/coldfire/memmove-coldfire.S new file mode 100755 index 0000000000..bdd2e2e206 --- /dev/null +++ b/firmware/target/coldfire/memmove-coldfire.S | |||
@@ -0,0 +1,668 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2006 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 memmove | ||
26 | .type memmove,@function | ||
27 | |||
28 | /* Moves <length> bytes of data in memory from <source> to <dest> | ||
29 | * Regions may overlap. | ||
30 | * This version is optimized for speed, and needs the corresponding memcpy | ||
31 | * implementation for the forward copy branch. | ||
32 | * | ||
33 | * arguments: | ||
34 | * (4,%sp) - destination address | ||
35 | * (8,%sp) - source address | ||
36 | * (12,%sp) - length | ||
37 | * | ||
38 | * return value: | ||
39 | * %d0 - destination address (like ANSI version) | ||
40 | * | ||
41 | * register usage: | ||
42 | * %a0 - current source address | ||
43 | * %a1 - current dest address | ||
44 | * %a2 - source start address (in line-copy loops) | ||
45 | * %d0 - source start address (byte and longword copy) / data / scratch | ||
46 | * %d1 - data / scratch | ||
47 | * %d2 - data / scratch | ||
48 | * %d3..%d7 - data | ||
49 | * | ||
50 | * For maximum speed this routine reads and writes whole lines using burst | ||
51 | * move (movem.l) where possible. For byte aligned destinations (long-1 and | ||
52 | * long-3) it writes longwords only. Same goes for word aligned destinations | ||
53 | * if FULLSPEED is undefined. | ||
54 | */ | ||
55 | memmove: | ||
56 | move.l (4,%sp),%a1 /* Destination */ | ||
57 | move.l (8,%sp),%a0 /* Source */ | ||
58 | move.l (12,%sp),%d1 /* Length */ | ||
59 | |||
60 | cmp.l %a0,%a1 | ||
61 | bhi.b .backward /* dest > src -> backward copy */ | ||
62 | jmp __memcpy_fwd_entry | ||
63 | |||
64 | .backward: | ||
65 | move.l %a0,%d0 /* %d0 = source start */ | ||
66 | add.l %d1,%a0 /* %a0 = source end */ | ||
67 | add.l %d1,%a1 /* %a1 = destination end */ | ||
68 | |||
69 | move.l %a0,%d1 | ||
70 | and.l #0xFFFFFFFC,%d1 /* %d1 = last source long bound */ | ||
71 | subq.l #4,%d1 | ||
72 | cmp.l %d0,%d1 /* at least one aligned longword to copy? */ | ||
73 | blo.w .bytes2r_start | ||
74 | |||
75 | addq.l #4,%d1 /* %d1 = last source long bound */ | ||
76 | cmp.l %d1,%a0 /* any bytes to copy */ | ||
77 | jls .bytes1r_end /* no: skip byte loop */ | ||
78 | |||
79 | /* leading byte loop: copies 0..3 bytes */ | ||
80 | .bytes1r_loop: | ||
81 | move.b -(%a0),-(%a1) /* copy byte */ | ||
82 | cmp.l %d1,%a0 /* runs %a0 down to last long bound */ | ||
83 | jhi .bytes1r_loop | ||
84 | |||
85 | .bytes1r_end: | ||
86 | moveq.l #-16,%d1 | ||
87 | add.l %a0,%d1 | ||
88 | and.l #0xFFFFFFF0,%d1 /* %d1 = last source line bound - 16 */ | ||
89 | cmp.l %d0,%d1 /* at least one aligned line to copy? */ | ||
90 | blo.w .longr_start /* no: jump to longword copy loop */ | ||
91 | |||
92 | lea.l (-28,%sp),%sp /* free up some registers */ | ||
93 | movem.l %d2-%d7/%a2,(%sp) | ||
94 | |||
95 | moveq.l #16,%d2 | ||
96 | add.l %d2,%d1 /* %d1 = last source line bound */ | ||
97 | move.l %d0,%a2 /* %a2 = start address */ | ||
98 | lea.l (15,%a2),%a2 /* adjust start address for loops doing 16 bytes/pass */ | ||
99 | move.l %a1,%d0 | ||
100 | moveq.l #3,%d2 /* mask */ | ||
101 | and.l %d2,%d0 | ||
102 | jmp.l (2,%pc,%d0.l*4) /* switch (dest_addr & 3) */ | ||
103 | bra.w .lines_do0r_start | ||
104 | bra.w .lines_do1r_start | ||
105 | bra.w .lines_do2r_start | ||
106 | /* bra.w .lines_do3r_start implicit */ | ||
107 | |||
108 | /* byte aligned destination (long - 1): use line burst reads in main loop */ | ||
109 | .lines_do3r_start: | ||
110 | moveq.l #24,%d0 /* shift count for shifting by 3 bytes */ | ||
111 | cmp.l %d1,%a0 /* any leading longwords? */ | ||
112 | jhi .lines_do3r_head_start /* yes: leading longword copy */ | ||
113 | |||
114 | lea.l (-16,%a0),%a0 | ||
115 | movem.l (%a0),%d3-%d6 /* load initial line */ | ||
116 | move.l %d6,%d2 /* last longword, bytes 3210 */ | ||
117 | move.b %d2,-(%a1) /* store byte */ | ||
118 | lsr.l #8,%d2 /* last longword, bytes .321 */ | ||
119 | move.w %d2,-(%a1) /* store word */ | ||
120 | jra .lines_do3r_entry | ||
121 | |||
122 | .lines_do3r_head_start: | ||
123 | move.l -(%a0),%d3 /* load initial longword */ | ||
124 | move.l %d3,%d2 /* bytes 3210 */ | ||
125 | move.b %d2,-(%a1) /* store byte */ | ||
126 | lsr.l #8,%d2 /* bytes .321 */ | ||
127 | move.w %d2,-(%a1) /* store word */ | ||
128 | jra .lines_do3r_head_entry | ||
129 | |||
130 | .lines_do3r_head_loop: | ||
131 | move.l %d3,%d4 /* move old longword away */ | ||
132 | move.l -(%a0),%d3 /* load new longword */ | ||
133 | move.l %d3,%d2 | ||
134 | lsl.l #8,%d2 /* get bytes 210. */ | ||
135 | or.l %d2,%d4 /* combine with old high byte */ | ||
136 | move.l %d4,-(%a1) /* store longword */ | ||
137 | .lines_do3r_head_entry: | ||
138 | lsr.l %d0,%d3 /* shift down high byte */ | ||
139 | cmp.l %d1,%a0 /* run %a0 down to last line bound */ | ||
140 | jhi .lines_do3r_head_loop | ||
141 | |||
142 | .lines_do3r_loop: | ||
143 | move.l %d3,%d7 /* move first longword of last line away */ | ||
144 | lea.l (-16,%a0),%a0 | ||
145 | movem.l (%a0),%d3-%d6 /* load new line */ | ||
146 | move.l %d6,%d2 | ||
147 | lsl.l #8,%d2 /* get bytes 210. of 4th longword */ | ||
148 | or.l %d2,%d7 /* combine with high byte of old longword */ | ||
149 | move.l %d7,-(%a1) /* store longword */ | ||
150 | .lines_do3r_entry: | ||
151 | lsr.l %d0,%d6 /* shift down high byte */ | ||
152 | move.l %d5,%d2 | ||
153 | lsl.l #8,%d2 /* get bytes 210. of 3rd longword */ | ||
154 | or.l %d2,%d6 /* combine with high byte of 4th longword */ | ||
155 | move.l %d6,-(%a1) /* store longword */ | ||
156 | lsr.l %d0,%d5 /* shift down high byte */ | ||
157 | move.l %d4,%d2 | ||
158 | lsl.l #8,%d2 /* get bytes 210. of 2nd longword */ | ||
159 | or.l %d2,%d5 /* combine with high byte or 3rd longword */ | ||
160 | move.l %d5,-(%a1) /* store longword */ | ||
161 | lsr.l %d0,%d4 /* shift down high byte */ | ||
162 | move.l %d3,%d2 | ||
163 | lsl.l #8,%d2 /* get bytes 210. of 1st longword */ | ||
164 | or.l %d2,%d4 /* combine with high byte of 2nd longword */ | ||
165 | move.l %d4,-(%a1) /* store longword */ | ||
166 | lsr.l %d0,%d3 /* shift down high byte */ | ||
167 | cmp.l %a2,%a0 /* run %a0 down to first line bound */ | ||
168 | jhi .lines_do3r_loop | ||
169 | |||
170 | lea.l (-12,%a2),%a2 /* readjust start address for doing longwords */ | ||
171 | cmp.l %a2,%a0 /* any trailing longwords? */ | ||
172 | jls .lines_do3r_tail_end /* no: just store last high byte */ | ||
173 | |||
174 | .lines_do3r_tail_loop: | ||
175 | move.l %d3,%d4 /* move old longword away */ | ||
176 | move.l -(%a0),%d3 /* load new longword */ | ||
177 | move.l %d3,%d2 | ||
178 | lsl.l #8,%d2 /* get bytes 210. */ | ||
179 | or.l %d2,%d4 /* combine with old high byte */ | ||
180 | move.l %d4,-(%a1) /* store longword */ | ||
181 | lsr.l %d0,%d3 /* shift down high byte */ | ||
182 | cmp.l %a2,%a0 /* run %a0 down to first long bound */ | ||
183 | jhi .lines_do3r_tail_loop | ||
184 | |||
185 | .lines_do3r_tail_end: | ||
186 | move.b %d3,-(%a1) /* store shifted-down high byte */ | ||
187 | jra .linesr_end | ||
188 | |||
189 | /* byte aligned destination (long - 3): use line burst reads in main loop */ | ||
190 | .lines_do1r_start: | ||
191 | moveq.l #24,%d0 /* shift count for shifting by 3 bytes */ | ||
192 | cmp.l %d1,%a0 /* any leading longwords? */ | ||
193 | jhi .lines_do1r_head_start /* yes: leading longword copy */ | ||
194 | |||
195 | lea.l (-16,%a0),%a0 | ||
196 | movem.l (%a0),%d3-%d6 /* load initial line */ | ||
197 | move.b %d6,-(%a1) /* store low byte of last longword */ | ||
198 | jra .lines_do1r_entry | ||
199 | |||
200 | .lines_do1r_head_start: | ||
201 | move.l -(%a0),%d3 /* load initial longword */ | ||
202 | move.b %d3,-(%a1) /* store low byte */ | ||
203 | jra .lines_do1r_head_entry | ||
204 | |||
205 | .lines_do1r_head_loop: | ||
206 | move.l %d3,%d4 /* move old longword away */ | ||
207 | move.l -(%a0),%d3 /* load new longword */ | ||
208 | move.l %d3,%d2 | ||
209 | lsl.l %d0,%d2 /* get low byte */ | ||
210 | or.l %d2,%d4 /* combine with old bytes .321 */ | ||
211 | move.l %d4,-(%a1) /* store longword */ | ||
212 | .lines_do1r_head_entry: | ||
213 | lsr.l #8,%d3 /* get bytes .321 */ | ||
214 | cmp.l %d1,%a0 /* run %a0 down to last line bound */ | ||
215 | jhi .lines_do1r_head_loop | ||
216 | |||
217 | .lines_do1r_loop: | ||
218 | move.l %d3,%d7 /* move first longword of old line away */ | ||
219 | lea.l (-16,%a0),%a0 | ||
220 | movem.l (%a0),%d3-%d6 /* load new line */ | ||
221 | move.l %d6,%d2 | ||
222 | lsl.l %d0,%d2 /* get low byte of 4th longword */ | ||
223 | or.l %d2,%d7 /* combine with bytes .321 of old longword */ | ||
224 | move.l %d7,-(%a1) /* store longword */ | ||
225 | .lines_do1r_entry: | ||
226 | lsr.l #8,%d6 /* get bytes .321 */ | ||
227 | move.l %d5,%d2 | ||
228 | lsl.l %d0,%d2 /* get low byte of 3rd longword */ | ||
229 | or.l %d2,%d6 /* combine with bytes .321 of 4th longword */ | ||
230 | move.l %d6,-(%a1) /* store longword */ | ||
231 | lsr.l #8,%d5 /* get bytes .321 */ | ||
232 | move.l %d4,%d2 | ||
233 | lsl.l %d0,%d2 /* get low byte of 2nd longword */ | ||
234 | or.l %d2,%d5 /* combine with bytes .321 of 3rd longword */ | ||
235 | move.l %d5,-(%a1) /* store longword */ | ||
236 | lsr.l #8,%d4 /* get bytes .321 */ | ||
237 | move.l %d3,%d2 | ||
238 | lsl.l %d0,%d2 /* get low byte of 1st longword */ | ||
239 | or.l %d2,%d4 /* combine with bytes .321 of 2nd longword */ | ||
240 | move.l %d4,-(%a1) /* store longword */ | ||
241 | lsr.l #8,%d3 /* get bytes .321 */ | ||
242 | cmp.l %a2,%a0 /* run %a0 down to first line bound */ | ||
243 | jhi .lines_do1r_loop | ||
244 | |||
245 | lea.l (-12,%a2),%a2 /* readjust start address for doing longwords */ | ||
246 | cmp.l %a2,%a0 /* any trailing longwords? */ | ||
247 | jls .lines_do1r_tail_end /* no: just store last high byte */ | ||
248 | |||
249 | .lines_do1r_tail_loop: | ||
250 | move.l %d3,%d4 /* move old longword away */ | ||
251 | move.l -(%a0),%d3 /* load new longword */ | ||
252 | move.l %d3,%d2 | ||
253 | lsl.l %d0,%d2 /* get low byte */ | ||
254 | or.l %d2,%d4 /* combine with old bytes .321 */ | ||
255 | move.l %d4,-(%a1) /* store longword */ | ||
256 | lsr.l #8,%d3 /* get bytes .321 */ | ||
257 | cmp.l %a2,%a0 /* run %a0 down to first long bound */ | ||
258 | jhi .lines_do1r_tail_loop | ||
259 | |||
260 | .lines_do1r_tail_end: | ||
261 | move.w %d3,-(%a1) /* store word 21 */ | ||
262 | swap %d3 | ||
263 | move.b %d3,-(%a1) /* store byte 3 */ | ||
264 | jra .linesr_end | ||
265 | |||
266 | /* long aligned destination (line - 0/4/8/12): head */ | ||
267 | .lines_do0r_head_loop: | ||
268 | move.l -(%a0),-(%a1) /* copy longword */ | ||
269 | .lines_do0r_start: | ||
270 | cmp.l %d1,%a0 /* run %a0 down to last line bound */ | ||
271 | jhi .lines_do0r_head_loop | ||
272 | |||
273 | .lines_do0r_head_end: | ||
274 | move.l %a1,%d1 | ||
275 | lsr.l #2,%d1 | ||
276 | moveq.l #3,%d0 /* mask */ | ||
277 | and.l %d0,%d1 | ||
278 | moveq.l #16,%d0 /* address decrement for one main loop pass */ | ||
279 | jmp.l (2,%pc,%d1.l*2) /* switch ((dest_addr >> 2) & 3) */ | ||
280 | bra.b .lines_lo0r_start | ||
281 | bra.b .lines_lo4r_start | ||
282 | bra.b .lines_lo8r_start | ||
283 | /* bra.b .lines_lo12r_start implicit */ | ||
284 | |||
285 | /* long aligned destination (line - 4): use line bursts in the loop */ | ||
286 | .lines_lo12r_start: | ||
287 | sub.l %d0,%a0 | ||
288 | movem.l (%a0),%d1-%d4 /* load initial line */ | ||
289 | move.l %d4,-(%a1) /* store 4th longword */ | ||
290 | move.l %d3,-(%a1) /* store 3rd longword */ | ||
291 | move.l %d2,-(%a1) /* store 2nd longword */ | ||
292 | cmp.l %a2,%a0 /* any full lines? */ | ||
293 | jls .lines_lo12r_end /* no: skip main loop */ | ||
294 | |||
295 | .lines_lo12r_loop: | ||
296 | move.l %d1,%d5 /* move first longword of old line away */ | ||
297 | sub.l %d0,%a0 | ||
298 | movem.l (%a0),%d1-%d4 /* load new line */ | ||
299 | sub.l %d0,%a1 | ||
300 | movem.l %d2-%d5,(%a1) /* store line (1 old + 3 new longwords */ | ||
301 | cmp.l %a2,%a0 /* run %a0 down to first line bound */ | ||
302 | jhi .lines_lo12r_loop | ||
303 | |||
304 | jra .lines_lo12r_end /* handle trailing longwords */ | ||
305 | |||
306 | /* line aligned destination: use line bursts in the loop */ | ||
307 | .lines_lo0r_start: | ||
308 | .lines_lo0r_loop: | ||
309 | sub.l %d0,%a0 | ||
310 | movem.l (%a0),%d1-%d4 /* load line */ | ||
311 | sub.l %d0,%a1 | ||
312 | movem.l %d1-%d4,(%a1) /* store line */ | ||
313 | cmp.l %a2,%a0 /* run %a0 down to first line bound */ | ||
314 | jhi .lines_lo0r_loop | ||
315 | |||
316 | jra .lines_lo0r_end /* handle trailing longwords */ | ||
317 | |||
318 | /* long aligned destination (line - 8): use line bursts in the loop */ | ||
319 | .lines_lo8r_start: | ||
320 | sub.l %d0,%a0 | ||
321 | movem.l (%a0),%d1-%d4 /* load initial line */ | ||
322 | move.l %d4,-(%a1) /* store 4th longword */ | ||
323 | move.l %d3,-(%a1) /* store 3rd longword */ | ||
324 | cmp.l %a2,%a0 /* any full lines? */ | ||
325 | jls .lines_lo8r_end /* no: skip main loop */ | ||
326 | |||
327 | .lines_lo8r_loop: | ||
328 | move.l %d2,%d6 /* move first 2 longwords of old line away */ | ||
329 | move.l %d1,%d5 | ||
330 | sub.l %d0,%a0 | ||
331 | movem.l (%a0),%d1-%d4 /* load new line */ | ||
332 | sub.l %d0,%a1 | ||
333 | movem.l %d3-%d6,(%a1) /* store line (2 old + 2 new longwords */ | ||
334 | cmp.l %a2,%a0 /* run %a0 down to first line bound */ | ||
335 | jhi .lines_lo8r_loop | ||
336 | |||
337 | jra .lines_lo8r_end /* handle trailing longwords */ | ||
338 | |||
339 | /* long aligned destination (line - 12): use line bursts in the loop */ | ||
340 | .lines_lo4r_start: | ||
341 | sub.l %d0,%a0 | ||
342 | movem.l (%a0),%d1-%d4 /* load initial line */ | ||
343 | move.l %d4,-(%a1) /* store 4th longword */ | ||
344 | cmp.l %a2,%a0 /* any full lines? */ | ||
345 | jls .lines_lo4r_end /* no: skip main loop */ | ||
346 | |||
347 | .lines_lo4r_loop: | ||
348 | move.l %d3,%d7 /* move first 3 longwords of old line away */ | ||
349 | move.l %d2,%d6 | ||
350 | move.l %d1,%d5 | ||
351 | sub.l %d0,%a0 | ||
352 | movem.l (%a0),%d1-%d4 /* load new line */ | ||
353 | sub.l %d0,%a1 | ||
354 | movem.l %d4-%d7,(%a1) /* store line (3 old + 1 new longwords */ | ||
355 | cmp.l %a2,%a0 /* run %a0 down to first line bound */ | ||
356 | jhi .lines_lo4r_loop | ||
357 | |||
358 | /* long aligned destination (line - 0/4/8/12): tail */ | ||
359 | .lines_lo4r_end: | ||
360 | move.l %d3,-(%a1) /* store 3rd last longword */ | ||
361 | .lines_lo8r_end: | ||
362 | move.l %d2,-(%a1) /* store 2nd last longword */ | ||
363 | .lines_lo12r_end: | ||
364 | move.l %d1,-(%a1) /* store last longword */ | ||
365 | .lines_lo0r_end: | ||
366 | lea.l (-12,%a2),%a2 /* readjust end address for doing longwords */ | ||
367 | cmp.l %a2,%a0 /* any trailing longwords? */ | ||
368 | jls .linesr_end /* no: get outta here */ | ||
369 | |||
370 | .lines_do0r_tail_loop: | ||
371 | move.l -(%a0),-(%a1) /* copy longword */ | ||
372 | cmp.l %a2,%a0 /* run %a0 down to first long bound */ | ||
373 | jhi .lines_do0r_tail_loop | ||
374 | |||
375 | jra .linesr_end | ||
376 | |||
377 | #ifdef FULLSPEED | ||
378 | /* word aligned destination (line - 2/6/10/14): head */ | ||
379 | .lines_do2r_start: | ||
380 | cmp.l %d1,%a0 /* any leading longwords? */ | ||
381 | jls .lines_do2r_selector /* no: jump to mainloop selector */ | ||
382 | |||
383 | move.l -(%a0),%d3 /* load initial longword */ | ||
384 | move.w %d3,-(%a1) /* store low word */ | ||
385 | cmp.l %d1,%a0 /* any more longwords? */ | ||
386 | jls .lines_do2r_head_end /* no: skip head loop */ | ||
387 | |||
388 | .lines_do2r_head_loop: | ||
389 | move.l %d3,%d4 /* move old longword away */ | ||
390 | move.l -(%a0),%d3 /* load new longword */ | ||
391 | move.w %d3,%d4 /* combine low word with old high word */ | ||
392 | swap %d4 /* swap words */ | ||
393 | move.l %d4,-(%a1) /* store longword */ | ||
394 | cmp.l %d1,%a0 /* run %a0 down to last line bound */ | ||
395 | jhi .lines_do2r_head_loop | ||
396 | |||
397 | .lines_do2r_head_end: | ||
398 | swap %d3 /* get high word */ | ||
399 | move.w %d3,-(%a1) /* and store it */ | ||
400 | |||
401 | .lines_do2r_selector: | ||
402 | move.l %a1,%d1 | ||
403 | lsr.l #2,%d1 | ||
404 | moveq.l #3,%d0 /* mask */ | ||
405 | and.l %d0,%d1 | ||
406 | moveq.l #16,%d7 /* address decrement for one main loop pass */ | ||
407 | jmp.l (2,%pc,%d1.l*4) /* switch ((dest_addr >> 2) & 3) */ | ||
408 | bra.w .lines_lo2r_start | ||
409 | bra.w .lines_lo6r_start | ||
410 | bra.w .lines_lo10r_start | ||
411 | /* bra.w .lines_lo14r_start implicit */ | ||
412 | |||
413 | /* word aligned destination (line - 2): use line bursts in the loop */ | ||
414 | .lines_lo14r_start: | ||
415 | sub.l %d7,%a0 | ||
416 | movem.l (%a0),%d0-%d3 /* load initial line */ | ||
417 | move.w %d3,-(%a1) /* store last low word */ | ||
418 | move.w %d2,%d3 /* combine 3rd low word with 4th high word */ | ||
419 | swap %d3 /* swap words of 3rd long */ | ||
420 | move.w %d1,%d2 /* combine 2nd low word with 3rd high word */ | ||
421 | swap %d2 /* swap words of 2nd long */ | ||
422 | move.w %d0,%d1 /* combine 1st low word with 2nd high word */ | ||
423 | swap %d1 /* swap words of 1st long */ | ||
424 | move.l %d3,-(%a1) /* store 3rd longword */ | ||
425 | move.l %d2,-(%a1) /* store 2nd longword */ | ||
426 | move.l %d1,-(%a1) /* store 1st longword */ | ||
427 | cmp.l %a2,%a0 /* any full lines? */ | ||
428 | jls .lines_lo14r_end /* no: skip main loop */ | ||
429 | |||
430 | .lines_lo14r_loop: | ||
431 | move.l %d0,%d4 /* move first longword of old line away */ | ||
432 | sub.l %d7,%a0 | ||
433 | movem.l (%a0),%d0-%d3 /* load line */ | ||
434 | move.w %d3,%d4 /* combine 4th low word with old high word */ | ||
435 | swap %d4 /* swap words of 4th long */ | ||
436 | move.w %d2,%d3 /* combine 3rd low word with 4th high word */ | ||
437 | swap %d3 /* swap words of 3rd long */ | ||
438 | move.w %d1,%d2 /* combine 2nd low word with 3rd high word */ | ||
439 | swap %d2 /* swap words of 2nd long */ | ||
440 | move.w %d0,%d1 /* combine 1st low word with 2nd high word */ | ||
441 | swap %d1 /* swap words of 1st long */ | ||
442 | sub.l %d7,%a1 | ||
443 | movem.l %d1-%d4,(%a1) /* store line */ | ||
444 | cmp.l %a2,%a0 /* run %a0 down to first line bound */ | ||
445 | jhi .lines_lo14r_loop | ||
446 | |||
447 | jra .lines_lo14r_end /* handle trailing longwords */ | ||
448 | |||
449 | /* word aligned destination (line - 6): use line bursts in the loop */ | ||
450 | .lines_lo10r_start: | ||
451 | sub.l %d7,%a0 | ||
452 | movem.l (%a0),%d0-%d3 /* load initial line */ | ||
453 | move.w %d3,-(%a1) /* store last low word */ | ||
454 | move.w %d2,%d3 /* combine 3rd low word with 4th high word */ | ||
455 | swap %d3 /* swap words of 3rd long */ | ||
456 | move.w %d1,%d2 /* combine 2nd low word with 3rd high word */ | ||
457 | swap %d2 /* swap words of 2nd long */ | ||
458 | move.l %d3,-(%a1) /* store 3rd longword */ | ||
459 | move.l %d2,-(%a1) /* store 2nd longword */ | ||
460 | jra .lines_lo10r_entry /* jump into main loop */ | ||
461 | |||
462 | .lines_lo10r_loop: | ||
463 | move.l %d0,%d4 /* move first 2 longwords of old line away */ | ||
464 | move.l %d1,%d5 | ||
465 | sub.l %d7,%a0 | ||
466 | movem.l (%a0),%d0-%d3 /* load line */ | ||
467 | move.w %d3,%d4 /* combine 4th low word with old high word */ | ||
468 | swap %d4 /* swap words of 4th long */ | ||
469 | move.w %d2,%d3 /* combine 3rd low word with 4th high word */ | ||
470 | swap %d3 /* swap words of 3rd long */ | ||
471 | move.w %d1,%d2 /* combine 2nd low word with 3rd high word */ | ||
472 | swap %d2 /* swap words of 2nd long */ | ||
473 | sub.l %d7,%a1 | ||
474 | movem.l %d2-%d5,(%a1) /* store line */ | ||
475 | .lines_lo10r_entry: | ||
476 | move.w %d0,%d1 /* combine 1st low word with 2nd high word */ | ||
477 | swap %d1 /* swap words of 1st long */ | ||
478 | cmp.l %a2,%a0 /* run %a0 down to first line bound */ | ||
479 | jhi .lines_lo10r_loop | ||
480 | |||
481 | jra .lines_lo10r_end /* handle trailing longwords */ | ||
482 | |||
483 | /* word aligned destination (line - 10): use line bursts in the loop */ | ||
484 | .lines_lo6r_start: | ||
485 | sub.l %d7,%a0 | ||
486 | movem.l (%a0),%d0-%d3 /* load initial line */ | ||
487 | move.w %d3,-(%a1) /* store last low word */ | ||
488 | move.w %d2,%d3 /* combine 3rd low word with 4th high word */ | ||
489 | swap %d3 /* swap words of 3rd long */ | ||
490 | move.l %d3,-(%a1) /* store 3rd longword */ | ||
491 | jra .lines_lo6r_entry /* jump into main loop */ | ||
492 | |||
493 | .lines_lo6r_loop: | ||
494 | move.l %d0,%d4 /* move first 3 longwords of old line away */ | ||
495 | move.l %d1,%d5 | ||
496 | move.l %d2,%d6 | ||
497 | sub.l %d7,%a0 | ||
498 | movem.l (%a0),%d0-%d3 /* load line */ | ||
499 | move.w %d3,%d4 /* combine 4th low word with old high word */ | ||
500 | swap %d4 /* swap words of 4th long */ | ||
501 | move.w %d2,%d3 /* combine 3rd low word with 4th high word */ | ||
502 | swap %d3 /* swap words of 3rd long */ | ||
503 | sub.l %d7,%a1 | ||
504 | movem.l %d3-%d6,(%a1) /* store line */ | ||
505 | .lines_lo6r_entry: | ||
506 | move.w %d1,%d2 /* combine 2nd low word with 3rd high word */ | ||
507 | swap %d2 /* swap words of 2nd long */ | ||
508 | move.w %d0,%d1 /* combine 1st low word with 2nd high word */ | ||
509 | swap %d1 /* swap words of 1st long */ | ||
510 | cmp.l %a2,%a0 /* run %a0 down to first line bound */ | ||
511 | jhi .lines_lo6r_loop | ||
512 | |||
513 | jra .lines_lo6r_end /* handle trailing longwords */ | ||
514 | |||
515 | /* word aligned destination (line - 14): use line bursts in the loop */ | ||
516 | .lines_lo2r_start: | ||
517 | sub.l %d7,%a0 | ||
518 | movem.l (%a0),%d0-%d3 /* load initial line */ | ||
519 | move.w %d3,-(%a1) /* store last low word */ | ||
520 | jra .lines_lo2r_entry /* jump into main loop */ | ||
521 | |||
522 | .lines_lo2r_loop: | ||
523 | move.l %d0,%d4 /* move old line away */ | ||
524 | move.l %d1,%d5 | ||
525 | move.l %d2,%d6 | ||
526 | move.l %d3,%d7 | ||
527 | lea.l (-16,%a0),%a0 | ||
528 | movem.l (%a0),%d0-%d3 /* load line */ | ||
529 | move.w %d3,%d4 /* combine 4th low word with old high word */ | ||
530 | swap %d4 /* swap words of 4th long */ | ||
531 | lea.l (-16,%a1),%a1 | ||
532 | movem.l %d4-%d7,(%a1) /* store line */ | ||
533 | .lines_lo2r_entry: | ||
534 | move.w %d2,%d3 /* combine 3rd low word with 4th high word */ | ||
535 | swap %d3 /* swap words of 3rd long */ | ||
536 | move.w %d1,%d2 /* combine 2nd low word with 3rd high word */ | ||
537 | swap %d2 /* swap words of 2nd long */ | ||
538 | move.w %d0,%d1 /* combine 1st low word with 2nd high word */ | ||
539 | swap %d1 /* swap words of 1st long */ | ||
540 | cmp.l %a2,%a0 /* run %a0 down to first line bound */ | ||
541 | jhi .lines_lo2r_loop | ||
542 | |||
543 | /* word aligned destination (line - 2/6/10/14): tail */ | ||
544 | .lines_lo2r_end: | ||
545 | move.l %d3,-(%a1) /* store third last longword */ | ||
546 | .lines_lo6r_end: | ||
547 | move.l %d2,-(%a1) /* store second last longword */ | ||
548 | .lines_lo10r_end: | ||
549 | move.l %d1,-(%a1) /* store last longword */ | ||
550 | .lines_lo14r_end: | ||
551 | lea.l (-12,%a2),%a2 /* readjust start address for doing longwords */ | ||
552 | cmp.l %a2,%a0 /* any trailing longwords? */ | ||
553 | jls .lines_do2r_tail_end /* no: skip tail loop */ | ||
554 | |||
555 | .lines_do2r_tail_loop: | ||
556 | move.l %d0,%d1 /* move old longword away */ | ||
557 | move.l -(%a0),%d0 /* load new longword */ | ||
558 | move.w %d0,%d1 /* combine low word with old high word */ | ||
559 | swap %d1 /* swap words */ | ||
560 | move.l %d1,-(%a1) /* store longword */ | ||
561 | cmp.l %a2,%a0 /* run %a0 down to first long bound */ | ||
562 | jhi .lines_do2r_tail_loop | ||
563 | |||
564 | .lines_do2r_tail_end: | ||
565 | swap %d0 /* get final high word */ | ||
566 | move.w %d0,-(%a1) /* store it */ | ||
567 | /* jra .linesr_end implicit */ | ||
568 | |||
569 | #else /* !FULLSPEED */ | ||
570 | |||
571 | /* word aligned destination (long - 2): use line burst reads in the loop */ | ||
572 | .lines_do2r_start: | ||
573 | cmp.l %d1,%a0 /* any leading longwords? */ | ||
574 | jhi .lines_do2r_head_start /* yes: leading longword copy */ | ||
575 | |||
576 | lea.l (-16,%a0),%a0 | ||
577 | movem.l (%a0),%d3-%d6 /* load initial line */ | ||
578 | move.w %d6,-(%a1) /* store last low word */ | ||
579 | jra .lines_do2r_entry /* jump into main loop */ | ||
580 | |||
581 | .lines_do2r_head_start: | ||
582 | move.l -(%a0),%d3 /* load initial longword */ | ||
583 | move.w %d3,-(%a1) /* store low word */ | ||
584 | cmp.l %d1,%a0 /* any full longword? */ | ||
585 | jls .lines_do2r_loop /* no: skip head loop */ | ||
586 | |||
587 | .lines_do2r_head_loop: | ||
588 | move.l %d3,%d4 /* move old longword away */ | ||
589 | move.l -(%a0),%d3 /* load new longword */ | ||
590 | move.w %d3,%d4 /* combine low word with old high word */ | ||
591 | swap %d4 /* swap words */ | ||
592 | move.l %d4,-(%a1) /* store longword */ | ||
593 | cmp.l %d1,%a0 /* run %a0 down to last line bound */ | ||
594 | jhi .lines_do2r_head_loop | ||
595 | |||
596 | .lines_do2r_loop: | ||
597 | move.l %d3,%d7 /* move first longword of old line away */ | ||
598 | lea.l (-16,%a0),%a0 | ||
599 | movem.l (%a0),%d3-%d6 /* load line */ | ||
600 | move.w %d6,%d7 /* combine 4th low word with old high word */ | ||
601 | swap %d7 /* swap words of 4th long */ | ||
602 | move.l %d7,-(%a1) /* store 4th longword */ | ||
603 | .lines_do2r_entry: | ||
604 | move.w %d5,%d6 /* combine 3rd low word with 4th high word */ | ||
605 | swap %d6 /* swap words of 3rd long */ | ||
606 | move.l %d6,-(%a1) /* store 3rd longword */ | ||
607 | move.w %d4,%d5 /* combine 2nd low word with 3rd high word */ | ||
608 | swap %d5 /* swap words of 2nd long */ | ||
609 | move.l %d5,-(%a1) /* store 2nd longword */ | ||
610 | move.w %d3,%d4 /* combine 1st low word with 2nd high word */ | ||
611 | swap %d4 /* swap words of 1st long */ | ||
612 | move.l %d4,-(%a1) /* store 1st longword */ | ||
613 | cmp.l %a2,%a0 /* run %a0 down to first line bound */ | ||
614 | jhi .lines_do2r_loop | ||
615 | |||
616 | .lines_do2r_end: | ||
617 | lea.l (-12,%a2),%a2 /* readjust start address for doing longwords */ | ||
618 | cmp.l %a2,%a0 /* any trailing longwords? */ | ||
619 | jls .lines_do2r_tail_end /* no: skip tail loop */ | ||
620 | |||
621 | .lines_do2r_tail_loop: | ||
622 | move.l %d3,%d4 /* move old longword away */ | ||
623 | move.l -(%a0),%d3 /* load new longword */ | ||
624 | move.w %d3,%d4 /* combine low word with old high word */ | ||
625 | swap %d4 /* swap words */ | ||
626 | move.l %d4,-(%a1) /* store longword */ | ||
627 | cmp.l %a2,%a0 /* run %a0 down to first long bound */ | ||
628 | jhi .lines_do2r_tail_loop | ||
629 | |||
630 | .lines_do2r_tail_end: | ||
631 | swap %d3 /* get final high word */ | ||
632 | move.w %d3,-(%a1) /* store it */ | ||
633 | /* jra .linesr_end implicit */ | ||
634 | |||
635 | #endif /* !FULLSPEED */ | ||
636 | |||
637 | .linesr_end: | ||
638 | subq.l #3,%a2 /* readjust end address */ | ||
639 | move.l %a2,%d0 /* start address in %d0 again */ | ||
640 | movem.l (%sp),%d2-%d7/%a2 /* restore registers */ | ||
641 | lea.l (28,%sp),%sp | ||
642 | jra .bytes2r_start /* jump to trailing byte loop */ | ||
643 | |||
644 | .longr_start: | ||
645 | addq.l #3,%d0 /* adjust start address for doing 4 bytes/ pass */ | ||
646 | |||
647 | /* longword copy loop - no lines */ | ||
648 | .longr_loop: | ||
649 | move.l -(%a0),-(%a1) /* copy longword (write can be unaligned) */ | ||
650 | cmp.l %d0,%a0 /* runs %a0 down to first long bound */ | ||
651 | jhi .longr_loop | ||
652 | |||
653 | subq.l #3,%d0 /* readjust start address */ | ||
654 | cmp.l %d0,%a0 /* any bytes left? */ | ||
655 | jls .bytes2r_end /* no: skip trailing byte loop */ | ||
656 | |||
657 | /* trailing byte loop */ | ||
658 | .bytes2r_loop: | ||
659 | move.b -(%a0),-(%a1) /* copy byte */ | ||
660 | .bytes2r_start: | ||
661 | cmp.l %d0,%a0 /* runs %a0 down to start address */ | ||
662 | jhi .bytes2r_loop | ||
663 | |||
664 | .bytes2r_end: | ||
665 | rts /* returns start address */ | ||
666 | |||
667 | .end: | ||
668 | .size memmove,.end-memmove | ||
diff --git a/firmware/target/coldfire/memset-coldfire.S b/firmware/target/coldfire/memset-coldfire.S new file mode 100755 index 0000000000..7c9fe88463 --- /dev/null +++ b/firmware/target/coldfire/memset-coldfire.S | |||
@@ -0,0 +1,150 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2004 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 | .align 2 | ||
24 | .global memset | ||
25 | .type memset,@function | ||
26 | |||
27 | /* Fills a memory region with specified byte value | ||
28 | * This version is optimized for speed | ||
29 | * | ||
30 | * arguments: | ||
31 | * (4,%sp) - start address | ||
32 | * (8,%sp) - data | ||
33 | * (12,%sp) - length | ||
34 | * | ||
35 | * return value: | ||
36 | * %d0 - start address (like ANSI version) | ||
37 | * | ||
38 | * register usage: | ||
39 | * %d0 - data (spread to all 4 bytes when using long stores) | ||
40 | * %d1 - temporary / data (for burst transfer) | ||
41 | * %d2 - data (for burst transfer) | ||
42 | * %d3 - data (for burst transfer) | ||
43 | * %a0 - start address | ||
44 | * %a1 - current address (runs down from end to start) | ||
45 | * | ||
46 | * For maximum speed this routine uses both long stores and burst mode, | ||
47 | * storing whole lines with movem.l. The routine fills memory from end | ||
48 | * to start in order to ease returning the start address. | ||
49 | */ | ||
50 | memset: | ||
51 | move.l (4,%sp),%a0 /* start address */ | ||
52 | move.l (8,%sp),%d0 /* data */ | ||
53 | move.l (12,%sp),%a1 /* length */ | ||
54 | add.l %a0,%a1 /* %a1 = end address */ | ||
55 | |||
56 | move.l %a0,%d1 | ||
57 | addq.l #7,%d1 | ||
58 | and.l #0xFFFFFFFC,%d1 /* %d1 = first long bound + 4 */ | ||
59 | cmp.l %d1,%a1 /* at least one aligned longword to fill? */ | ||
60 | blo.b .no_longs /* no, jump directly to byte loop */ | ||
61 | |||
62 | and.l #0xFF,%d0 /* start: spread data to all 4 bytes */ | ||
63 | move.l %d0,%d1 | ||
64 | lsl.l #8,%d1 | ||
65 | or.l %d1,%d0 /* data now in 2 lower bytes of %d0 */ | ||
66 | move.l %d0,%d1 | ||
67 | swap %d0 | ||
68 | or.l %d1,%d0 /* data now in all 4 bytes of %d0 */ | ||
69 | |||
70 | move.l %a1,%d1 | ||
71 | and.l #0xFFFFFFFC,%d1 /* %d1 = last long bound */ | ||
72 | cmp.l %d1,%a1 /* any bytes to set? */ | ||
73 | bls.b .end_b1 /* no: skip byte loop */ | ||
74 | |||
75 | /* leading byte loop: sets 0..3 bytes */ | ||
76 | .loop_b1: | ||
77 | move.b %d0,-(%a1) /* store byte */ | ||
78 | cmp.l %d1,%a1 /* runs %a1 down to last long bound */ | ||
79 | bhi.b .loop_b1 | ||
80 | |||
81 | .end_b1: | ||
82 | moveq.l #31,%d1 | ||
83 | add.l %a0,%d1 | ||
84 | and.l #0xFFFFFFF0,%d1 /* %d1 = first line bound + 16 */ | ||
85 | cmp.l %d1,%a1 /* at least one full line to fill? */ | ||
86 | blo.b .no_lines /* no, jump to longword loop */ | ||
87 | |||
88 | mov.l %a1,%d1 | ||
89 | and.l #0xFFFFFFF0,%d1 /* %d1 = last line bound */ | ||
90 | cmp.l %d1,%a1 /* any longwords to set? */ | ||
91 | bls.b .end_l1 /* no: skip longword loop */ | ||
92 | |||
93 | /* leading longword loop: sets 0..3 longwords */ | ||
94 | .loop_l1: | ||
95 | move.l %d0,-(%a1) /* store longword */ | ||
96 | cmp.l %d1,%a1 /* runs %a1 down to last line bound */ | ||
97 | bhi.b .loop_l1 | ||
98 | |||
99 | .end_l1: | ||
100 | move.l %d2,-(%sp) /* free some registers */ | ||
101 | move.l %d3,-(%sp) | ||
102 | |||
103 | move.l %d0,%d1 /* spread data to 4 data registers */ | ||
104 | move.l %d0,%d2 | ||
105 | move.l %d0,%d3 | ||
106 | lea.l (15,%a0),%a0 /* start address += 15, acct. for trl. data */ | ||
107 | |||
108 | /* main loop: set whole lines utilising burst mode */ | ||
109 | .loop_line: | ||
110 | lea.l (-16,%a1),%a1 /* pre-decrement */ | ||
111 | movem.l %d0-%d3,(%a1) /* store line */ | ||
112 | cmp.l %a0,%a1 /* runs %a1 down to first line bound */ | ||
113 | bhi.b .loop_line | ||
114 | |||
115 | lea.l (-15,%a0),%a0 /* correct start address */ | ||
116 | move.l (%sp)+,%d3 /* restore registers */ | ||
117 | move.l (%sp)+,%d2 | ||
118 | |||
119 | move.l %a0,%d1 /* %d1 = start address ... */ | ||
120 | addq.l #3,%d1 /* ... +3, account for possible trailing bytes */ | ||
121 | cmp.l %d1,%a1 /* any longwords left */ | ||
122 | bhi.b .loop_l2 /* yes: jump to longword loop */ | ||
123 | bra.b .no_longs /* no: skip loop */ | ||
124 | |||
125 | .no_lines: | ||
126 | move.l %a0,%d1 /* %d1 = start address ... */ | ||
127 | addq.l #3,%d1 /* ... +3, account for possible trailing bytes */ | ||
128 | |||
129 | /* trailing longword loop */ | ||
130 | .loop_l2: | ||
131 | move.l %d0,-(%a1) /* store longword */ | ||
132 | cmp.l %d1,%a1 /* runs %a1 down to first long bound */ | ||
133 | bhi.b .loop_l2 | ||
134 | |||
135 | .no_longs: | ||
136 | cmp.l %a0,%a1 /* any bytes left? */ | ||
137 | bls.b .end_b2 /* no: skip loop */ | ||
138 | |||
139 | /* trailing byte loop */ | ||
140 | .loop_b2: | ||
141 | move.b %d0,-(%a1) /* store byte */ | ||
142 | cmp.l %a0,%a1 /* runs %a1 down to start address */ | ||
143 | bhi.b .loop_b2 | ||
144 | |||
145 | .end_b2: | ||
146 | move.l %a0,%d0 /* return start address */ | ||
147 | rts | ||
148 | |||
149 | .end: | ||
150 | .size memset,.end-memset | ||
diff --git a/firmware/target/coldfire/memset16-coldfire.S b/firmware/target/coldfire/memset16-coldfire.S new file mode 100755 index 0000000000..d9f72f683f --- /dev/null +++ b/firmware/target/coldfire/memset16-coldfire.S | |||
@@ -0,0 +1,144 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2006 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 | .global memset16 | ||
24 | .type memset16,@function | ||
25 | |||
26 | /* Fills a memory region with specified word value | ||
27 | * Start address must be word aligned, length is in words | ||
28 | * This version is optimized for speed | ||
29 | * | ||
30 | * arguments: | ||
31 | * (4,%sp) - start address | ||
32 | * (8,%sp) - data | ||
33 | * (12,%sp) - length | ||
34 | * | ||
35 | * return value: | ||
36 | * %d0 - start address | ||
37 | * | ||
38 | * register usage: | ||
39 | * %d0 - data (spread to both words when using long stores) | ||
40 | * %d1 - temporary / data (for burst transfer) | ||
41 | * %d2 - data (for burst transfer) | ||
42 | * %d3 - data (for burst transfer) | ||
43 | * %a0 - start address | ||
44 | * %a1 - current address (runs down from end to start) | ||
45 | * | ||
46 | * For maximum speed this routine uses both long stores and burst mode, | ||
47 | * storing whole lines with movem.l. The routine fills memory from end | ||
48 | * to start in order to ease returning the start address. | ||
49 | */ | ||
50 | memset16: | ||
51 | move.l (4,%sp),%a0 /* start address */ | ||
52 | move.l (8,%sp),%d0 /* data */ | ||
53 | move.l (12,%sp),%a1 /* length */ | ||
54 | add.l %a1,%a1 | ||
55 | add.l %a0,%a1 /* %a1 = end address */ | ||
56 | |||
57 | move.l %a0,%d1 | ||
58 | addq.l #6,%d1 | ||
59 | and.l #0xFFFFFFFC,%d1 /* %d1 = first long bound + 4 */ | ||
60 | cmp.l %d1,%a1 /* at least one aligned longword to fill? */ | ||
61 | blo.b .no_longs /* no, jump directly to word loop */ | ||
62 | |||
63 | and.l #0xFFFF,%d0 /* start: spread data to both words */ | ||
64 | move.l %d0,%d1 | ||
65 | swap %d1 | ||
66 | or.l %d1,%d0 /* data now in both words */ | ||
67 | |||
68 | move.l %a1,%d1 | ||
69 | and.l #0xFFFFFFFC,%d1 /* %d1 = last long bound */ | ||
70 | cmp.l %d1,%a1 /* one extra word? */ | ||
71 | bls.b .end_w1 /* no: skip */ | ||
72 | |||
73 | move.w %d0,-(%a1) /* set leading word */ | ||
74 | |||
75 | .end_w1: | ||
76 | moveq.l #30,%d1 | ||
77 | add.l %a0,%d1 | ||
78 | and.l #0xFFFFFFF0,%d1 /* %d1 = first line bound + 16 */ | ||
79 | cmp.l %d1,%a1 /* at least one full line to fill? */ | ||
80 | blo.b .no_lines /* no, jump to longword loop */ | ||
81 | |||
82 | mov.l %a1,%d1 | ||
83 | and.l #0xFFFFFFF0,%d1 /* %d1 = last line bound */ | ||
84 | cmp.l %d1,%a1 /* any longwords to set? */ | ||
85 | bls.b .end_l1 /* no: skip longword loop */ | ||
86 | |||
87 | /* leading longword loop: sets 0..3 longwords */ | ||
88 | .loop_l1: | ||
89 | move.l %d0,-(%a1) /* store longword */ | ||
90 | cmp.l %d1,%a1 /* runs %a1 down to last line bound */ | ||
91 | bhi.b .loop_l1 | ||
92 | |||
93 | .end_l1: | ||
94 | move.l %d2,-(%sp) /* free some registers */ | ||
95 | move.l %d3,-(%sp) | ||
96 | |||
97 | move.l %d0,%d1 /* spread data to 4 data registers */ | ||
98 | move.l %d0,%d2 | ||
99 | move.l %d0,%d3 | ||
100 | lea.l (14,%a0),%a0 /* start address += 14, acct. for trl. data */ | ||
101 | |||
102 | /* main loop: set whole lines utilising burst mode */ | ||
103 | .loop_line: | ||
104 | lea.l (-16,%a1),%a1 /* pre-decrement */ | ||
105 | movem.l %d0-%d3,(%a1) /* store line */ | ||
106 | cmp.l %a0,%a1 /* runs %a1 down to first line bound */ | ||
107 | bhi.b .loop_line | ||
108 | |||
109 | lea.l (-14,%a0),%a0 /* correct start address */ | ||
110 | move.l (%sp)+,%d3 /* restore registers */ | ||
111 | move.l (%sp)+,%d2 | ||
112 | |||
113 | move.l %a0,%d1 /* %d1 = start address ... */ | ||
114 | addq.l #2,%d1 /* ... +2, account for possible trailing word */ | ||
115 | cmp.l %d1,%a1 /* any longwords left */ | ||
116 | bhi.b .loop_l2 /* yes: jump to longword loop */ | ||
117 | bra.b .no_longs /* no: skip loop */ | ||
118 | |||
119 | .no_lines: | ||
120 | move.l %a0,%d1 /* %d1 = start address ... */ | ||
121 | addq.l #2,%d1 /* ... +2, account for possible trailing word */ | ||
122 | |||
123 | /* trailing longword loop */ | ||
124 | .loop_l2: | ||
125 | move.l %d0,-(%a1) /* store longword */ | ||
126 | cmp.l %d1,%a1 /* runs %a1 down to first long bound */ | ||
127 | bhi.b .loop_l2 | ||
128 | |||
129 | .no_longs: | ||
130 | cmp.l %a0,%a1 /* any words left? */ | ||
131 | bls.b .end_w2 /* no: skip loop */ | ||
132 | |||
133 | /* trailing word loop */ | ||
134 | .loop_w2: | ||
135 | move.w %d0,-(%a1) /* store word */ | ||
136 | cmp.l %a0,%a1 /* runs %a1 down to start address */ | ||
137 | bhi.b .loop_w2 | ||
138 | |||
139 | .end_w2: | ||
140 | move.l %a0,%d0 /* return start address */ | ||
141 | rts | ||
142 | |||
143 | .end: | ||
144 | .size memset16,.end-memset16 | ||
diff --git a/firmware/target/sh/memcpy-sh.S b/firmware/target/sh/memcpy-sh.S new file mode 100755 index 0000000000..0b5e086be9 --- /dev/null +++ b/firmware/target/sh/memcpy-sh.S | |||
@@ -0,0 +1,217 @@ | |||
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 | .align 2 | ||
24 | .global _memcpy | ||
25 | .global ___memcpy_fwd_entry | ||
26 | .type _memcpy,@function | ||
27 | |||
28 | /* Copies <length> bytes of data in memory from <source> to <dest> | ||
29 | * This version is optimized for speed | ||
30 | * | ||
31 | * arguments: | ||
32 | * r4 - destination address | ||
33 | * r5 - source address | ||
34 | * r6 - length | ||
35 | * | ||
36 | * return value: | ||
37 | * r0 - destination address (like ANSI version) | ||
38 | * | ||
39 | * register usage: | ||
40 | * r0 - data / scratch | ||
41 | * r1 - 2nd data / scratch | ||
42 | * r2 - scratch | ||
43 | * r3 - first long bound / adjusted end address (only if >= 11 bytes) | ||
44 | * r4 - current dest address | ||
45 | * r5 - current source address | ||
46 | * r6 - source end address | ||
47 | * r7 - stored dest start address | ||
48 | * | ||
49 | * The instruction order is devised in a way to utilize the pipelining | ||
50 | * of the SH1 to the max. The routine also tries to utilize fast page mode. | ||
51 | */ | ||
52 | |||
53 | _memcpy: | ||
54 | mov r4,r7 /* store dest for returning */ | ||
55 | ___memcpy_fwd_entry: | ||
56 | add #-8,r4 /* offset for early increment (max. 2 longs) */ | ||
57 | mov #11,r0 | ||
58 | cmp/hs r0,r6 /* at least 11 bytes to copy? (ensures 2 aligned longs) */ | ||
59 | add r5,r6 /* r6 = source_end */ | ||
60 | bf .start_b2 /* no: jump directly to byte loop */ | ||
61 | |||
62 | mov #3,r0 | ||
63 | neg r5,r3 | ||
64 | and r0,r3 /* r3 = (4 - align_offset) % 4 */ | ||
65 | tst r3,r3 /* already aligned? */ | ||
66 | bt .end_b1 /* yes: skip leading byte loop */ | ||
67 | |||
68 | add r5,r3 /* r3 = first source long bound */ | ||
69 | |||
70 | /* leading byte loop: copies 0..3 bytes */ | ||
71 | .loop_b1: | ||
72 | mov.b @r5+,r0 /* load byte & increment source addr */ | ||
73 | add #1,r4 /* increment dest addr */ | ||
74 | mov.b r0,@(7,r4) /* store byte */ | ||
75 | cmp/hi r5,r3 /* runs r5 up to first long bound */ | ||
76 | bt .loop_b1 | ||
77 | /* now r5 is always at a long boundary */ | ||
78 | /* -> memory reading is done in longs for all dest alignments */ | ||
79 | |||
80 | /* selector for main copy loop */ | ||
81 | .end_b1: | ||
82 | mov #3,r1 | ||
83 | and r4,r1 /* r1 = dest alignment offset */ | ||
84 | mova .jmptab,r0 | ||
85 | mov.b @(r0,r1),r1 /* select appropriate main loop */ | ||
86 | add r0,r1 | ||
87 | mov r6,r3 /* move end address to r3 */ | ||
88 | jmp @r1 /* and jump to it */ | ||
89 | add #-7,r3 /* adjust end addr for main loops doing 2 longs/pass */ | ||
90 | |||
91 | /** main loops, copying 2 longs per pass to profit from fast page mode **/ | ||
92 | |||
93 | /* long aligned destination (fastest) */ | ||
94 | .align 2 | ||
95 | .loop_do0: | ||
96 | mov.l @r5+,r1 /* load first long & increment source addr */ | ||
97 | add #16,r4 /* increment dest addr & account for decrementing stores */ | ||
98 | mov.l @r5+,r0 /* load second long & increment source addr */ | ||
99 | cmp/hi r5,r3 /* runs r5 up to last or second last long bound */ | ||
100 | mov.l r0,@-r4 /* store second long */ | ||
101 | mov.l r1,@-r4 /* store first long; NOT ALIGNED - no speed loss here! */ | ||
102 | bt .loop_do0 | ||
103 | |||
104 | add #4,r3 /* readjust end address */ | ||
105 | cmp/hi r5,r3 /* one long left? */ | ||
106 | bf .start_b2 /* no, jump to trailing byte loop */ | ||
107 | |||
108 | mov.l @r5+,r0 /* load last long & increment source addr */ | ||
109 | add #4,r4 /* increment dest addr */ | ||
110 | bra .start_b2 /* jump to trailing byte loop */ | ||
111 | mov.l r0,@(4,r4) /* store last long */ | ||
112 | |||
113 | /* word aligned destination (long + 2) */ | ||
114 | .align 2 | ||
115 | .loop_do2: | ||
116 | mov.l @r5+,r1 /* load first long & increment source addr */ | ||
117 | add #16,r4 /* increment dest addr */ | ||
118 | mov.l @r5+,r0 /* load second long & increment source addr */ | ||
119 | cmp/hi r5,r3 /* runs r5 up to last or second last long bound */ | ||
120 | mov.w r0,@-r4 /* store low word of second long */ | ||
121 | xtrct r1,r0 /* extract low word of first long & high word of second long */ | ||
122 | mov.l r0,@-r4 /* and store as long */ | ||
123 | swap.w r1,r0 /* get high word of first long */ | ||
124 | mov.w r0,@-r4 /* and store it */ | ||
125 | bt .loop_do2 | ||
126 | |||
127 | add #4,r3 /* readjust end address */ | ||
128 | cmp/hi r5,r3 /* one long left? */ | ||
129 | bf .start_b2 /* no, jump to trailing byte loop */ | ||
130 | |||
131 | mov.l @r5+,r0 /* load last long & increment source addr */ | ||
132 | add #4,r4 /* increment dest addr */ | ||
133 | mov.w r0,@(6,r4) /* store low word */ | ||
134 | shlr16 r0 /* get high word */ | ||
135 | bra .start_b2 /* jump to trailing byte loop */ | ||
136 | mov.w r0,@(4,r4) /* and store it */ | ||
137 | |||
138 | /* jumptable for loop selector */ | ||
139 | .align 2 | ||
140 | .jmptab: | ||
141 | .byte .loop_do0 - .jmptab /* placed in the middle because the SH1 */ | ||
142 | .byte .loop_do1 - .jmptab /* loads bytes sign-extended. Otherwise */ | ||
143 | .byte .loop_do2 - .jmptab /* the last loop would be out of reach */ | ||
144 | .byte .loop_do3 - .jmptab /* of the offset range. */ | ||
145 | |||
146 | /* byte aligned destination (long + 1) */ | ||
147 | .align 2 | ||
148 | .loop_do1: | ||
149 | mov.l @r5+,r1 /* load first long & increment source addr */ | ||
150 | add #16,r4 /* increment dest addr */ | ||
151 | mov.l @r5+,r0 /* load second long & increment source addr */ | ||
152 | cmp/hi r5,r3 /* runs r5 up to last or second last long bound */ | ||
153 | mov.b r0,@-r4 /* store low byte of second long */ | ||
154 | shlr8 r0 /* get upper 3 bytes */ | ||
155 | mov r1,r2 /* copy first long */ | ||
156 | shll16 r2 /* move low byte of first long all the way up, .. */ | ||
157 | shll8 r2 | ||
158 | or r2,r0 /* ..combine with the 3 bytes of second long.. */ | ||
159 | mov.l r0,@-r4 /* ..and store as long */ | ||
160 | shlr8 r1 /* get middle 2 bytes */ | ||
161 | mov.w r1,@-r4 /* store as word */ | ||
162 | shlr16 r1 /* get upper byte */ | ||
163 | mov.b r1,@-r4 /* and store */ | ||
164 | bt .loop_do1 | ||
165 | |||
166 | add #4,r3 /* readjust end address */ | ||
167 | .last_do13: | ||
168 | cmp/hi r5,r3 /* one long left? */ | ||
169 | bf .start_b2 /* no, jump to trailing byte loop */ | ||
170 | |||
171 | mov.l @r5+,r0 /* load last long & increment source addr */ | ||
172 | add #12,r4 /* increment dest addr */ | ||
173 | mov.b r0,@-r4 /* store low byte */ | ||
174 | shlr8 r0 /* get middle 2 bytes */ | ||
175 | mov.w r0,@-r4 /* store as word */ | ||
176 | shlr16 r0 /* get upper byte */ | ||
177 | mov.b r0,@-r4 /* and store */ | ||
178 | bra .start_b2 /* jump to trailing byte loop */ | ||
179 | add #-4,r4 /* readjust destination */ | ||
180 | |||
181 | /* byte aligned destination (long + 3) */ | ||
182 | .align 2 | ||
183 | .loop_do3: | ||
184 | mov.l @r5+,r1 /* load first long & increment source addr */ | ||
185 | add #16,r4 /* increment dest addr */ | ||
186 | mov.l @r5+,r0 /* load second long & increment source addr */ | ||
187 | mov r1,r2 /* copy first long */ | ||
188 | mov.b r0,@-r4 /* store low byte of second long */ | ||
189 | shlr8 r0 /* get middle 2 bytes */ | ||
190 | mov.w r0,@-r4 /* store as word */ | ||
191 | shlr16 r0 /* get upper byte */ | ||
192 | shll8 r2 /* move lower 3 bytes of first long one up.. */ | ||
193 | or r2,r0 /* ..combine with the 1 byte of second long.. */ | ||
194 | mov.l r0,@-r4 /* ..and store as long */ | ||
195 | shlr16 r1 /* get upper byte of first long.. */ | ||
196 | shlr8 r1 | ||
197 | cmp/hi r5,r3 /* runs r5 up to last or second last long bound */ | ||
198 | mov.b r1,@-r4 /* ..and store */ | ||
199 | bt .loop_do3 | ||
200 | |||
201 | bra .last_do13 /* handle last longword: reuse routine for (long + 1) */ | ||
202 | add #4,r3 /* readjust end address */ | ||
203 | |||
204 | /* trailing byte loop: copies 0..3 bytes (or all for < 11 in total) */ | ||
205 | .align 2 | ||
206 | .loop_b2: | ||
207 | mov.b @r5+,r0 /* load byte & increment source addr */ | ||
208 | add #1,r4 /* increment dest addr */ | ||
209 | mov.b r0,@(7,r4) /* store byte */ | ||
210 | .start_b2: | ||
211 | cmp/hi r5,r6 /* runs r5 up to end address */ | ||
212 | bt .loop_b2 | ||
213 | |||
214 | rts | ||
215 | mov r7,r0 /* return dest start address */ | ||
216 | .end: | ||
217 | .size _memcpy,.end-_memcpy | ||
diff --git a/firmware/target/sh/memmove-sh.S b/firmware/target/sh/memmove-sh.S new file mode 100755 index 0000000000..9ae9ae5fa2 --- /dev/null +++ b/firmware/target/sh/memmove-sh.S | |||
@@ -0,0 +1,220 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2006 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 | .align 2 | ||
24 | .global _memmove | ||
25 | .type _memmove,@function | ||
26 | |||
27 | /* Moves <length> bytes of data in memory from <source> to <dest> | ||
28 | * Regions may overlap. | ||
29 | * This version is optimized for speed, and needs the corresponding memcpy | ||
30 | * implementation for the forward copy branch. | ||
31 | * | ||
32 | * arguments: | ||
33 | * r4 - destination address | ||
34 | * r5 - source address | ||
35 | * r6 - length | ||
36 | * | ||
37 | * return value: | ||
38 | * r0 - destination address (like ANSI version) | ||
39 | * | ||
40 | * register usage: | ||
41 | * r0 - data / scratch | ||
42 | * r1 - 2nd data / scratch | ||
43 | * r2 - scratch | ||
44 | * r3 - last long bound / adjusted start address (only if >= 11 bytes) | ||
45 | * r4 - current dest address | ||
46 | * r5 - source start address | ||
47 | * r6 - current source address | ||
48 | * | ||
49 | * The instruction order is devised in a way to utilize the pipelining | ||
50 | * of the SH1 to the max. The routine also tries to utilize fast page mode. | ||
51 | */ | ||
52 | |||
53 | _memmove: | ||
54 | cmp/hi r4,r5 /* source > destination */ | ||
55 | bf .backward /* no: backward copy */ | ||
56 | mov.l .memcpy_fwd,r0 | ||
57 | jmp @r0 | ||
58 | mov r4,r7 /* store dest for returning */ | ||
59 | |||
60 | .align 2 | ||
61 | .memcpy_fwd: | ||
62 | .long ___memcpy_fwd_entry | ||
63 | |||
64 | .backward: | ||
65 | add r6,r4 /* r4 = destination end */ | ||
66 | mov #11,r0 | ||
67 | cmp/hs r0,r6 /* at least 11 bytes to copy? (ensures 2 aligned longs) */ | ||
68 | add #-8,r5 /* adjust for late decrement (max. 2 longs) */ | ||
69 | add r5,r6 /* r6 = source end - 8 */ | ||
70 | bf .start_b2r /* no: jump directly to byte loop */ | ||
71 | |||
72 | mov #-4,r3 /* r3 = 0xfffffffc */ | ||
73 | and r6,r3 /* r3 = last source long bound */ | ||
74 | cmp/hi r3,r6 /* already aligned? */ | ||
75 | bf .end_b1r /* yes: skip leading byte loop */ | ||
76 | |||
77 | .loop_b1r: | ||
78 | mov.b @(7,r6),r0 /* load byte */ | ||
79 | add #-1,r6 /* decrement source addr */ | ||
80 | mov.b r0,@-r4 /* store byte */ | ||
81 | cmp/hi r3,r6 /* runs r6 down to last long bound */ | ||
82 | bt .loop_b1r | ||
83 | |||
84 | .end_b1r: | ||
85 | mov #3,r1 | ||
86 | and r4,r1 /* r1 = dest alignment offset */ | ||
87 | mova .jmptab_r,r0 | ||
88 | mov.b @(r0,r1),r1 /* select appropriate main loop.. */ | ||
89 | add r0,r1 | ||
90 | mov r5,r3 /* copy start adress to r3 */ | ||
91 | jmp @r1 /* ..and jump to it */ | ||
92 | add #7,r3 /* adjust end addr for main loops doing 2 longs/pass */ | ||
93 | |||
94 | /** main loops, copying 2 longs per pass to profit from fast page mode **/ | ||
95 | |||
96 | /* long aligned destination (fastest) */ | ||
97 | .align 2 | ||
98 | .loop_do0r: | ||
99 | mov.l @r6,r1 /* load first long */ | ||
100 | add #-8,r6 /* decrement source addr */ | ||
101 | mov.l @(12,r6),r0 /* load second long */ | ||
102 | cmp/hi r3,r6 /* runs r6 down to first or second long bound */ | ||
103 | mov.l r0,@-r4 /* store second long */ | ||
104 | mov.l r1,@-r4 /* store first long; NOT ALIGNED - no speed loss here! */ | ||
105 | bt .loop_do0r | ||
106 | |||
107 | add #-4,r3 /* readjust end address */ | ||
108 | cmp/hi r3,r6 /* first long left? */ | ||
109 | bf .start_b2r /* no, jump to trailing byte loop */ | ||
110 | |||
111 | mov.l @(4,r6),r0 /* load first long */ | ||
112 | add #-4,r6 /* decrement source addr */ | ||
113 | bra .start_b2r /* jump to trailing byte loop */ | ||
114 | mov.l r0,@-r4 /* store first long */ | ||
115 | |||
116 | /* word aligned destination (long + 2) */ | ||
117 | .align 2 | ||
118 | .loop_do2r: | ||
119 | mov.l @r6,r1 /* load first long */ | ||
120 | add #-8,r6 /* decrement source addr */ | ||
121 | mov.l @(12,r6),r0 /* load second long */ | ||
122 | cmp/hi r3,r6 /* runs r6 down to first or second long bound */ | ||
123 | mov.w r0,@-r4 /* store low word of second long */ | ||
124 | xtrct r1,r0 /* extract low word of first long & high word of second long */ | ||
125 | mov.l r0,@-r4 /* and store as long */ | ||
126 | shlr16 r1 /* get high word of first long */ | ||
127 | mov.w r1,@-r4 /* and store it */ | ||
128 | bt .loop_do2r | ||
129 | |||
130 | add #-4,r3 /* readjust end address */ | ||
131 | cmp/hi r3,r6 /* first long left? */ | ||
132 | bf .start_b2r /* no, jump to trailing byte loop */ | ||
133 | |||
134 | mov.l @(4,r6),r0 /* load first long & decrement source addr */ | ||
135 | add #-4,r6 /* decrement source addr */ | ||
136 | mov.w r0,@-r4 /* store low word */ | ||
137 | shlr16 r0 /* get high word */ | ||
138 | bra .start_b2r /* jump to trailing byte loop */ | ||
139 | mov.w r0,@-r4 /* and store it */ | ||
140 | |||
141 | /* jumptable for loop selector */ | ||
142 | .align 2 | ||
143 | .jmptab_r: | ||
144 | .byte .loop_do0r - .jmptab_r /* placed in the middle because the SH1 */ | ||
145 | .byte .loop_do1r - .jmptab_r /* loads bytes sign-extended. Otherwise */ | ||
146 | .byte .loop_do2r - .jmptab_r /* the last loop would be out of reach */ | ||
147 | .byte .loop_do3r - .jmptab_r /* of the offset range. */ | ||
148 | |||
149 | /* byte aligned destination (long + 1) */ | ||
150 | .align 2 | ||
151 | .loop_do1r: | ||
152 | mov.l @r6,r1 /* load first long */ | ||
153 | add #-8,r6 /* decrement source addr */ | ||
154 | mov.l @(12,r6),r0 /* load second long */ | ||
155 | cmp/hi r3,r6 /* runs r6 down to first or second long bound */ | ||
156 | mov.b r0,@-r4 /* store low byte of second long */ | ||
157 | shlr8 r0 /* get upper 3 bytes */ | ||
158 | mov r1,r2 /* copy first long */ | ||
159 | shll16 r2 /* move low byte of first long all the way up, .. */ | ||
160 | shll8 r2 | ||
161 | or r2,r0 /* ..combine with the 3 bytes of second long.. */ | ||
162 | mov.l r0,@-r4 /* ..and store as long */ | ||
163 | shlr8 r1 /* get middle 2 bytes */ | ||
164 | mov.w r1,@-r4 /* store as word */ | ||
165 | shlr16 r1 /* get upper byte */ | ||
166 | mov.b r1,@-r4 /* and store */ | ||
167 | bt .loop_do1r | ||
168 | |||
169 | add #-4,r3 /* readjust end address */ | ||
170 | .last_do13r: | ||
171 | cmp/hi r3,r6 /* first long left? */ | ||
172 | bf .start_b2r /* no, jump to trailing byte loop */ | ||
173 | |||
174 | nop /* alignment */ | ||
175 | mov.l @(4,r6),r0 /* load first long */ | ||
176 | add #-4,r6 /* decrement source addr */ | ||
177 | mov.b r0,@-r4 /* store low byte */ | ||
178 | shlr8 r0 /* get middle 2 bytes */ | ||
179 | mov.w r0,@-r4 /* store as word */ | ||
180 | shlr16 r0 /* get upper byte */ | ||
181 | bra .start_b2r /* jump to trailing byte loop */ | ||
182 | mov.b r0,@-r4 /* and store */ | ||
183 | |||
184 | /* byte aligned destination (long + 3) */ | ||
185 | .align 2 | ||
186 | .loop_do3r: | ||
187 | mov.l @r6,r1 /* load first long */ | ||
188 | add #-8,r6 /* decrement source addr */ | ||
189 | mov.l @(12,r6),r0 /* load second long */ | ||
190 | mov r1,r2 /* copy first long */ | ||
191 | mov.b r0,@-r4 /* store low byte of second long */ | ||
192 | shlr8 r0 /* get middle 2 bytes */ | ||
193 | mov.w r0,@-r4 /* store as word */ | ||
194 | shlr16 r0 /* get upper byte */ | ||
195 | shll8 r2 /* move lower 3 bytes of first long one up.. */ | ||
196 | or r2,r0 /* ..combine with the 1 byte of second long.. */ | ||
197 | mov.l r0,@-r4 /* ..and store as long */ | ||
198 | shlr16 r1 /* get upper byte of first long */ | ||
199 | shlr8 r1 | ||
200 | cmp/hi r3,r6 /* runs r6 down to first or second long bound */ | ||
201 | mov.b r1,@-r4 /* ..and store */ | ||
202 | bt .loop_do3r | ||
203 | |||
204 | bra .last_do13r /* handle first longword: reuse routine for (long + 1) */ | ||
205 | add #-4,r3 /* readjust end address */ | ||
206 | |||
207 | /* trailing byte loop: copies 0..3 bytes (or all for < 11 in total) */ | ||
208 | .align 2 | ||
209 | .loop_b2r: | ||
210 | mov.b @(7,r6),r0 /* load byte */ | ||
211 | add #-1,r6 /* decrement source addr */ | ||
212 | mov.b r0,@-r4 /* store byte */ | ||
213 | .start_b2r: | ||
214 | cmp/hi r5,r6 /* runs r6 down to start address */ | ||
215 | bt .loop_b2r | ||
216 | |||
217 | rts | ||
218 | mov r4,r0 /* return dest start address */ | ||
219 | .end: | ||
220 | .size _memmove,.end-_memmove | ||
diff --git a/firmware/target/sh/memset-sh.S b/firmware/target/sh/memset-sh.S new file mode 100755 index 0000000000..9b96b93f27 --- /dev/null +++ b/firmware/target/sh/memset-sh.S | |||
@@ -0,0 +1,107 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2004 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 | .align 2 | ||
24 | .global _memset | ||
25 | .type _memset,@function | ||
26 | |||
27 | /* Fills a memory region with specified byte value | ||
28 | * This version is optimized for speed | ||
29 | * | ||
30 | * arguments: | ||
31 | * r4 - start address | ||
32 | * r5 - data | ||
33 | * r6 - length | ||
34 | * | ||
35 | * return value: | ||
36 | * r0 - start address (like ANSI version) | ||
37 | * | ||
38 | * register usage: | ||
39 | * r0 - temporary | ||
40 | * r1 - start address +11 for main loop | ||
41 | * r4 - start address | ||
42 | * r5 - data (spread to all 4 bytes when using long stores) | ||
43 | * r6 - current address (runs down from end to start) | ||
44 | * | ||
45 | * The instruction order below is devised in a way to utilize the pipelining | ||
46 | * of the SH1 to the max. The routine fills memory from end to start in | ||
47 | * order to utilize the auto-decrementing store instructions. | ||
48 | */ | ||
49 | |||
50 | _memset: | ||
51 | neg r4,r0 | ||
52 | and #3,r0 /* r0 = (4 - align_offset) % 4 */ | ||
53 | add #4,r0 | ||
54 | cmp/hs r0,r6 /* at least one aligned longword to fill? */ | ||
55 | add r4,r6 /* r6 = end_address */ | ||
56 | bf .no_longs /* no, jump directly to byte loop */ | ||
57 | |||
58 | extu.b r5,r5 /* start: spread data to all 4 bytes */ | ||
59 | swap.b r5,r0 | ||
60 | or r0,r5 /* data now in 2 lower bytes of r5 */ | ||
61 | swap.w r5,r0 | ||
62 | or r0,r5 /* data now in all 4 bytes of r5 */ | ||
63 | |||
64 | mov r6,r0 | ||
65 | tst #3,r0 /* r0 already long aligned? */ | ||
66 | bt .end_b1 /* yes: skip loop */ | ||
67 | |||
68 | /* leading byte loop: sets 0..3 bytes */ | ||
69 | .loop_b1: | ||
70 | mov.b r5,@-r0 /* store byte */ | ||
71 | tst #3,r0 /* r0 long aligned? */ | ||
72 | bf .loop_b1 /* runs r0 down until long aligned */ | ||
73 | |||
74 | mov r0,r6 /* r6 = last long bound */ | ||
75 | nop /* keep alignment */ | ||
76 | |||
77 | .end_b1: | ||
78 | mov r4,r1 /* r1 = start_address... */ | ||
79 | add #11,r1 /* ... + 11, combined for rounding and offset */ | ||
80 | xor r1,r0 | ||
81 | tst #4,r0 /* bit 2 tells whether an even or odd number of */ | ||
82 | bf .loop_odd /* longwords to set */ | ||
83 | |||
84 | /* main loop: set 2 longs per pass */ | ||
85 | .loop_2l: | ||
86 | mov.l r5,@-r6 /* store first long */ | ||
87 | .loop_odd: | ||
88 | cmp/hi r1,r6 /* runs r6 down to first long bound */ | ||
89 | mov.l r5,@-r6 /* store second long */ | ||
90 | bt .loop_2l | ||
91 | |||
92 | .no_longs: | ||
93 | cmp/hi r4,r6 /* any bytes left? */ | ||
94 | bf .end_b2 /* no: skip loop */ | ||
95 | |||
96 | /* trailing byte loop */ | ||
97 | .loop_b2: | ||
98 | mov.b r5,@-r6 /* store byte */ | ||
99 | cmp/hi r4,r6 /* runs r6 down to the start address */ | ||
100 | bt .loop_b2 | ||
101 | |||
102 | .end_b2: | ||
103 | rts | ||
104 | mov r4,r0 /* return start address */ | ||
105 | |||
106 | .end: | ||
107 | .size _memset,.end-_memset | ||
diff --git a/firmware/target/sh/strlen-sh.S b/firmware/target/sh/strlen-sh.S new file mode 100755 index 0000000000..34837605ac --- /dev/null +++ b/firmware/target/sh/strlen-sh.S | |||
@@ -0,0 +1,94 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 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 | .align 2 | ||
24 | .global _strlen | ||
25 | .type _strlen,@function | ||
26 | |||
27 | /* Works out the length of a string | ||
28 | * This version is optimized for speed | ||
29 | * | ||
30 | * arguments: | ||
31 | * r4 - start address | ||
32 | * | ||
33 | * return value: | ||
34 | * r0 - string length | ||
35 | * | ||
36 | * register usage: | ||
37 | * r0 - current address | ||
38 | * r1 - current value (byte/long) | ||
39 | * r2 - mask for alignment / zero (for cmp/str) | ||
40 | * r4 - start address | ||
41 | * | ||
42 | */ | ||
43 | |||
44 | _strlen: | ||
45 | mov r4,r0 /* r0 = start address */ | ||
46 | tst #3,r0 /* long aligned? */ | ||
47 | bt .start_l /* yes, jump directly to the longword loop */ | ||
48 | |||
49 | /* not long aligned: check the first 3 bytes */ | ||
50 | mov.b @r0+,r1 /* fetch first byte */ | ||
51 | tst r1,r1 /* byte == 0 ? */ | ||
52 | bt .hitzero /* yes, string end found */ | ||
53 | mov.b @r0+,r1 /* fetch second byte */ | ||
54 | mov #3,r2 /* prepare mask: r2 = 0..00000011b */ | ||
55 | tst r1,r1 /* byte == 0 ? */ | ||
56 | bt .hitzero /* yes, string end found */ | ||
57 | mov.b @r0+,r1 /* fetch third byte */ | ||
58 | not r2,r2 /* prepare mask: r2 = 1..11111100b */ | ||
59 | tst r1,r1 /* byte == 0 ? */ | ||
60 | bt .hitzero /* yes, string end found */ | ||
61 | |||
62 | /* not yet found, fall through into longword loop */ | ||
63 | and r2,r0 /* align down to long bound */ | ||
64 | |||
65 | /* main loop: check longwords */ | ||
66 | .start_l: | ||
67 | mov #0,r2 /* zero longword for cmp/str */ | ||
68 | .loop_l: | ||
69 | mov.l @r0+,r1 /* fetch long word */ | ||
70 | cmp/str r1,r2 /* any zero byte within? */ | ||
71 | bf .loop_l /* no, loop */ | ||
72 | add #-4,r0 /* set address back to start of this longword */ | ||
73 | |||
74 | /* the last longword contains the string end: figure out the byte */ | ||
75 | mov.b @r0+,r1 /* fetch first byte */ | ||
76 | tst r1,r1 /* byte == 0 ? */ | ||
77 | bt .hitzero /* yes, string end found */ | ||
78 | mov.b @r0+,r1 /* fetch second byte */ | ||
79 | tst r1,r1 /* byte == 0 ? */ | ||
80 | bt .hitzero /* yes, string end found */ | ||
81 | mov.b @r0+,r1 /* fetch third byte */ | ||
82 | tst r1,r1 /* byte == 0 ? */ | ||
83 | bt .hitzero /* yes, string end found */ | ||
84 | rts /* must be the fourth byte */ | ||
85 | sub r4,r0 /* len = string_end - string_start */ | ||
86 | |||
87 | .hitzero: | ||
88 | add #-1,r0 /* undo address increment */ | ||
89 | rts | ||
90 | sub r4,r0 /* len = string_end - string_start */ | ||
91 | |||
92 | .end: | ||
93 | .size _strlen,.end-_strlen | ||
94 | |||