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>
17 * This can be used to enable code to cacheline align the source pointer.
18 * Experiments on tested architectures (StrongARM and XScale) didn't show
19 * this a worthwhile thing to do. That might be different in the future.
21 //#define CALGN(code...) code
22 #define CALGN(code...)
27 * Prototype: void *memmove(void *dest, const void *src, size_t n);
31 * If the memory regions don't overlap, we simply branch to memcpy which is
32 * normally a bit faster. Otherwise the copy is done going downwards. This
33 * is a transposition of the code from copy_template.S but with the copy
34 * occurring in the opposite direction.
43 stmfd sp!, {r0, r4, lr}
58 CALGN( ands ip, r1, #31 )
59 CALGN( sbcnes r4, ip, r2 ) @ C is always set here
62 CALGN( subs r2, r2, ip ) @ C is set here
63 CALGN( add pc, r4, ip )
66 2: PLD( subs r2, r2, #96 )
72 3: PLD( pld [r1, #-128] )
73 4: ldmdb r1!, {r3, r4, r5, r6, r7, r8, ip, lr}
75 stmdb r0!, {r3, r4, r5, r6, r7, r8, ip, lr}
82 addne pc, pc, ip @ C is always clear here
106 7: ldmfd sp!, {r5 - r8}
108 8: movs r2, r2, lsl #31
109 ldrneb r3, [r1, #-1]!
110 ldrcsb r4, [r1, #-1]!
112 strneb r3, [r0, #-1]!
113 strcsb r4, [r0, #-1]!
115 ldmfd sp!, {r0, r4, pc}
118 ldrgtb r3, [r1, #-1]!
119 ldrgeb r4, [r1, #-1]!
121 strgtb r3, [r0, #-1]!
122 strgeb r4, [r0, #-1]!
136 .macro backward_copy_shift push pull
141 CALGN( ands ip, r1, #31 )
142 CALGN( rsb ip, ip, #32 )
143 CALGN( sbcnes r4, ip, r2 ) @ C is always set here
144 CALGN( subcc r2, r2, ip )
147 11: stmfd sp!, {r5 - r9}
150 PLD( subs r2, r2, #96 )
151 PLD( pld [r1, #-32] )
153 PLD( pld [r1, #-64] )
154 PLD( pld [r1, #-96] )
156 12: PLD( pld [r1, #-128] )
157 13: ldmdb r1!, {r7, r8, r9, ip}
158 mov lr, r3, push #\push
160 ldmdb r1!, {r3, r4, r5, r6}
161 orr lr, lr, ip, pull #\pull
162 mov ip, ip, push #\push
163 orr ip, ip, r9, pull #\pull
164 mov r9, r9, push #\push
165 orr r9, r9, r8, pull #\pull
166 mov r8, r8, push #\push
167 orr r8, r8, r7, pull #\pull
168 mov r7, r7, push #\push
169 orr r7, r7, r6, pull #\pull
170 mov r6, r6, push #\push
171 orr r6, r6, r5, pull #\pull
172 mov r5, r5, push #\push
173 orr r5, r5, r4, pull #\pull
174 mov r4, r4, push #\push
175 orr r4, r4, r3, pull #\pull
176 stmdb r0!, {r4 - r9, ip, lr}
186 15: mov lr, r3, push #\push
189 orr lr, lr, r3, pull #\pull
195 16: add r1, r1, #(\pull / 8)
201 backward_copy_shift push=8 pull=24
203 17: backward_copy_shift push=16 pull=16
205 18: backward_copy_shift push=24 pull=8