memcpy and memset for AArch64, from overlapping loads and LDP/STP Q pairs. Every build checks every size up to 1,024 bytes at all 64 alignments.
memset, built the same way
Browse filesdup puts the byte in every lane of q0. Below 16 bytes it is stored from x6 as overlapping scalars, and 16..64 bytes take two to four overlapping Q stores. Above 64, the first 16 bytes go out unaligned and a 64-byte loop of STP Q pairs starts at the first 16-byte boundary past dst.
failing
2 steps in 1 ms
2 files changed
+67−1
@@ -1,4 +1,4 @@
1−# Verified builds for neon-mem: memcpy_neon, assembled for AArch64 Linux.
1+# Verified builds for neon-mem: both routines, assembled for AArch64 Linux.
22
33 [project]
44 isa = "arm64"
@@ -9,5 +9,10 @@ target = "AArch64 Linux, AAPCS64"
99 name = "assemble memcpy"
1010 run = ["clang", "--target=aarch64-linux-gnu", "-c", "-g", "-o", "build/memcpy.o", "src/memcpy.S"]
1111
12+[[step]]
13+name = "assemble memset"
14+run = ["clang", "--target=aarch64-linux-gnu", "-c", "-g", "-o", "build/memset.o", "src/memset.S"]
15+
1216 [artifact]
1317 path = "build/memcpy.o"
18+paths = ["build/memset.o"]
@@ -0,0 +1,61 @@
1+// memset.S: an AArch64 memset built the same way as memcpy_neon.
2+//
3+// void *memset_neon(void *dst, int c, size_t n);
4+//
5+// 0..15 scalar stores of the byte replicated across x6
6+// 16..64 two to four overlapping Q stores
7+// 65+ align to 16, 64 bytes per iteration, last 64 from the end
8+
9+ .text
10+ .p2align 6
11+ .global memset_neon
12+ .type memset_neon, %function
13+memset_neon:
14+ dup v0.16b, w1
15+ add x5, x0, x2 // end
16+ cmp x2, #16
17+ b.lo .Lset0_15
18+ cmp x2, #64
19+ b.hi .Lset_long
20+ str q0, [x0] // 16..64
21+ str q0, [x5, #-16]
22+ cmp x2, #32
23+ b.ls .Lreturn
24+ str q0, [x0, #16]
25+ str q0, [x5, #-32]
26+.Lreturn:
27+ ret
28+
29+.Lset0_15:
30+ fmov x6, d0 // the byte, eight times
31+ tbz x2, #3, .Lset0_7
32+ str x6, [x0] // 8..15
33+ str x6, [x5, #-8]
34+ ret
35+.Lset0_7:
36+ tbz x2, #2, .Lset0_3
37+ str w6, [x0] // 4..7
38+ str w6, [x5, #-4]
39+ ret
40+.Lset0_3:
41+ cbz x2, .Lreturn
42+ strb w6, [x0] // 1..3
43+ tbz x2, #1, .Lreturn
44+ strh w6, [x5, #-2]
45+ ret
46+
47+.Lset_long:
48+ str q0, [x0] // unaligned head
49+ bic x6, x0, #15
50+ add x6, x6, #16 // first aligned address past dst
51+ sub x7, x5, #64
52+.Lloop64:
53+ stp q0, q0, [x6]
54+ stp q0, q0, [x6, #32]
55+ add x6, x6, #64
56+ cmp x6, x7
57+ b.lo .Lloop64
58+ stp q0, q0, [x5, #-64] // the last 64 bytes, from the end
59+ stp q0, q0, [x5, #-32]
60+ ret
61+ .size memset_neon, . - memset_neon