summaryrefslogtreecommitdiff
path: root/firmware/asm/sh/memcpy.S
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/asm/sh/memcpy.S')
-rw-r--r--firmware/asm/sh/memcpy.S227
1 files changed, 0 insertions, 227 deletions
diff --git a/firmware/asm/sh/memcpy.S b/firmware/asm/sh/memcpy.S
deleted file mode 100644
index 3d623c48cd..0000000000
--- a/firmware/asm/sh/memcpy.S
+++ /dev/null
@@ -1,227 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2004-2005 by Jens Arnold
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "config.h"
22
23 .section .icode,"ax",@progbits
24
25 .align 2
26 .global _memcpy
27 .global _mempcpy
28 .global ___memcpy_fwd_entry
29 .type _memcpy,@function
30 .type _mempcpy,@function
31
32/* Copies <length> bytes of data in memory from <source> to <dest>
33 * This version is optimized for speed
34 *
35 * arguments:
36 * r4 - destination address
37 * r5 - source address
38 * r6 - length
39 *
40 * return value:
41 * r0 - destination address (like ANSI version)
42 *
43 * register usage:
44 * r0 - data / scratch
45 * r1 - 2nd data / scratch
46 * r2 - scratch
47 * r3 - first long bound / adjusted end address (only if >= 11 bytes)
48 * r4 - current dest address
49 * r5 - current source address
50 * r6 - source end address
51 * r7 - stored dest start address
52 *
53 * The instruction order is devised in a way to utilize the pipelining
54 * of the SH1 to the max. The routine also tries to utilize fast page mode.
55 */
56_mempcpy:
57 mov r4,r7 /* store dest + length for returning */
58 bra ___memcpy_fwd_entry
59 add r6,r7
60
61_memcpy:
62 mov r4,r7 /* store dest for returning */
63___memcpy_fwd_entry:
64 add #-8,r4 /* offset for early increment (max. 2 longs) */
65 mov #11,r0
66 cmp/hs r0,r6 /* at least 11 bytes to copy? (ensures 2 aligned longs) */
67 add r5,r6 /* r6 = source_end */
68 bf .start_b2 /* no: jump directly to byte loop */
69
70 mov #3,r0
71 neg r5,r3
72 and r0,r3 /* r3 = (4 - align_offset) % 4 */
73 tst r3,r3 /* already aligned? */
74 bt .end_b1 /* yes: skip leading byte loop */
75
76 add r5,r3 /* r3 = first source long bound */
77
78 /* leading byte loop: copies 0..3 bytes */
79.loop_b1:
80 mov.b @r5+,r0 /* load byte & increment source addr */
81 add #1,r4 /* increment dest addr */
82 mov.b r0,@(7,r4) /* store byte */
83 cmp/hi r5,r3 /* runs r5 up to first long bound */
84 bt .loop_b1
85 /* now r5 is always at a long boundary */
86 /* -> memory reading is done in longs for all dest alignments */
87
88 /* selector for main copy loop */
89.end_b1:
90 mov #3,r1
91 and r4,r1 /* r1 = dest alignment offset */
92 mova .jmptab,r0
93 mov.b @(r0,r1),r1 /* select appropriate main loop */
94 add r0,r1
95 mov r6,r3 /* move end address to r3 */
96 jmp @r1 /* and jump to it */
97 add #-7,r3 /* adjust end addr for main loops doing 2 longs/pass */
98
99 /** main loops, copying 2 longs per pass to profit from fast page mode **/
100
101 /* long aligned destination (fastest) */
102 .align 2
103.loop_do0:
104 mov.l @r5+,r1 /* load first long & increment source addr */
105 add #16,r4 /* increment dest addr & account for decrementing stores */
106 mov.l @r5+,r0 /* load second long & increment source addr */
107 cmp/hi r5,r3 /* runs r5 up to last or second last long bound */
108 mov.l r0,@-r4 /* store second long */
109 mov.l r1,@-r4 /* store first long; NOT ALIGNED - no speed loss here! */
110 bt .loop_do0
111
112 add #4,r3 /* readjust end address */
113 cmp/hi r5,r3 /* one long left? */
114 bf .start_b2 /* no, jump to trailing byte loop */
115
116 mov.l @r5+,r0 /* load last long & increment source addr */
117 add #4,r4 /* increment dest addr */
118 bra .start_b2 /* jump to trailing byte loop */
119 mov.l r0,@(4,r4) /* store last long */
120
121 /* word aligned destination (long + 2) */
122 .align 2
123.loop_do2:
124 mov.l @r5+,r1 /* load first long & increment source addr */
125 add #16,r4 /* increment dest addr */
126 mov.l @r5+,r0 /* load second long & increment source addr */
127 cmp/hi r5,r3 /* runs r5 up to last or second last long bound */
128 mov.w r0,@-r4 /* store low word of second long */
129 xtrct r1,r0 /* extract low word of first long & high word of second long */
130 mov.l r0,@-r4 /* and store as long */
131 swap.w r1,r0 /* get high word of first long */
132 mov.w r0,@-r4 /* and store it */
133 bt .loop_do2
134
135 add #4,r3 /* readjust end address */
136 cmp/hi r5,r3 /* one long left? */
137 bf .start_b2 /* no, jump to trailing byte loop */
138
139 mov.l @r5+,r0 /* load last long & increment source addr */
140 add #4,r4 /* increment dest addr */
141 mov.w r0,@(6,r4) /* store low word */
142 shlr16 r0 /* get high word */
143 bra .start_b2 /* jump to trailing byte loop */
144 mov.w r0,@(4,r4) /* and store it */
145
146 /* jumptable for loop selector */
147 .align 2
148.jmptab:
149 .byte .loop_do0 - .jmptab /* placed in the middle because the SH1 */
150 .byte .loop_do1 - .jmptab /* loads bytes sign-extended. Otherwise */
151 .byte .loop_do2 - .jmptab /* the last loop would be out of reach */
152 .byte .loop_do3 - .jmptab /* of the offset range. */
153
154 /* byte aligned destination (long + 1) */
155 .align 2
156.loop_do1:
157 mov.l @r5+,r1 /* load first long & increment source addr */
158 add #16,r4 /* increment dest addr */
159 mov.l @r5+,r0 /* load second long & increment source addr */
160 cmp/hi r5,r3 /* runs r5 up to last or second last long bound */
161 mov.b r0,@-r4 /* store low byte of second long */
162 shlr8 r0 /* get upper 3 bytes */
163 mov r1,r2 /* copy first long */
164 shll16 r2 /* move low byte of first long all the way up, .. */
165 shll8 r2
166 or r2,r0 /* ..combine with the 3 bytes of second long.. */
167 mov.l r0,@-r4 /* ..and store as long */
168 shlr8 r1 /* get middle 2 bytes */
169 mov.w r1,@-r4 /* store as word */
170 shlr16 r1 /* get upper byte */
171 mov.b r1,@-r4 /* and store */
172 bt .loop_do1
173
174 add #4,r3 /* readjust end address */
175.last_do13:
176 cmp/hi r5,r3 /* one long left? */
177 bf .start_b2 /* no, jump to trailing byte loop */
178
179 mov.l @r5+,r0 /* load last long & increment source addr */
180 add #12,r4 /* increment dest addr */
181 mov.b r0,@-r4 /* store low byte */
182 shlr8 r0 /* get middle 2 bytes */
183 mov.w r0,@-r4 /* store as word */
184 shlr16 r0 /* get upper byte */
185 mov.b r0,@-r4 /* and store */
186 bra .start_b2 /* jump to trailing byte loop */
187 add #-4,r4 /* readjust destination */
188
189 /* byte aligned destination (long + 3) */
190 .align 2
191.loop_do3:
192 mov.l @r5+,r1 /* load first long & increment source addr */
193 add #16,r4 /* increment dest addr */
194 mov.l @r5+,r0 /* load second long & increment source addr */
195 mov r1,r2 /* copy first long */
196 mov.b r0,@-r4 /* store low byte of second long */
197 shlr8 r0 /* get middle 2 bytes */
198 mov.w r0,@-r4 /* store as word */
199 shlr16 r0 /* get upper byte */
200 shll8 r2 /* move lower 3 bytes of first long one up.. */
201 or r2,r0 /* ..combine with the 1 byte of second long.. */
202 mov.l r0,@-r4 /* ..and store as long */
203 shlr16 r1 /* get upper byte of first long.. */
204 shlr8 r1
205 cmp/hi r5,r3 /* runs r5 up to last or second last long bound */
206 mov.b r1,@-r4 /* ..and store */
207 bt .loop_do3
208
209 bra .last_do13 /* handle last longword: reuse routine for (long + 1) */
210 add #4,r3 /* readjust end address */
211
212 /* trailing byte loop: copies 0..3 bytes (or all for < 11 in total) */
213 .align 2
214.loop_b2:
215 mov.b @r5+,r0 /* load byte & increment source addr */
216 add #1,r4 /* increment dest addr */
217 mov.b r0,@(7,r4) /* store byte */
218.start_b2:
219 cmp/hi r5,r6 /* runs r5 up to end address */
220 bt .loop_b2
221
222 rts
223 mov r7,r0 /* return dest start address */
224.end:
225 .size _memcpy,.end-_memcpy
226 .size _mempcpy,.end-_mempcpy
227