1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * linux/arch/arm/lib/memmove.S
5 * Author: Nicolas Pitre
6 * Created: Sep 28, 2005
7 * Copyright: (C) MontaVista Software Inc.
10 #include <linux/linkage.h>
11 #include <asm/assembler.h>
12 #include <asm/unwind.h>
17 * Prototype: void *memmove(void *dest, const void *src, size_t n);
21 * If the memory regions don't overlap, we simply branch to memcpy which is
22 * normally a bit faster. Otherwise the copy is done going downwards. This
23 * is a transposition of the code from copy_template.S but with the copy
24 * occurring in the opposite direction.
35 stmfd sp!, {r0, r4, lr}
39 UNWIND( .save {r0, r4, lr} ) @ in first stmfd block
55 UNWIND( .save {r0, r4, lr} )
56 UNWIND( .save {r5 - r8} ) @ in second stmfd block
59 CALGN( ands ip, r0, #31 )
60 CALGN( sbcsne r4, ip, r2 ) @ C is always set here
63 CALGN( subs r2, r2, ip ) @ C is set here
64 CALGN( rsb ip, ip, #32 )
65 CALGN( add pc, r4, ip )
68 2: PLD( subs r2, r2, #96 )
74 3: PLD( pld [r1, #-128] )
75 4: ldmdb r1!, {r3, r4, r5, r6, r7, r8, ip, lr}
77 stmdb r0!, {r3, r4, r5, r6, r7, r8, ip, lr}
84 addne pc, pc, ip @ C is always clear here
100 W(str) r5, [r0, #-4]!
101 W(str) r6, [r0, #-4]!
102 W(str) r7, [r0, #-4]!
103 W(str) r8, [r0, #-4]!
104 W(str) lr, [r0, #-4]!
108 7: ldmfd sp!, {r5 - r8}
109 UNWIND( .fnend ) @ end of second stmfd block
112 UNWIND( .save {r0, r4, lr} ) @ still in first stmfd block
114 8: movs r2, r2, lsl #31
115 ldrbne r3, [r1, #-1]!
116 ldrbcs r4, [r1, #-1]!
118 strbne r3, [r0, #-1]!
119 strbcs r4, [r0, #-1]!
121 ldmfd sp!, {r0, r4, pc}
124 ldrbgt r3, [r1, #-1]!
125 ldrbge r4, [r1, #-1]!
127 strbgt r3, [r0, #-1]!
128 strbge r4, [r0, #-1]!
143 .macro backward_copy_shift push pull
146 UNWIND( .save {r0, r4, lr} ) @ still in first stmfd block
150 CALGN( ands ip, r0, #31 )
151 CALGN( sbcsne r4, ip, r2 ) @ C is always set here
152 CALGN( subcc r2, r2, ip )
155 11: stmfd sp!, {r5 - r9}
159 UNWIND( .save {r0, r4, lr} )
160 UNWIND( .save {r5 - r9} ) @ in new second stmfd block
163 PLD( subs r2, r2, #96 )
164 PLD( pld [r1, #-32] )
166 PLD( pld [r1, #-64] )
167 PLD( pld [r1, #-96] )
169 12: PLD( pld [r1, #-128] )
170 13: ldmdb r1!, {r7, r8, r9, ip}
171 mov lr, r3, lspush #\push
173 ldmdb r1!, {r3, r4, r5, r6}
174 orr lr, lr, ip, lspull #\pull
175 mov ip, ip, lspush #\push
176 orr ip, ip, r9, lspull #\pull
177 mov r9, r9, lspush #\push
178 orr r9, r9, r8, lspull #\pull
179 mov r8, r8, lspush #\push
180 orr r8, r8, r7, lspull #\pull
181 mov r7, r7, lspush #\push
182 orr r7, r7, r6, lspull #\pull
183 mov r6, r6, lspush #\push
184 orr r6, r6, r5, lspull #\pull
185 mov r5, r5, lspush #\push
186 orr r5, r5, r4, lspull #\pull
187 mov r4, r4, lspush #\push
188 orr r4, r4, r3, lspull #\pull
189 stmdb r0!, {r4 - r9, ip, lr}
195 UNWIND( .fnend ) @ end of the second stmfd block
198 UNWIND( .save {r0, r4, lr} ) @ still in first stmfd block
203 15: mov lr, r3, lspush #\push
206 orr lr, lr, r3, lspull #\pull
212 16: add r1, r1, #(\pull / 8)
219 backward_copy_shift push=8 pull=24
221 17: backward_copy_shift push=16 pull=16
223 18: backward_copy_shift push=24 pull=8