1
/* Copyright (c) 2010-2011, Linaro Limited
4
Redistribution and use in source and binary forms, with or without
5
modification, are permitted provided that the following conditions
8
* Redistributions of source code must retain the above copyright
9
notice, this list of conditions and the following disclaimer.
11
* Redistributions in binary form must reproduce the above copyright
12
notice, this list of conditions and the following disclaimer in the
13
documentation and/or other materials provided with the distribution.
15
* Neither the name of Linaro Limited nor the names of its
16
contributors may be used to endorse or promote products derived
17
from this software without specific prior written permission.
19
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
Written by Dave Gilbert <david.gilbert@linaro.org>
33
This memcpy routine is optimised on a Cortex-A9 and should work on
34
all ARMv7 processors with NEON. */
36
@ 2011-09-01 david.gilbert@linaro.org
37
@ Extracted from local git 2f11b436
42
@ this lets us check a flag in a 00/ff byte easily in either endianness
44
#define CHARTSTMASK(c) 1<<(31-(c*8))
46
#define CHARTSTMASK(c) 1<<(c*8)
51
@ ---------------------------------------------------------------------------
56
.type memcpy,%function
62
@ Overlaps of source/dest not allowed according to spec
63
@ Note this routine relies on v7 misaligned loads/stores
65
mov r12, r0 @ stash original r0
67
blt 10f @ take the small copy case separately
69
@ test for either source or destination being misaligned
70
@ (We only rely on word align)
74
bne 30f @ misaligned case
77
@ at this point we are word (or better) aligned and have at least
78
@ 32 bytes to play with
80
@ If it's a huge copy, try Neon
82
bge 35f @ Sharing general non-aligned case here, aligned could be faster
84
push {r3,r4,r5,r6,r7,r8,r10,r11}
86
ldmia r1!,{r3,r4,r5,r6,r7,r8,r10,r11}
90
stmia r0!,{r3,r4,r5,r6,r7,r8,r10,r11}
93
pop {r3,r4,r5,r6,r7,r8,r10,r11}
94
@ We are now down to less than 32 bytes
95
cbz r2,15f @ quick exit for the case where we copied a multiple of 32
97
10: @ small copies (not necessarily aligned - note might be slightly more than 32bytes)
118
mov r0,r12 @ restore r0
123
30: @ non-aligned - at least 32 bytes to play with
124
@ Test for co-misalignment
129
@ Use Neon for misaligned
131
vld1.8 {d0,d1,d2,d3}, [r1]!
135
vst1.8 {d0,d1,d2,d3}, [r0]!
137
b 10b @ TODO: Probably a bad idea to switch to ARM at this point
142
@ At this point we've got at least 32 bytes