neon-mem
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.
| Size | memcpy | memset |
|---|---|---|
| 0–3 | first, middle and last byte | first byte, then a halfword from the end |
| 4–7 | two overlapping W moves | two overlapping W stores |
| 8–15 | two overlapping X moves | two overlapping X stores |
| 16 | two X moves | two Q stores to the same 16 bytes |
| 17–32 | two overlapping Q moves | two overlapping Q stores |
| 33–64 | two Q pairs, one from each end | four overlapping Q stores |
| 65–128 | four Q pairs, two from each end | four Q pairs, two from each end |
| 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 |
Both follow AAPCS64 and touch only registers the caller does not expect to keep, so neither saves anything.
Test
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.
It is the test that found the 65–79 byte overrun in the first memset loop.
Not yet
- A
DC ZVApath for large zero fills. It needs aDCZID_EL0read to learn the block size. - SVE versions. The size classes should carry over, with
whileloreplacing the overlapping tails.