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.

README: every size class, and the test that found the memset overrun

Browse files
yuki-itocommitted 1 parent c06c506 commit 1a21c95af23713a457b7c3fff73aa4fa93bc0a25
failing 4 steps in 2 ms
1 file changed +23−9
modified README.md +23−9
@@ -1,13 +1,27 @@
11 # neon-mem
22
3−`memcpy` for AArch64, written around one idea: never loop over a byte count you can cover with two overlapping loads and stores.
3+`memcpy` and `memset` for AArch64, written around one idea: never loop over a byte count you can cover with a few overlapping loads and stores.
44
5−| Size | memcpy |
6−|---|---|
7−| 0–3 | first, middle and last byte |
8−| 4–7 | two overlapping W moves |
9−| 8–16 | two overlapping X moves |
10−| 17–32 | two overlapping Q moves |
11−| 33+ | a 16-byte Q loop, then the last 16 from the end |
5+| Size | memcpy | memset |
6+|---|---|---|
7+| 0–3 | first, middle and last byte | first byte, then a halfword from the end |
8+| 4–7 | two overlapping W moves | two overlapping W stores |
9+| 8–15 | two overlapping X moves | two overlapping X stores |
10+| 16 | two X moves | two Q stores to the same 16 bytes |
11+| 17–32 | two overlapping Q moves | two overlapping Q stores |
12+| 33–64 | two Q pairs, one from each end | four overlapping Q stores |
13+| 65–128 | four Q pairs, two from each end | four Q pairs, two from each end |
14+| 129+ | first 16 bytes, a 64-byte LDP/STP loop on the aligned part of dst, then the last 64 from the end | the same, with STP only |
1215
13−`memset` comes next, built the same way.
16+Both follow AAPCS64 and touch only registers the caller does not expect to keep, so neither saves anything.
17+
18+## Test
19+
20+Every build runs `test/sizes.c` on Linux: both routines, every size from 0 to 1,024 at all 64 destination alignments, with guard bytes on both sides of the buffer. It is freestanding, with no libc for the target, and talks to Linux through `svc`. On a builder that is not an Arm machine it runs under qemu-aarch64.
21+
22+It is the test that found the 65–79 byte overrun in the first `memset` loop.
23+
24+## Not yet
25+
26+- A `DC ZVA` path for large zero fills. It needs a `DCZID_EL0` read to learn the block size.
27+- SVE versions. The size classes should carry over, with `whilelo` replacing the overlapping tails.