]> git.ipfire.org Git - thirdparty/glibc.git/commit
x86: Optimize memchr-evex.S and implement with VMM headers
authorNoah Goldstein <goldstein.w.n@gmail.com>
Wed, 19 Oct 2022 00:44:03 +0000 (17:44 -0700)
committerNoah Goldstein <goldstein.w.n@gmail.com>
Thu, 20 Oct 2022 00:31:03 +0000 (17:31 -0700)
commit330881763efff626d6b1cdf8de9ffee4ed7a1ba1
treebe5ed6967393bbb1b87d8ac6c1ed3cc1bdef25cd
parent451c6e58540e8571e31581c04c4829e5d2cfe8ac
x86: Optimize memchr-evex.S and implement with VMM headers

Optimizations are:

1. Use the fact that tzcnt(0) -> VEC_SIZE for memchr to save a branch
   in short string case.
2. Restructure code so that small strings are given the hot path.
- This is a net-zero on the benchmark suite but in general makes
      sense as smaller sizes are far more common.
3. Use more code-size efficient instructions.
- tzcnt ...     -> bsf ...
- vpcmpb $0 ... -> vpcmpeq ...
4. Align labels less aggressively, especially if it doesn't save fetch
   blocks / causes the basic-block to span extra cache-lines.

The optimizations (especially for point 2) make the memchr and
rawmemchr code essentially incompatible so split rawmemchr-evex
to a new file.

Code Size Changes:
memchr-evex.S       : -107 bytes
rawmemchr-evex.S    :  -53 bytes

Net perf changes:

Reported as geometric mean of all improvements / regressions from N=10
runs of the benchtests. Value as New Time / Old Time so < 1.0 is
improvement and 1.0 is regression.

memchr-evex.S       : 0.928
rawmemchr-evex.S    : 0.986 (Less targets cross cache lines)

Full results attached in email.

Full check passes on x86-64.
sysdeps/x86_64/multiarch/memchr-evex.S
sysdeps/x86_64/multiarch/rawmemchr-evex-rtm.S
sysdeps/x86_64/multiarch/rawmemchr-evex.S