]> git.ipfire.org Git - thirdparty/glibc.git/commit
x86: Optimize memrchr-avx2.S
authorNoah Goldstein <goldstein.w.n@gmail.com>
Tue, 7 Jun 2022 04:11:32 +0000 (21:11 -0700)
committerSunil K Pandey <skpgkp2@gmail.com>
Tue, 19 Jul 2022 03:45:21 +0000 (20:45 -0700)
commitb05bd59823bcedee281d3fd5bd4928698ea9d69d
treee9f093f5d7fe2603979c343c44114fa9d43eabaf
parent83a986e9fbc301e6056dbc9d9ec6888621b60f67
x86: Optimize memrchr-avx2.S

The new code:
    1. prioritizes smaller user-arg lengths more.
    2. optimizes target placement more carefully
    3. reuses logic more
    4. fixes up various inefficiencies in the logic. The biggest
       case here is the `lzcnt` logic for checking returns which
       saves either a branch or multiple instructions.

The total code size saving is: 306 bytes
Geometric Mean of all benchmarks New / Old: 0.760

Regressions:
There are some regressions. Particularly where the length (user arg
length) is large but the position of the match char is near the
beginning of the string (in first VEC). This case has roughly a
10-20% regression.

This is because the new logic gives the hot path for immediate matches
to shorter lengths (the more common input). This case has roughly
a 15-45% speedup.

Full xcheck passes on x86_64.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
(cherry picked from commit af5306a735eb0966fdc2f8ccdafa8888e2df0c87)
sysdeps/x86_64/multiarch/memrchr-avx2-rtm.S
sysdeps/x86_64/multiarch/memrchr-avx2.S