[PATCH 0/2] string: vectorize the strspn single-accept-character case
Matt Turner <[email protected]>
| Newsgroups | gmane.comp.lib.glibc.alpha |
|---|---|
| Message-ID | <[email protected]> |
These two patches replace "[PATCH 16/20] alpha: add vectorized single-char fast path for strspn" from the alpha series, which added a strspn to sysdeps/alpha rather than improving the generic one. Adhemerval was right that this belongs in the generic implementation, and the result is both faster and useful to every target that lacks an assembly strspn. Patch 1 adds find_ne_all (), which searches for byte inequality alone. The existing find_zero_ne_all () also searches for a zero byte in X1, which the strspn caller does not need: the accept character is not NUL there, so a NUL byte already differs from it. Dropping the zero test is worth 13-16% on an EV68CB and 1.3-1.8x on x86_64 over using find_zero_ne_all () in patch 2, so it is not just tidiness. Each target that provides its own string-fza.h needs its own version, since the mask conventions differ and a plain bitwise inverse of find_eq_all () is only correct where the mask is a full byte. Patch 2 rewrites the single-accept-character case as a word-at-a-time scan. Speedup over the byte-at-a-time loop it replaces: length 8 32 128 512 2K 8K 32K EV68CB 1.4x 3.3x 4.5x 5.7x 6.4x 6.6x 6.6x i7-1370P 0.8x 1.6x 4.3x 3.6x 2.7x 2.8x 2.9x The x86_64 numbers are for the generic C string-fza.h, which x86_64 itself only reaches where SSE4.2 is unavailable; they stand in for the targets that use the generic implementation for real. Below 16 bytes it loses under half a nanosecond per call, which I am happy to trade but can gate on a length check if anyone objects. Checked against strspn () for lengths 0 to 300 at every byte alignment on x86_64, s390x, powerpc64, arm and alpha, covering the generic, cmpb, uqsub8 and cmpbge string-fza.h implementations. The riscv orc.b one was built but not run. string/test-strspn, string/bug-strspn1 and string/test-strcspn pass on x86_64. Matt Turner (2): string: add find_ne_all to string-fza.h string: vectorize strspn single-accept-char case string/strspn.c | 27 ++++++++++++++++++++++++--- sysdeps/alpha/string-fza.h | 6 ++++++ sysdeps/arm/armv6t2/string-fza.h | 8 ++++++++ sysdeps/generic/string-fza.h | 10 ++++++++++ sysdeps/powerpc/string-fza.h | 8 ++++++++ sysdeps/riscv/string-fza.h | 7 +++++++ 6 files changed, 63 insertions(+), 3 deletions(-) -- 2.54.0