4 * Copyright(c) 2015 RehiveTech. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of RehiveTech nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #ifndef _RTE_MEMCPY_ARM32_H_
34 #define _RTE_MEMCPY_ARM32_H_
43 #include "generic/rte_memcpy.h"
47 /* ARM NEON Intrinsics are used to copy data */
51 rte_mov16(uint8_t *dst, const uint8_t *src)
53 vst1q_u8(dst, vld1q_u8(src));
57 rte_mov32(uint8_t *dst, const uint8_t *src)
60 "vld1.8 {d0-d3}, [%0]\n\t"
61 "vst1.8 {d0-d3}, [%1]\n\t"
62 : "+r" (src), "+r" (dst)
63 : : "memory", "d0", "d1", "d2", "d3");
67 rte_mov48(uint8_t *dst, const uint8_t *src)
70 "vld1.8 {d0-d3}, [%0]!\n\t"
71 "vld1.8 {d4-d5}, [%0]\n\t"
72 "vst1.8 {d0-d3}, [%1]!\n\t"
73 "vst1.8 {d4-d5}, [%1]\n\t"
74 : "+r" (src), "+r" (dst)
76 : "memory", "d0", "d1", "d2", "d3", "d4", "d5");
80 rte_mov64(uint8_t *dst, const uint8_t *src)
83 "vld1.8 {d0-d3}, [%0]!\n\t"
84 "vld1.8 {d4-d7}, [%0]\n\t"
85 "vst1.8 {d0-d3}, [%1]!\n\t"
86 "vst1.8 {d4-d7}, [%1]\n\t"
87 : "+r" (src), "+r" (dst)
89 : "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7");
93 rte_mov128(uint8_t *dst, const uint8_t *src)
95 asm volatile ("pld [%0, #64]" : : "r" (src));
97 "vld1.8 {d0-d3}, [%0]!\n\t"
98 "vld1.8 {d4-d7}, [%0]!\n\t"
99 "vld1.8 {d8-d11}, [%0]!\n\t"
100 "vld1.8 {d12-d15}, [%0]\n\t"
101 "vst1.8 {d0-d3}, [%1]!\n\t"
102 "vst1.8 {d4-d7}, [%1]!\n\t"
103 "vst1.8 {d8-d11}, [%1]!\n\t"
104 "vst1.8 {d12-d15}, [%1]\n\t"
105 : "+r" (src), "+r" (dst)
107 : "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
108 "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15");
112 rte_mov256(uint8_t *dst, const uint8_t *src)
114 asm volatile ("pld [%0, #64]" : : "r" (src));
115 asm volatile ("pld [%0, #128]" : : "r" (src));
116 asm volatile ("pld [%0, #192]" : : "r" (src));
117 asm volatile ("pld [%0, #256]" : : "r" (src));
118 asm volatile ("pld [%0, #320]" : : "r" (src));
119 asm volatile ("pld [%0, #384]" : : "r" (src));
120 asm volatile ("pld [%0, #448]" : : "r" (src));
122 "vld1.8 {d0-d3}, [%0]!\n\t"
123 "vld1.8 {d4-d7}, [%0]!\n\t"
124 "vld1.8 {d8-d11}, [%0]!\n\t"
125 "vld1.8 {d12-d15}, [%0]!\n\t"
126 "vld1.8 {d16-d19}, [%0]!\n\t"
127 "vld1.8 {d20-d23}, [%0]!\n\t"
128 "vld1.8 {d24-d27}, [%0]!\n\t"
129 "vld1.8 {d28-d31}, [%0]\n\t"
130 "vst1.8 {d0-d3}, [%1]!\n\t"
131 "vst1.8 {d4-d7}, [%1]!\n\t"
132 "vst1.8 {d8-d11}, [%1]!\n\t"
133 "vst1.8 {d12-d15}, [%1]!\n\t"
134 "vst1.8 {d16-d19}, [%1]!\n\t"
135 "vst1.8 {d20-d23}, [%1]!\n\t"
136 "vst1.8 {d24-d27}, [%1]!\n\t"
137 "vst1.8 {d28-d31}, [%1]!\n\t"
138 : "+r" (src), "+r" (dst)
140 : "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
141 "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15",
142 "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23",
143 "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31");
146 #define rte_memcpy(dst, src, n) \
147 ({ (__builtin_constant_p(n)) ? \
148 memcpy((dst), (src), (n)) : \
149 rte_memcpy_func((dst), (src), (n)); })
152 rte_memcpy_func(void *dst, const void *src, size_t n)
156 /* We can't copy < 16 bytes using XMM registers so do it manually. */
159 *(uint8_t *)dst = *(const uint8_t *)src;
160 dst = (uint8_t *)dst + 1;
161 src = (const uint8_t *)src + 1;
164 *(uint16_t *)dst = *(const uint16_t *)src;
165 dst = (uint16_t *)dst + 1;
166 src = (const uint16_t *)src + 1;
169 *(uint32_t *)dst = *(const uint32_t *)src;
170 dst = (uint32_t *)dst + 1;
171 src = (const uint32_t *)src + 1;
174 /* ARMv7 can not handle unaligned access to long long
175 * (uint64_t). Therefore two uint32_t operations are
178 *(uint32_t *)dst = *(const uint32_t *)src;
179 dst = (uint32_t *)dst + 1;
180 src = (const uint32_t *)src + 1;
181 *(uint32_t *)dst = *(const uint32_t *)src;
186 /* Special fast cases for <= 128 bytes */
188 rte_mov16((uint8_t *)dst, (const uint8_t *)src);
189 rte_mov16((uint8_t *)dst - 16 + n,
190 (const uint8_t *)src - 16 + n);
195 rte_mov32((uint8_t *)dst, (const uint8_t *)src);
196 rte_mov32((uint8_t *)dst - 32 + n,
197 (const uint8_t *)src - 32 + n);
202 rte_mov64((uint8_t *)dst, (const uint8_t *)src);
203 rte_mov64((uint8_t *)dst - 64 + n,
204 (const uint8_t *)src - 64 + n);
209 * For large copies > 128 bytes. This combination of 256, 64 and 16 byte
210 * copies was found to be faster than doing 128 and 32 byte copies as
213 for ( ; n >= 256; n -= 256) {
214 rte_mov256((uint8_t *)dst, (const uint8_t *)src);
215 dst = (uint8_t *)dst + 256;
216 src = (const uint8_t *)src + 256;
220 * We split the remaining bytes (which will be less than 256) into
221 * 64byte (2^6) chunks.
222 * Using incrementing integers in the case labels of a switch statement
223 * enourages the compiler to use a jump table. To get incrementing
224 * integers, we shift the 2 relevant bits to the LSB position to first
225 * get decrementing integers, and then subtract.
227 switch (3 - (n >> 6)) {
229 rte_mov64((uint8_t *)dst, (const uint8_t *)src);
231 dst = (uint8_t *)dst + 64;
232 src = (const uint8_t *)src + 64; /* fallthrough */
234 rte_mov64((uint8_t *)dst, (const uint8_t *)src);
236 dst = (uint8_t *)dst + 64;
237 src = (const uint8_t *)src + 64; /* fallthrough */
239 rte_mov64((uint8_t *)dst, (const uint8_t *)src);
241 dst = (uint8_t *)dst + 64;
242 src = (const uint8_t *)src + 64; /* fallthrough */
248 * We split the remaining bytes (which will be less than 64) into
249 * 16byte (2^4) chunks, using the same switch structure as above.
251 switch (3 - (n >> 4)) {
253 rte_mov16((uint8_t *)dst, (const uint8_t *)src);
255 dst = (uint8_t *)dst + 16;
256 src = (const uint8_t *)src + 16; /* fallthrough */
258 rte_mov16((uint8_t *)dst, (const uint8_t *)src);
260 dst = (uint8_t *)dst + 16;
261 src = (const uint8_t *)src + 16; /* fallthrough */
263 rte_mov16((uint8_t *)dst, (const uint8_t *)src);
265 dst = (uint8_t *)dst + 16;
266 src = (const uint8_t *)src + 16; /* fallthrough */
271 /* Copy any remaining bytes, without going beyond end of buffers */
273 rte_mov16((uint8_t *)dst - 16 + n,
274 (const uint8_t *)src - 16 + n);
281 rte_mov16(uint8_t *dst, const uint8_t *src)
283 memcpy(dst, src, 16);
287 rte_mov32(uint8_t *dst, const uint8_t *src)
289 memcpy(dst, src, 32);
293 rte_mov48(uint8_t *dst, const uint8_t *src)
295 memcpy(dst, src, 48);
299 rte_mov64(uint8_t *dst, const uint8_t *src)
301 memcpy(dst, src, 64);
305 rte_mov128(uint8_t *dst, const uint8_t *src)
307 memcpy(dst, src, 128);
311 rte_mov256(uint8_t *dst, const uint8_t *src)
313 memcpy(dst, src, 256);
317 rte_memcpy(void *dst, const void *src, size_t n)
319 return memcpy(dst, src, n);
323 rte_memcpy_func(void *dst, const void *src, size_t n)
325 return memcpy(dst, src, n);
328 #endif /* __ARM_NEON_FP */
334 #endif /* _RTE_MEMCPY_ARM32_H_ */