2
* Copyright (C) 2008 The Android Open Source Project
5
* Redistribution and use in source and binary forms, with or without
6
* 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.
10
* * Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in
12
* the documentation and/or other materials provided with the
15
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30
* This code assumes it is running on a processor that supports all arm v7
31
* instructions, that supports neon instructions, and that has a 32 byte
38
#define CACHE_LINE_SIZE 32
41
.type memcpy,%function
45
/* start preloading as early as possible */
46
pld [r1, #(CACHE_LINE_SIZE * 0)]
48
pld [r1, #(CACHE_LINE_SIZE * 2)]
50
// Check so divider is at least 16 bytes, needed for alignment code.
55
/* check if buffers are aligned. If so, run arm-only version */
60
/* Check the upper size limit for Neon unaligned memory access in memcpy */
64
/* align destination to 16 bytes for the write-buffer */
69
/* copy up to 15-bytes (count in r3) */
80
// copies 4 bytes, destination 32-bits aligned
81
vld1.32 {d0[0]}, [r1]!
82
vst1.32 {d0[0]}, [r0, :32]!
84
// copies 8 bytes, destination 64-bits aligned
86
vst1.8 {d0}, [r0, :64]!
88
/* preload immediately the next cache line, which we may need */
89
pld [r1, #(CACHE_LINE_SIZE * 0)]
90
pld [r1, #(CACHE_LINE_SIZE * 2)]
92
/* make sure we have at least 64 bytes to copy */
96
/* preload all the cache lines we need */
97
pld [r1, #(CACHE_LINE_SIZE * 4)]
98
pld [r1, #(CACHE_LINE_SIZE * 6)]
100
1: /* The main loop copies 64 bytes at a time */
101
vld1.8 {d0 - d3}, [r1]!
102
vld1.8 {d4 - d7}, [r1]!
103
pld [r1, #(CACHE_LINE_SIZE * 6)]
105
vst1.8 {d0 - d3}, [r0]!
106
vst1.8 {d4 - d7}, [r0]!
109
2: /* fix-up the remaining count and make sure we have >= 32 bytes left */
114
3: /* 32 bytes at a time. These cache lines were already preloaded */
115
vld1.8 {d0 - d3}, [r1]!
117
vst1.8 {d0 - d3}, [r0]!
120
4: /* less than 32 left */
124
// copies 16 bytes, 128-bits aligned
125
vld1.8 {d0, d1}, [r1]!
126
vst1.8 {d0, d1}, [r0]!
127
5: /* copy up to 15-bytes (count in r2) */
133
vld1.32 {d0[0]}, [r1]!
134
vst1.32 {d0[0]}, [r0]!
135
2: movs ip, r2, lsl #31
146
/* Simple arm-only copy loop to handle aligned copy operations */
147
stmfd sp!, {r4, r5, r6, r7, r8}
148
pld [r1, #(CACHE_LINE_SIZE * 4)]
150
/* Check alignment */
155
/* align source to 32 bits. We need to insert 2 instructions between
156
* a ldr[b|h] and str[b|h] because byte and half-word instructions
159
movs r12, r3, lsl #31
160
sub r2, r2, r3 /* we know that r3 <= r2 because r2 >= 4 */
172
3: /* Main copy loop, copying 64 bytes at a time */
173
pld [r1, #(CACHE_LINE_SIZE * 8)]
174
ldmia r1!, {r3, r4, r5, r6, r7, r8, r12, lr}
175
stmia r0!, {r3, r4, r5, r6, r7, r8, r12, lr}
176
ldmia r1!, {r3, r4, r5, r6, r7, r8, r12, lr}
177
stmia r0!, {r3, r4, r5, r6, r7, r8, r12, lr}
181
4: /* Check if there are > 32 bytes left */
187
ldmia r1!, {r3, r4, r5, r6, r7, r8, r12, lr}
188
stmia r0!, {r3, r4, r5, r6, r7, r8, r12, lr}
191
5: /* Handle any remaining bytes */
195
movs r12, r2, lsl #28
196
ldmcsia r1!, {r3, r4, r5, r6} /* 16 bytes */
197
ldmmiia r1!, {r7, r8} /* 8 bytes */
198
stmcsia r0!, {r3, r4, r5, r6}
199
stmmiia r0!, {r7, r8}
200
movs r12, r2, lsl #30
201
ldrcs r3, [r1], #4 /* 4 bytes */
202
ldrmih r4, [r1], #2 /* 2 bytes */
206
ldrneb r3, [r1] /* last byte */
209
ldmfd sp!, {r4, r5, r6, r7, r8}
212
.size memcpy, .-memcpy