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.
34 stmfd sp!, {r0, r4, lr}
38 UNWIND( .save {r0, r4, lr} ) @ in first stmfd block
54 UNWIND( .save {r0, r4, lr} )
55 UNWIND( .save {r5 - r8} ) @ in second stmfd block
58 CALGN( ands ip, r0, #31 )
59 CALGN( sbcsne r4, ip, r2 ) @ C is always set here
62 CALGN( subs r2, r2, ip ) @ C is set here
63 CALGN( rsb ip, ip, #32 )
64 CALGN( add pc, r4, ip )
67 2: PLD( subs r2, r2, #96 )
73 3: PLD( pld [r1, #-128] )
74 4: ldmdb r1!, {r3, r4, r5, r6, r7, r8, ip, lr}
76 stmdb r0!, {r3, r4, r5, r6, r7, r8, ip, lr}
83 addne pc, pc, ip @ C is always clear here
100 W(str) r6, [r0, #-4]!
101 W(str) r7, [r0, #-4]!
102 W(str) r8, [r0, #-4]!
103 W(str) lr, [r0, #-4]!
107 7: ldmfd sp!, {r5 - r8}
108 UNWIND( .fnend ) @ end of second stmfd block
111 UNWIND( .save {r0, r4, lr} ) @ still in first stmfd block
113 8: movs r2, r2, lsl #31
114 ldrbne r3, [r1, #-1]!
115 ldrbcs r4, [r1, #-1]!
117 strbne r3, [r0, #-1]!
118 strbcs r4, [r0, #-1]!
120 ldmfd sp!, {r0, r4, pc}
123 ldrbgt r3, [r1, #-1]!
124 ldrbge r4, [r1, #-1]!
126 strbgt r3, [r0, #-1]!
127 strbge r4, [r0, #-1]!
142 .macro backward_copy_shift push pull
145 UNWIND( .save {r0, r4, lr} ) @ still in first stmfd block
149 CALGN( ands ip, r0, #31 )
150 CALGN( sbcsne r4, ip, r2 ) @ C is always set here
151 CALGN( subcc r2, r2, ip )
154 11: stmfd sp!, {r5 - r9}
158 UNWIND( .save {r0, r4, lr} )
159 UNWIND( .save {r5 - r9} ) @ in new second stmfd block
162 PLD( subs r2, r2, #96 )
163 PLD( pld [r1, #-32] )
165 PLD( pld [r1, #-64] )
166 PLD( pld [r1, #-96] )
168 12: PLD( pld [r1, #-128] )
169 13: ldmdb r1!, {r7, r8, r9, ip}
170 mov lr, r3, lspush #\push
172 ldmdb r1!, {r3, r4, r5, r6}
173 orr lr, lr, ip, lspull #\pull
174 mov ip, ip, lspush #\push
175 orr ip, ip, r9, lspull #\pull
176 mov r9, r9, lspush #\push
177 orr r9, r9, r8, lspull #\pull
178 mov r8, r8, lspush #\push
179 orr r8, r8, r7, lspull #\pull
180 mov r7, r7, lspush #\push
181 orr r7, r7, r6, lspull #\pull
182 mov r6, r6, lspush #\push
183 orr r6, r6, r5, lspull #\pull
184 mov r5, r5, lspush #\push
185 orr r5, r5, r4, lspull #\pull
186 mov r4, r4, lspush #\push
187 orr r4, r4, r3, lspull #\pull
188 stmdb r0!, {r4 - r9, ip, lr}
194 UNWIND( .fnend ) @ end of the second stmfd block
197 UNWIND( .save {r0, r4, lr} ) @ still in first stmfd block
202 15: mov lr, r3, lspush #\push
205 orr lr, lr, r3, lspull #\pull
211 16: add r1, r1, #(\pull / 8)
218 backward_copy_shift push=8 pull=24
220 17: backward_copy_shift push=16 pull=16
222 18: backward_copy_shift push=24 pull=8