blob: 3114c7eba1dba65416331f7fc3f0eb0f4d13fd3a [file] [log] [blame]
Gabe Black7a6651c2013-07-07 14:15:22 -07001/*
2 * linux/arch/arm/lib/memmove.S
3 *
4 * Author: Nicolas Pitre
5 * Created: Sep 28, 2005
6 * Copyright: (C) MontaVista Software Inc.
7 *
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.
Martin Roth4af58862016-01-21 13:15:16 -070011 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Gabe Black7a6651c2013-07-07 14:15:22 -070016 */
17
Julius Wernerd65e2142013-12-13 12:59:57 -080018#include <arch/asm.h>
19#include "asmlib.h"
Gabe Black7a6651c2013-07-07 14:15:22 -070020
Gabe Black7a6651c2013-07-07 14:15:22 -070021/*
22 * Prototype: void *memmove(void *dest, const void *src, size_t n);
23 *
24 * Note:
25 *
26 * If the memory regions don't overlap, we simply branch to memcpy which is
27 * normally a bit faster. Otherwise the copy is done going downwards. This
28 * is a transposition of the code from copy_template.S but with the copy
29 * occurring in the opposite direction.
30 */
31
Julius Wernerd65e2142013-12-13 12:59:57 -080032ENTRY(memmove)
33
Gabe Black7a6651c2013-07-07 14:15:22 -070034 subs ip, r0, r1
35 cmphi r2, ip
36 bls memcpy
37
38 stmfd sp!, {r0, r4, lr}
39 add r1, r1, r2
40 add r0, r0, r2
41 subs r2, r2, #4
42 blt 8f
43 ands ip, r0, #3
44 PLD( pld [r1, #-4] )
45 bne 9f
46 ands ip, r1, #3
47 bne 10f
48
491: subs r2, r2, #(28)
50 stmfd sp!, {r5 - r8}
51 blt 5f
52
53 CALGN( ands ip, r0, #31 )
54 CALGN( sbcnes r4, ip, r2 ) @ C is always set here
55 CALGN( bcs 2f )
56 CALGN( adr r4, 6f )
57 CALGN( subs r2, r2, ip ) @ C is set here
58 CALGN( rsb ip, ip, #32 )
59 CALGN( add pc, r4, ip )
60
61 PLD( pld [r1, #-4] )
622: PLD( subs r2, r2, #96 )
63 PLD( pld [r1, #-32] )
64 PLD( blt 4f )
65 PLD( pld [r1, #-64] )
66 PLD( pld [r1, #-96] )
67
683: PLD( pld [r1, #-128] )
694: ldmdb r1!, {r3, r4, r5, r6, r7, r8, ip, lr}
70 subs r2, r2, #32
71 stmdb r0!, {r3, r4, r5, r6, r7, r8, ip, lr}
72 bge 3b
73 PLD( cmn r2, #96 )
74 PLD( bge 4b )
75
765: ands ip, r2, #28
77 rsb ip, ip, #32
78 addne pc, pc, ip @ C is always clear here
79 b 7f
806: W(nop)
81 W(ldr) r3, [r1, #-4]!
82 W(ldr) r4, [r1, #-4]!
83 W(ldr) r5, [r1, #-4]!
84 W(ldr) r6, [r1, #-4]!
85 W(ldr) r7, [r1, #-4]!
86 W(ldr) r8, [r1, #-4]!
87 W(ldr) lr, [r1, #-4]!
88
89 add pc, pc, ip
90 nop
91 W(nop)
92 W(str) r3, [r0, #-4]!
93 W(str) r4, [r0, #-4]!
94 W(str) r5, [r0, #-4]!
95 W(str) r6, [r0, #-4]!
96 W(str) r7, [r0, #-4]!
97 W(str) r8, [r0, #-4]!
98 W(str) lr, [r0, #-4]!
99
100 CALGN( bcs 2b )
101
1027: ldmfd sp!, {r5 - r8}
103
1048: movs r2, r2, lsl #31
105 ldrneb r3, [r1, #-1]!
106 ldrcsb r4, [r1, #-1]!
107 ldrcsb ip, [r1, #-1]
108 strneb r3, [r0, #-1]!
109 strcsb r4, [r0, #-1]!
110 strcsb ip, [r0, #-1]
111 ldmfd sp!, {r0, r4, pc}
112
1139: cmp ip, #2
114 ldrgtb r3, [r1, #-1]!
115 ldrgeb r4, [r1, #-1]!
116 ldrb lr, [r1, #-1]!
117 strgtb r3, [r0, #-1]!
118 strgeb r4, [r0, #-1]!
119 subs r2, r2, ip
120 strb lr, [r0, #-1]!
121 blt 8b
122 ands ip, r1, #3
123 beq 1b
124
12510: bic r1, r1, #3
126 cmp ip, #2
127 ldr r3, [r1, #0]
128 beq 17f
129 blt 18f
130
131
132 .macro backward_copy_shift push pull
133
134 subs r2, r2, #28
135 blt 14f
136
137 CALGN( ands ip, r0, #31 )
138 CALGN( sbcnes r4, ip, r2 ) @ C is always set here
139 CALGN( subcc r2, r2, ip )
140 CALGN( bcc 15f )
141
14211: stmfd sp!, {r5 - r9}
143
144 PLD( pld [r1, #-4] )
145 PLD( subs r2, r2, #96 )
146 PLD( pld [r1, #-32] )
147 PLD( blt 13f )
148 PLD( pld [r1, #-64] )
149 PLD( pld [r1, #-96] )
150
15112: PLD( pld [r1, #-128] )
15213: ldmdb r1!, {r7, r8, r9, ip}
153 mov lr, r3, push #\push
154 subs r2, r2, #32
155 ldmdb r1!, {r3, r4, r5, r6}
156 orr lr, lr, ip, pull #\pull
157 mov ip, ip, push #\push
158 orr ip, ip, r9, pull #\pull
159 mov r9, r9, push #\push
160 orr r9, r9, r8, pull #\pull
161 mov r8, r8, push #\push
162 orr r8, r8, r7, pull #\pull
163 mov r7, r7, push #\push
164 orr r7, r7, r6, pull #\pull
165 mov r6, r6, push #\push
166 orr r6, r6, r5, pull #\pull
167 mov r5, r5, push #\push
168 orr r5, r5, r4, pull #\pull
169 mov r4, r4, push #\push
170 orr r4, r4, r3, pull #\pull
171 stmdb r0!, {r4 - r9, ip, lr}
172 bge 12b
173 PLD( cmn r2, #96 )
174 PLD( bge 13b )
175
176 ldmfd sp!, {r5 - r9}
177
17814: ands ip, r2, #28
179 beq 16f
180
18115: mov lr, r3, push #\push
182 ldr r3, [r1, #-4]!
183 subs ip, ip, #4
184 orr lr, lr, r3, pull #\pull
185 str lr, [r0, #-4]!
186 bgt 15b
187 CALGN( cmp r2, #0 )
188 CALGN( bge 11b )
189
19016: add r1, r1, #(\pull / 8)
191 b 8b
192
193 .endm
194
195
196 backward_copy_shift push=8 pull=24
197
19817: backward_copy_shift push=16 pull=16
199
20018: backward_copy_shift push=24 pull=8
Julius Wernerd65e2142013-12-13 12:59:57 -0800201
202ENDPROC(memmove)