2 * linux/arch/arm/lib/memmove.S
4 * Author: Nicolas Pitre
5 * Created: Sep 28, 2005
6 * Copyright: (C) MontaVista Software Inc.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/linkage.h>
14 #include <asm/assembler.h>
15 #include <asm/unwind.h>
20 * Prototype: void *memmove(void *dest, const void *src, size_t n);
24 * If the memory regions don't overlap, we simply branch to memcpy which is
25 * normally a bit faster. Otherwise the copy is done going downwards. This
26 * is a transposition of the code from copy_template.S but with the copy
27 * occurring in the opposite direction.
37 stmfd sp!, {r0, r4, lr}
41 UNWIND( .save {r0, r4, lr} ) @ in first stmfd block
57 UNWIND( .save {r0, r4, lr} )
58 UNWIND( .save {r5 - r8} ) @ in second stmfd block
61 CALGN( ands ip, r0, #31 )
62 CALGN( sbcnes r4, ip, r2 ) @ C is always set here
65 CALGN( subs r2, r2, ip ) @ C is set here
66 CALGN( rsb ip, ip, #32 )
67 CALGN( add pc, r4, ip )
70 2: PLD( subs r2, r2, #96 )
76 3: PLD( pld [r1, #-128] )
77 4: ldmdb r1!, {r3, r4, r5, r6, r7, r8, ip, lr}
79 stmdb r0!, {r3, r4, r5, r6, r7, r8, ip, lr}
86 addne pc, pc, ip @ C is always clear here
100 W(str) r3, [r0, #-4]!
101 W(str) r4, [r0, #-4]!
102 W(str) r5, [r0, #-4]!
103 W(str) r6, [r0, #-4]!
104 W(str) r7, [r0, #-4]!
105 W(str) r8, [r0, #-4]!
106 W(str) lr, [r0, #-4]!
110 7: ldmfd sp!, {r5 - r8}
111 UNWIND( .fnend ) @ end of second stmfd block
114 UNWIND( .save {r0, r4, lr} ) @ still in first stmfd block
116 8: movs r2, r2, lsl #31
117 ldrneb r3, [r1, #-1]!
118 ldrcsb r4, [r1, #-1]!
120 strneb r3, [r0, #-1]!
121 strcsb r4, [r0, #-1]!
123 ldmfd sp!, {r0, r4, pc}
126 ldrgtb r3, [r1, #-1]!
127 ldrgeb r4, [r1, #-1]!
129 strgtb r3, [r0, #-1]!
130 strgeb r4, [r0, #-1]!
145 .macro backward_copy_shift push pull
148 UNWIND( .save {r0, r4, lr} ) @ still in first stmfd block
152 CALGN( ands ip, r0, #31 )
153 CALGN( sbcnes r4, ip, r2 ) @ C is always set here
154 CALGN( subcc r2, r2, ip )
157 11: stmfd sp!, {r5 - r9}
161 UNWIND( .save {r0, r4, lr} )
162 UNWIND( .save {r5 - r9} ) @ in new second stmfd block
165 PLD( subs r2, r2, #96 )
166 PLD( pld [r1, #-32] )
168 PLD( pld [r1, #-64] )
169 PLD( pld [r1, #-96] )
171 12: PLD( pld [r1, #-128] )
172 13: ldmdb r1!, {r7, r8, r9, ip}
173 mov lr, r3, lspush #\push
175 ldmdb r1!, {r3, r4, r5, r6}
176 orr lr, lr, ip, lspull #\pull
177 mov ip, ip, lspush #\push
178 orr ip, ip, r9, lspull #\pull
179 mov r9, r9, lspush #\push
180 orr r9, r9, r8, lspull #\pull
181 mov r8, r8, lspush #\push
182 orr r8, r8, r7, lspull #\pull
183 mov r7, r7, lspush #\push
184 orr r7, r7, r6, lspull #\pull
185 mov r6, r6, lspush #\push
186 orr r6, r6, r5, lspull #\pull
187 mov r5, r5, lspush #\push
188 orr r5, r5, r4, lspull #\pull
189 mov r4, r4, lspush #\push
190 orr r4, r4, r3, lspull #\pull
191 stmdb r0!, {r4 - r9, ip, lr}
197 UNWIND( .fnend ) @ end of the second stmfd block
200 UNWIND( .save {r0, r4, lr} ) @ still in first stmfd block
205 15: mov lr, r3, lspush #\push
208 orr lr, lr, r3, lspull #\pull
214 16: add r1, r1, #(\pull / 8)
221 backward_copy_shift push=8 pull=24
223 17: backward_copy_shift push=16 pull=16
225 18: backward_copy_shift push=24 pull=8