x86: Optimize and shrink st{r|p}{n}{cat|cpy}-avx2 functions
commit642933158e7cf072d873231b1a9bb03291f2b989
authorNoah Goldstein <goldstein.w.n@gmail.com>
Wed, 9 Nov 2022 01:38:39 +0000 (8 17:38 -0800)
committerNoah Goldstein <goldstein.w.n@gmail.com>
Wed, 9 Nov 2022 03:22:33 +0000 (8 19:22 -0800)
tree352c3956cef706e683d0ac26ef85d165d1adcceb
parentf049f52dfeed8129c11ab1641a815705d09ff7e8
x86: Optimize and shrink st{r|p}{n}{cat|cpy}-avx2 functions

Optimizations are:
    1. Use more overlapping stores to avoid branches.
    2. Reduce how unrolled the aligning copies are (this is more of a
       code-size save, its a negative for some sizes in terms of
       perf).
    3. For st{r|p}n{cat|cpy} re-order the branches to minimize the
       number that are taken.

Performance Changes:

    Times are from N = 10 runs of the benchmark suite and are
    reported as geometric mean of all ratios of
    New Implementation / Old Implementation.

    strcat-avx2      -> 0.998
    strcpy-avx2      -> 0.937
    stpcpy-avx2      -> 0.971

    strncpy-avx2     -> 0.793
    stpncpy-avx2     -> 0.775

    strncat-avx2     -> 0.962

Code Size Changes:
    function         -> Bytes New / Bytes Old -> Ratio

    strcat-avx2      ->  685 / 1639 -> 0.418
    strcpy-avx2      ->  560 /  903 -> 0.620
    stpcpy-avx2      ->  592 /  939 -> 0.630

    strncpy-avx2     -> 1176 / 2390 -> 0.492
    stpncpy-avx2     -> 1268 / 2438 -> 0.520

    strncat-avx2     -> 1042 / 2563 -> 0.407

Notes:
    1. Because of the significant difference between the
       implementations they are split into three files.

           strcpy-avx2.S    -> strcpy, stpcpy, strcat
           strncpy-avx2.S   -> strncpy
           strncat-avx2.S    > strncat

       I couldn't find a way to merge them without making the
       ifdefs incredibly difficult to follow.

Full check passes on x86-64 and build succeeds for all ISA levels w/
and w/o multiarch.
13 files changed:
sysdeps/x86_64/multiarch/stpcpy-avx2-rtm.S
sysdeps/x86_64/multiarch/stpncpy-avx2-rtm.S
sysdeps/x86_64/multiarch/stpncpy-avx2.S
sysdeps/x86_64/multiarch/strcat-avx2-rtm.S
sysdeps/x86_64/multiarch/strcat-avx2.S [copied from sysdeps/x86_64/multiarch/x86-avx-vecs.h with 51% similarity]
sysdeps/x86_64/multiarch/strcat-strlen-avx2.h.S [new file with mode: 0644]
sysdeps/x86_64/multiarch/strcpy-avx2-rtm.S
sysdeps/x86_64/multiarch/strcpy-avx2.S
sysdeps/x86_64/multiarch/strncat-avx2-rtm.S
sysdeps/x86_64/multiarch/strncat-avx2.S
sysdeps/x86_64/multiarch/strncpy-avx2-rtm.S
sysdeps/x86_64/multiarch/strncpy-avx2.S
sysdeps/x86_64/multiarch/x86-avx-vecs.h