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.
memcpy: test for the long path second
Browse filesSizes above 128 now reach the loop after two compares instead of four. 33..128 share their first loads, one Q pair from each end, and a compare against 64 decides whether two more pairs follow. memcpy_neon is 8 bytes shorter: 276 instead of 284.
failing
4 steps in 2 ms
1 file changed
+21−25
@@ -4,9 +4,7 @@
44 //
55 // Size classes:
66 // 0..16 overlapping scalar loads from both ends, no loop
7−// 17..32 two Q registers, one from each end
8−// 33..64 two Q-register pairs, one from each end
9−// 65..128 four Q-register pairs, two from each end
7+// 17..128 one to four Q-register pairs, also from both ends
108 // 129+ align dst to 16, copy 64 bytes per iteration, finish with the
119 // last 64 bytes from the end (they may overlap the loop's work)
1210 //
@@ -21,31 +19,12 @@ memcpy_neon:
2119 add x5, x0, x2 // dst end
2220 cmp x2, #16
2321 b.ls .Lcopy0_16
24− cmp x2, #32
25− b.ls .Lcopy17_32
26− cmp x2, #64
27− b.ls .Lcopy33_64
2822 cmp x2, #128
2923 b.hi .Lcopy_long
24+ cmp x2, #32
25+ b.hi .Lcopy33_128
3026
31− ldp q0, q1, [x1] // 65..128
32− ldp q4, q5, [x1, #32]
33− ldp q6, q7, [x4, #-64]
34− ldp q2, q3, [x4, #-32]
35− stp q0, q1, [x0]
36− stp q4, q5, [x0, #32]
37− stp q6, q7, [x5, #-64]
38− stp q2, q3, [x5, #-32]
39− ret
40−
41−.Lcopy33_64:
42− ldp q0, q1, [x1]
43− ldp q2, q3, [x4, #-32]
44− stp q0, q1, [x0]
45− stp q2, q3, [x5, #-32]
46− ret
47−
48−.Lcopy17_32: // two 16-byte moves that meet in the middle
27+ // 17..32: two 16-byte moves that meet in the middle
4928 ldr q0, [x1]
5029 ldr q1, [x4, #-16]
5130 str q0, [x0]
@@ -79,6 +58,23 @@ memcpy_neon:
7958 .Lreturn:
8059 ret
8160
61+.Lcopy33_128:
62+ ldp q0, q1, [x1]
63+ ldp q2, q3, [x4, #-32]
64+ cmp x2, #64
65+ b.hi .Lcopy65_128
66+ stp q0, q1, [x0] // 33..64
67+ stp q2, q3, [x5, #-32]
68+ ret
69+.Lcopy65_128:
70+ ldp q4, q5, [x1, #32]
71+ ldp q6, q7, [x4, #-64]
72+ stp q0, q1, [x0]
73+ stp q4, q5, [x0, #32]
74+ stp q6, q7, [x5, #-64]
75+ stp q2, q3, [x5, #-32]
76+ ret
77+
8278 .Lcopy_long:
8379 ldr q0, [x1] // first 16 bytes, unaligned
8480 str q0, [x0]