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.

1 branch · 0 tags History
README.md

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.

Sizememcpymemset
0–3first, middle and last bytefirst byte, then a halfword from the end
4–7two overlapping W movestwo overlapping W stores
8–15two overlapping X movestwo overlapping X stores
16two X movestwo Q stores to the same 16 bytes
17–32two overlapping Q movestwo overlapping Q stores
33–64two Q pairs, one from each endfour overlapping Q stores
65–128four Q pairs, two from each endfour 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 endthe 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 ZVA path for large zero fills. It needs a DCZID_EL0 read to learn the block size.
  • SVE versions. The size classes should carry over, with whilelo replacing the overlapping tails.