[PATCH v3 1/3] string: add find_ne_all to string-fza.h

Wilco Dijkstra Wilco.Dijkstra@arm.com
Mon Aug 17 11:48:51 GMT 2026


Hi Matt,

> find_zero_ne_all () searches for a zero byte in X1 or a byte that differs
> between X1 and X2.  A caller that knows X2 contains no NUL byte does not
> need the zero test, since a NUL byte in X1 already differs from every
> byte of X2.
>
> Add find_ne_all (), which searches for inequality alone, to the generic
> implementation and to each target that provides its own string-fza.h.
> Dropping the zero test makes it cheaper than find_zero_ne_all () on every
> target.
>
> Return the difference unreduced wherever index_first () and index_last ()
> come from the generic string-fzi.h, which uses stdc_trailing_zeros () and
> stdc_leading_zeros () and so only needs to know which byte holds the first
> or the last set bit.  That covers armv6t2, powerpc and riscv with the
> bitmap extensions, as well as the generic implementation.  Only the
> generic one tests HAVE_BITOPTS_WORKING, since its fallback ctzb () and
> clzb () isolate a single bit and expect it at 0x80; the target masks are
> already incompatible with that fallback and cannot use it either way.
>
> riscv without the bitmap extensions takes its string-fza.h from the
> generic implementation while defining its own index_first () and
> index_last (), which tested bit 7 of each byte.  Test the whole byte
> instead, so that they accept the unreduced difference.
>
> alpha keeps a reduced form, its find_t being a cmpbge mask of one bit per
> byte throughout.

This version looks great.

Reviewed-by: Wilco Dijkstra  <Wilco.Dijkstra@arm.com>

Cheers,
Wilco


More information about the Libc-alpha mailing list