1 /* Copyright (C) 2006, 2008 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 Contributed by MontaVista Software, Inc. (written by Nicolas Pitre)
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 * Data preload for architectures that support it (ARM V5TE and above)
26 #if (!defined (__ARM_ARCH_2__) && !defined (__ARM_ARCH_3__) \
27 && !defined (__ARM_ARCH_3M__) && !defined (__ARM_ARCH_4__) \
28 && !defined (__ARM_ARCH_4T__) && !defined (__ARM_ARCH_5__) \
29 && !defined (__ARM_ARCH_5T__))
30 #define PLD(code...) code
36 * This can be used to enable code to cacheline align the source pointer.
37 * Experiments on tested architectures (StrongARM and XScale) didn't show
38 * this a worthwhile thing to do. That might be different in the future.
40 //#define CALGN(code...) code
41 #define CALGN(code...)
44 * Endian independent macros for shifting bytes within registers.
57 * Prototype: void *memmove(void *dest, const void *src, size_t n);
61 * If the memory regions don't overlap, we simply branch to memcpy which is
62 * normally a bit faster. Otherwise the copy is done going downwards.
72 bls HIDDEN_JUMPTARGET(memcpy)
75 stmfd sp!, {r0, r4, lr}
90 CALGN( ands ip, r1, #31 )
91 CALGN( sbcnes r4, ip, r2 ) @ C is always set here
94 CALGN( subs r2, r2, ip ) @ C is set here
95 CALGN( add pc, r4, ip )
98 2: PLD( subs r2, r2, #96 )
101 PLD( pld [r1, #-64] )
102 PLD( pld [r1, #-96] )
104 3: PLD( pld [r1, #-128] )
105 4: ldmdb r1!, {r3, r4, r5, r6, r7, r8, ip, lr}
107 stmdb r0!, {r3, r4, r5, r6, r7, r8, ip, lr}
114 addne pc, pc, ip @ C is always clear here
138 7: ldmfd sp!, {r5 - r8}
140 8: movs r2, r2, lsl #31
141 ldrneb r3, [r1, #-1]!
142 ldrcsb r4, [r1, #-1]!
144 strneb r3, [r0, #-1]!
145 strcsb r4, [r0, #-1]!
147 ldmfd sp!, {r0, r4, pc}
150 ldrgtb r3, [r1, #-1]!
151 ldrgeb r4, [r1, #-1]!
153 strgtb r3, [r0, #-1]!
154 strgeb r4, [r0, #-1]!
168 .macro backward_copy_shift push pull
173 CALGN( ands ip, r1, #31 )
174 CALGN( rsb ip, ip, #32 )
175 CALGN( sbcnes r4, ip, r2 ) @ C is always set here
176 CALGN( subcc r2, r2, ip )
179 11: stmfd sp!, {r5 - r9}
182 PLD( subs r2, r2, #96 )
183 PLD( pld [r1, #-32] )
185 PLD( pld [r1, #-64] )
186 PLD( pld [r1, #-96] )
188 12: PLD( pld [r1, #-128] )
189 13: ldmdb r1!, {r7, r8, r9, ip}
190 mov lr, r3, push #\push
192 ldmdb r1!, {r3, r4, r5, r6}
193 orr lr, lr, ip, pull #\pull
194 mov ip, ip, push #\push
195 orr ip, ip, r9, pull #\pull
196 mov r9, r9, push #\push
197 orr r9, r9, r8, pull #\pull
198 mov r8, r8, push #\push
199 orr r8, r8, r7, pull #\pull
200 mov r7, r7, push #\push
201 orr r7, r7, r6, pull #\pull
202 mov r6, r6, push #\push
203 orr r6, r6, r5, pull #\pull
204 mov r5, r5, push #\push
205 orr r5, r5, r4, pull #\pull
206 mov r4, r4, push #\push
207 orr r4, r4, r3, pull #\pull
208 stmdb r0!, {r4 - r9, ip, lr}
218 15: mov lr, r3, push #\push
221 orr lr, lr, r3, pull #\pull
227 16: add r1, r1, #(\pull / 8)
233 backward_copy_shift push=8 pull=24
235 17: backward_copy_shift push=16 pull=16
237 18: backward_copy_shift push=24 pull=8
241 libc_hidden_builtin_def (memmove)