acompiled

The catalog contains seeded project examples. Your workspace stores your own projects and conversations.

yuki-ito/neon-mem

Public
Star6

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.

History
61 lines·1.8 KB·GAS AArch64 Raw Blame
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
13memset_neon:
14 dup v0.16b, w1
15 add x5, x0, x2 // end
16 cmp x2, #16
18 cmp x2, #64
20 str q0, [x0] // 16..64
21 str q0, [x5, #-16]
22 cmp x2, #32
24 str q0, [x0, #16]
25 str q0, [x5, #-32]
26.Lreturn:
27 ret
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
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
58 stp q0, q0, [x5, #-64] // the last 64 bytes, from the end
59 stp q0, q0, [x5, #-32]
60 ret