[PATCH] x86-64: Implement strcmp family IFUNC selectors in C

H.J. Lu hjl.tools@gmail.com
Mon Jun 19 16:01:00 GMT 2017


On Tue, Jun 13, 2017 at 9:41 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
> Implement strcmp family IFUNC selectors in C and enable SSE4.2/AVX
> strcmp/strncmp.
>
> All internal calls within libc.so can use IFUNC on x86-64 since unlike
> x86, x86-64 supports PC-relative addressing to access the GOT entry so
> that it can call via PLT without using an extra register.  For libc.a,
> we can't use IFUNC for functions which are called before IFUNC has been
> initialized.  Use IFUNC internally reduces the icache footprint since
> libc.so and other codes in the process use the same implementations.
> This patch uses IFUNC for strcmp family functions within libc.
>
> Any comments?
>
> H.J.
> ---
>         [BZ #21572]
>         * sysdeps/x86_64/multiarch/Makefile (sysdep_routines): Add
>         strcmp-sse2, strcmp-sse4_2, strcmp-avx, strncmp-sse2,
>         strncmp-sse4_2, strncmp-avx, strcasecmp_l-sse2,
>         strcasecmp_l-sse4_2, strcasecmp_l-avx, strncase_l-sse2,
>         strncase_l-sse4_2 and strncase_l-avx.
>         * sysdeps/x86_64/multiarch/ifunc-impl-list.c
>         (__libc_ifunc_impl_list): Add tests for __strcmp_avx and
>         __strncmp_avx.
>         * sysdeps/x86_64/multiarch/ifunc-strcmp.h: New file.
>         * sysdeps/x86_64/multiarch/strcasecmp.c: Likewise.
>         * sysdeps/x86_64/multiarch/strcasecmp_l-avx.S: Likewise.
>         * sysdeps/x86_64/multiarch/strcasecmp_l-sse2.S: Likewise.
>         * sysdeps/x86_64/multiarch/strcasecmp_l-sse4_2.S: Likewise.
>         * sysdeps/x86_64/multiarch/strcasecmp_l.c: Likewise.
>         * sysdeps/x86_64/multiarch/strcmp-avx.S: Likewise.
>         * sysdeps/x86_64/multiarch/strcmp-sse2.S: Likewise.
>         * sysdeps/x86_64/multiarch/strcmp-sse4_2.S: Likewise.
>         * sysdeps/x86_64/multiarch/strcmp.c: Likewise.
>         * sysdeps/x86_64/multiarch/strncase.c: Likewise.
>         * sysdeps/x86_64/multiarch/strncase_l-avx.S : Likewise.
>         * sysdeps/x86_64/multiarch/strncase_l-sse2.S: Likewise.
>         * sysdeps/x86_64/multiarch/strncase_l-sse4_2.S: Likewise.
>         * sysdeps/x86_64/multiarch/strncase_l.c: Likewise.
>         * sysdeps/x86_64/multiarch/strncmp-avx.S: Likewise.
>         * sysdeps/x86_64/multiarch/strncmp-sse2.S: Likewise.
>         * sysdeps/x86_64/multiarch/strncmp-sse4_2.S: Likewise.
>         * sysdeps/x86_64/multiarch/strncmp.c: Likewise.
>         * sysdeps/x86_64/multiarch/strcasecmp_l.S: Removed.
>         * sysdeps/x86_64/multiarch/strcmp.S: Likewise.
>         * sysdeps/x86_64/multiarch/strncase_l.S: Likewise.
>         * sysdeps/x86_64/multiarch/strncmp.S: Likewise.
>         * sysdeps/x86_64/multiarch/strcmp-sse42.S: Include <sysdep.h>.
>         (STRCMP_SSE42): New.  Defined to __strcmp_sse42 if not defined.
>         [USE_AS_STRCASECMP_L || USE_AS_STRNCASECMP_L]: Include
>         "locale-defines.h".
>         (UPDATE_STRNCMP_COUNTER): New.
>         (SECTION): Likewise.
>         (GLABEL): Likewise.
>         (LABEL): Likewise.
>         * sysdeps/x86_64/multiarch/strncmp-ssse3.S: Rewrite and enable
>         for libc.a

I collected data with bench-strcmp.  There are rooms for improvement
with AVX2.  Here is the updated patch without the fix for [BZ #21572].
We will look into improving strcmp family functions with AVX2 after 2.26
is released.

Any comments?

-- 
H.J.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-x86-64-Implement-strcmp-family-IFUNC-selectors-in-C.patch
Type: text/x-patch
Size: 41642 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20170619/6a140e63/attachment.bin>


More information about the Libc-alpha mailing list