// memset.S: an AArch64 memset built the same way as memcpy_neon. // // void *memset_neon(void *dst, int c, size_t n); // // 0..15 scalar stores of the byte replicated across x6 // 16..64 two to four overlapping Q stores // 65..128 four Q-register pairs, two from each end // 129+ align to 16, 64 bytes per iteration, last 64 from the end // // The 65..128 class exists because a 64-byte loop starting at the first // aligned address can run past the end of a buffer shorter than 80 bytes. .text .p2align 6 .global memset_neon .type memset_neon, %function memset_neon: dup v0.16b, w1 add x5, x0, x2 // end cmp x2, #16 b.lo .Lset0_15 cmp x2, #64 b.hi .Lset65 str q0, [x0] // 16..64 str q0, [x5, #-16] cmp x2, #32 b.ls .Lreturn str q0, [x0, #16] str q0, [x5, #-32] .Lreturn: ret .Lset0_15: fmov x6, d0 // the byte, eight times tbz x2, #3, .Lset0_7 str x6, [x0] // 8..15 str x6, [x5, #-8] ret .Lset0_7: tbz x2, #2, .Lset0_3 str w6, [x0] // 4..7 str w6, [x5, #-4] ret .Lset0_3: cbz x2, .Lreturn strb w6, [x0] // 1..3 tbz x2, #1, .Lreturn strh w6, [x5, #-2] ret .Lset65: cmp x2, #128 b.hi .Lset_long stp q0, q0, [x0] // 65..128 stp q0, q0, [x0, #32] stp q0, q0, [x5, #-64] stp q0, q0, [x5, #-32] ret .Lset_long: str q0, [x0] // unaligned head bic x6, x0, #15 add x6, x6, #16 // first aligned address past dst sub x7, x5, #64 .Lloop64: stp q0, q0, [x6] stp q0, q0, [x6, #32] add x6, x6, #64 cmp x6, x7 b.lo .Lloop64 stp q0, q0, [x5, #-64] // the last 64 bytes, from the end stp q0, q0, [x5, #-32] ret .size memset_neon, . - memset_neon