[PATCH v2] aarch64: add optimised strspn/strcspn

Wilco Dijkstra Wilco.Dijkstra@arm.com
Wed Aug 27 14:40:51 GMT 2025


Hi Florian/remph,

> +     /* Align beginning of function to a multiple of 32 but not 64 */
> +     .text
> +     .balign 64
> +     .nop
> +     .balign 32
> +#ifndef USE_AS_STRCSPN
> +     nop     /* Better before the start than after */
> +     nop
> +#endif
> +ENTRY_ALIGN(STRSPN, 0)

> Isn't using ENTRY_ALIGN after the manual alignment a bit brittle?

It works, but the real issue is skipping half a cacheline at the start which
means you end up using more cachelines, and worse, they have to be
fetched immediately at the start of the function. Without it the initial
loop fits within the first cacheline, which is far better overall.

So'm happy with it without the nop/balign 32. That means there are
just 2 executed NOPs in both strcspn and strspn.

The rest of the changes look OK - another instruction removed from the
loop! I believe there are further opportunities for performance gains,
so it's best not to spend too much time on micro optimizations.

Cheers,
Wilco




More information about the Libc-alpha mailing list