From patchwork Mon Jun 19 16:01:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 21090 Received: (qmail 107252 invoked by alias); 19 Jun 2017 16:01:13 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 107218 invoked by uid 89); 19 Jun 2017 16:01:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.3 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-ot0-f196.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=PT8ZnoDmqIVXC2LICherZv4aUL7t1dkBK2iPFeMkLRQ=; b=s7f2Et/Rl7mES097OBZhvG/IzfBUzMTSQCxalgNyh4F84UgDBPgHCRhaOzEZRs00Ih xhB4WRwXTGgMYWXiQO84IfDemfrol6dgYcof9IRc3TOeudkJw2m94oytuzdyWqfmZ5cD hJIvu2xRccJr6UVQIr7C/Iej2ca45q4U2HBq8meBzpA2iSS0mOIRzRLhwMrPCE7Ai163 39Oc3GQQa1iutT3qxASdvnO0DvjKwupGnVNJOC5qY4p85XMiLZdAh1VC392LDp2CqsoB 1ntJ7VTdIx1zRTkb5xR5YBAVpU1FYBfrVMjKL5Un/ub9CTFlGvGraykZWgN2WZMFop0/ A8iw== X-Gm-Message-State: AKS2vOxhUIcssiuxoDUX/rsTFdMHnJnoTN0X7RA9aQk7sFc1zvPNLXIN Br8SojBdQ4U2iM/e2Rd9nHdxY624M0Y4 X-Received: by 10.157.3.80 with SMTP id 74mr12264750otv.39.1497888068205; Mon, 19 Jun 2017 09:01:08 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20170613164151.GA12238@gmail.com> References: <20170613164151.GA12238@gmail.com> From: "H.J. Lu" Date: Mon, 19 Jun 2017 09:01:07 -0700 Message-ID: Subject: Re: [PATCH] x86-64: Implement strcmp family IFUNC selectors in C To: GNU C Library , "Rodriguez Bahena, Victor" On Tue, Jun 13, 2017 at 9:41 AM, H.J. Lu 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 . > (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? From 13041a24da79afcb57a4d654dafeb75e7662577e Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Mon, 12 Jun 2017 17:08:44 -0700 Subject: [PATCH] x86-64: Implement strcmp family IFUNC selectors in C Implement strcmp family IFUNC selectors in C. 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. * sysdeps/x86_64/multiarch/Makefile (sysdep_routines): Add strcmp-sse2, strcmp-sse4_2, strncmp-sse2, strncmp-sse4_2, 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-strcasecmp.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-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-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 . (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. --- sysdeps/x86_64/multiarch/Makefile | 14 +- sysdeps/x86_64/multiarch/ifunc-strcasecmp.h | 43 +++++ sysdeps/x86_64/multiarch/strcasecmp.c | 39 +++++ sysdeps/x86_64/multiarch/strcasecmp_l-avx.S | 22 +++ sysdeps/x86_64/multiarch/strcasecmp_l-sse2.S | 23 +++ sysdeps/x86_64/multiarch/strcasecmp_l-sse4_2.S | 21 +++ sysdeps/x86_64/multiarch/strcasecmp_l.S | 8 - sysdeps/x86_64/multiarch/strcasecmp_l.c | 40 +++++ sysdeps/x86_64/multiarch/strcmp-sse2.S | 28 ++++ sysdeps/x86_64/multiarch/strcmp-sse42.S | 34 ++++ sysdeps/x86_64/multiarch/strcmp-sse4_2.S | 21 +++ sysdeps/x86_64/multiarch/strcmp.S | 209 ------------------------- sysdeps/x86_64/multiarch/strcmp.c | 53 +++++++ sysdeps/x86_64/multiarch/strncase.c | 35 +++++ sysdeps/x86_64/multiarch/strncase_l-avx.S | 22 +++ sysdeps/x86_64/multiarch/strncase_l-sse2.S | 23 +++ sysdeps/x86_64/multiarch/strncase_l-sse4_2.S | 21 +++ sysdeps/x86_64/multiarch/strncase_l.S | 8 - sysdeps/x86_64/multiarch/strncase_l.c | 40 +++++ sysdeps/x86_64/multiarch/strncmp-sse2.S | 27 ++++ sysdeps/x86_64/multiarch/strncmp-sse4_2.S | 21 +++ sysdeps/x86_64/multiarch/strncmp-ssse3.S | 34 +++- sysdeps/x86_64/multiarch/strncmp.S | 5 - sysdeps/x86_64/multiarch/strncmp.c | 54 +++++++ 24 files changed, 605 insertions(+), 240 deletions(-) create mode 100644 sysdeps/x86_64/multiarch/ifunc-strcasecmp.h create mode 100644 sysdeps/x86_64/multiarch/strcasecmp.c create mode 100644 sysdeps/x86_64/multiarch/strcasecmp_l-avx.S create mode 100644 sysdeps/x86_64/multiarch/strcasecmp_l-sse2.S create mode 100644 sysdeps/x86_64/multiarch/strcasecmp_l-sse4_2.S delete mode 100644 sysdeps/x86_64/multiarch/strcasecmp_l.S create mode 100644 sysdeps/x86_64/multiarch/strcasecmp_l.c create mode 100644 sysdeps/x86_64/multiarch/strcmp-sse2.S create mode 100644 sysdeps/x86_64/multiarch/strcmp-sse4_2.S delete mode 100644 sysdeps/x86_64/multiarch/strcmp.S create mode 100644 sysdeps/x86_64/multiarch/strcmp.c create mode 100644 sysdeps/x86_64/multiarch/strncase.c create mode 100644 sysdeps/x86_64/multiarch/strncase_l-avx.S create mode 100644 sysdeps/x86_64/multiarch/strncase_l-sse2.S create mode 100644 sysdeps/x86_64/multiarch/strncase_l-sse4_2.S delete mode 100644 sysdeps/x86_64/multiarch/strncase_l.S create mode 100644 sysdeps/x86_64/multiarch/strncase_l.c create mode 100644 sysdeps/x86_64/multiarch/strncmp-sse2.S create mode 100644 sysdeps/x86_64/multiarch/strncmp-sse4_2.S delete mode 100644 sysdeps/x86_64/multiarch/strncmp.S create mode 100644 sysdeps/x86_64/multiarch/strncmp.c diff --git a/sysdeps/x86_64/multiarch/Makefile b/sysdeps/x86_64/multiarch/Makefile index 2c54c5c..68257c4 100644 --- a/sysdeps/x86_64/multiarch/Makefile +++ b/sysdeps/x86_64/multiarch/Makefile @@ -4,8 +4,10 @@ endif ifeq ($(subdir),string) -sysdep_routines += strncat-c stpncpy-c strncpy-c strcmp-ssse3 \ - strcmp-sse2-unaligned strncmp-ssse3 \ +sysdep_routines += strncat-c stpncpy-c strncpy-c \ + strcmp-sse2 strcmp-sse2-unaligned strcmp-ssse3 \ + strcmp-sse4_2 \ + strncmp-sse2 strncmp-ssse3 strncmp-sse4_2 \ memchr-sse2 rawmemchr-sse2 memchr-avx2 rawmemchr-avx2 \ memrchr-sse2 memrchr-avx2 \ memcmp-sse2 \ @@ -14,11 +16,15 @@ sysdep_routines += strncat-c stpncpy-c strncpy-c strcmp-ssse3 \ memmove-ssse3 \ memcpy-ssse3-back \ memmove-ssse3-back \ - memmove-avx512-no-vzeroupper strcasecmp_l-ssse3 \ + memmove-avx512-no-vzeroupper \ + strcasecmp_l-sse2 strcasecmp_l-ssse3 \ + strcasecmp_l-sse4_2 strcasecmp_l-avx \ + strncase_l-sse2 strncase_l-ssse3 \ + strncase_l-sse4_2 strncase_l-avx \ strchr-sse2 strchrnul-sse2 strchr-avx2 strchrnul-avx2 \ strrchr-sse2 strrchr-avx2 \ strlen-sse2 strnlen-sse2 strlen-avx2 strnlen-avx2 \ - strncase_l-ssse3 strcat-ssse3 strncat-ssse3\ + strcat-ssse3 strncat-ssse3\ strcpy-sse2 stpcpy-sse2 \ strcpy-ssse3 strncpy-ssse3 stpcpy-ssse3 stpncpy-ssse3 \ strcpy-sse2-unaligned strncpy-sse2-unaligned \ diff --git a/sysdeps/x86_64/multiarch/ifunc-strcasecmp.h b/sysdeps/x86_64/multiarch/ifunc-strcasecmp.h new file mode 100644 index 0000000..adecd6d --- /dev/null +++ b/sysdeps/x86_64/multiarch/ifunc-strcasecmp.h @@ -0,0 +1,43 @@ +/* Common definition for strcasecmp famly ifunc selections. + All versions must be listed in ifunc-impl-list.c. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +extern __typeof (REDIRECT_NAME) OPTIMIZE (sse2) attribute_hidden; +extern __typeof (REDIRECT_NAME) OPTIMIZE (ssse3) attribute_hidden; +extern __typeof (REDIRECT_NAME) OPTIMIZE (sse42) attribute_hidden; +extern __typeof (REDIRECT_NAME) OPTIMIZE (avx) attribute_hidden; + +static inline void * +IFUNC_SELECTOR (void) +{ + const struct cpu_features* cpu_features = __get_cpu_features (); + + if (CPU_FEATURES_ARCH_P (cpu_features, AVX_Usable)) + return OPTIMIZE (avx); + + if (CPU_FEATURES_CPU_P (cpu_features, SSE4_2) + && !CPU_FEATURES_ARCH_P (cpu_features, Slow_SSE4_2)) + return OPTIMIZE (sse42); + + if (CPU_FEATURES_CPU_P (cpu_features, SSSE3)) + return OPTIMIZE (ssse3); + + return OPTIMIZE (sse2); +} diff --git a/sysdeps/x86_64/multiarch/strcasecmp.c b/sysdeps/x86_64/multiarch/strcasecmp.c new file mode 100644 index 0000000..8170bde --- /dev/null +++ b/sysdeps/x86_64/multiarch/strcasecmp.c @@ -0,0 +1,39 @@ +/* Multiple versions of strcasecmp. + All versions must be listed in ifunc-impl-list.c. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* Define multiple versions only for the definition in libc. */ +#if IS_IN (libc) +# define strcasecmp __redirect_strcasecmp +# define __strcasecmp __redirect___strcasecmp +# include +# undef strcasecmp +# undef __strcasecmp + +# define SYMBOL_NAME strcasecmp +# include "ifunc-strcasecmp.h" + +libc_ifunc_redirected (__redirect_strcasecmp, __strcasecmp, + IFUNC_SELECTOR ()); + +weak_alias (__strcasecmp, strcasecmp) +# ifdef SHARED +__hidden_ver1 (__strcasecmp, __GI___strcasecmp, __redirect___strcasecmp) + __attribute__ ((visibility ("hidden"))); +# endif +#endif diff --git a/sysdeps/x86_64/multiarch/strcasecmp_l-avx.S b/sysdeps/x86_64/multiarch/strcasecmp_l-avx.S new file mode 100644 index 0000000..60f5b50 --- /dev/null +++ b/sysdeps/x86_64/multiarch/strcasecmp_l-avx.S @@ -0,0 +1,22 @@ +/* strcasecmp_l optimized with AVX. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#define STRCMP_SSE42 __strcasecmp_l_avx +#define USE_AVX 1 +#define USE_AS_STRCASECMP_L +#include "strcmp-sse42.S" diff --git a/sysdeps/x86_64/multiarch/strcasecmp_l-sse2.S b/sysdeps/x86_64/multiarch/strcasecmp_l-sse2.S new file mode 100644 index 0000000..0b04184 --- /dev/null +++ b/sysdeps/x86_64/multiarch/strcasecmp_l-sse2.S @@ -0,0 +1,23 @@ +/* strcasecmp_l optimized with SSE2. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#define STRCMP __strcasecmp_l_sse2 +#define USE_AS_STRCASECMP_L +#define NO_NOLOCALE_ALIAS +#define __strcasecmp __strcasecmp_sse2 +#include diff --git a/sysdeps/x86_64/multiarch/strcasecmp_l-sse4_2.S b/sysdeps/x86_64/multiarch/strcasecmp_l-sse4_2.S new file mode 100644 index 0000000..92a660b --- /dev/null +++ b/sysdeps/x86_64/multiarch/strcasecmp_l-sse4_2.S @@ -0,0 +1,21 @@ +/* strcasecmp_l optimized with SSE4.2. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#define STRCMP_SSE42 __strcasecmp_l_sse42 +#define USE_AS_STRCASECMP_L +#include "strcmp-sse42.S" diff --git a/sysdeps/x86_64/multiarch/strcasecmp_l.S b/sysdeps/x86_64/multiarch/strcasecmp_l.S deleted file mode 100644 index 49f5b9f..0000000 --- a/sysdeps/x86_64/multiarch/strcasecmp_l.S +++ /dev/null @@ -1,8 +0,0 @@ -/* Multiple versions of strcasecmp and strcasecmp_l - All versions must be listed in ifunc-impl-list.c. */ -#define STRCMP __strcasecmp_l -#define USE_AS_STRCASECMP_L -#include "strcmp.S" - -weak_alias (__strcasecmp_l, strcasecmp_l) -libc_hidden_def (strcasecmp_l) diff --git a/sysdeps/x86_64/multiarch/strcasecmp_l.c b/sysdeps/x86_64/multiarch/strcasecmp_l.c new file mode 100644 index 0000000..f28db6c --- /dev/null +++ b/sysdeps/x86_64/multiarch/strcasecmp_l.c @@ -0,0 +1,40 @@ +/* Multiple versions of strcasecmp_l. + All versions must be listed in ifunc-impl-list.c. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* Define multiple versions only for the definition in libc. */ +#if IS_IN (libc) +# define strcasecmp_l __redirect_strcasecmp_l +# define __strcasecmp_l __redirect___strcasecmp_l +# include +# undef strcasecmp_l +# undef __strcasecmp_l + +# define SYMBOL_NAME strcasecmp_l +# include "ifunc-strcasecmp.h" + +libc_ifunc_redirected (__redirect_strcasecmp_l, __strcasecmp_l, + IFUNC_SELECTOR ()); + +weak_alias (__strcasecmp_l, strcasecmp_l) +# ifdef SHARED +__hidden_ver1 (__strcasecmp_l, __GI___strcasecmp_l, + __redirect___strcasecmp_l) + __attribute__ ((visibility ("hidden"))); +# endif +#endif diff --git a/sysdeps/x86_64/multiarch/strcmp-sse2.S b/sysdeps/x86_64/multiarch/strcmp-sse2.S new file mode 100644 index 0000000..834ba3f --- /dev/null +++ b/sysdeps/x86_64/multiarch/strcmp-sse2.S @@ -0,0 +1,28 @@ +/* strcmp optimized with SSE2. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#if IS_IN (libc) +# include + +# define STRCMP __strcmp_sse2 + +# undef libc_hidden_builtin_def +# define libc_hidden_builtin_def(strcmp) +#endif + +#include diff --git a/sysdeps/x86_64/multiarch/strcmp-sse42.S b/sysdeps/x86_64/multiarch/strcmp-sse42.S index ed26d4a..4aeb14e 100644 --- a/sysdeps/x86_64/multiarch/strcmp-sse42.S +++ b/sysdeps/x86_64/multiarch/strcmp-sse42.S @@ -17,6 +17,40 @@ License along with the GNU C Library; if not, see . */ +#include + +#ifndef STRCMP_SSE42 +# define STRCMP_SSE42 __strcmp_sse42 +#endif + +#if defined USE_AS_STRCASECMP_L || defined USE_AS_STRNCASECMP_L +# include "locale-defines.h" +#endif + +#if defined USE_AS_STRNCMP || defined USE_AS_STRNCASECMP_L +/* Since the counter, %r11, is unsigned, we branch to strcmp_exitz + if the new counter > the old one or is 0. */ +# define UPDATE_STRNCMP_COUNTER \ + /* calculate left number to compare */ \ + lea -16(%rcx, %r11), %r9; \ + cmp %r9, %r11; \ + jb LABEL(strcmp_exitz); \ + test %r9, %r9; \ + je LABEL(strcmp_exitz); \ + mov %r9, %r11 +#else +# define UPDATE_STRNCMP_COUNTER +#endif + +#ifdef USE_AVX +# define SECTION avx +# define GLABEL(l) l##_avx +#else +# define SECTION sse4.2 +# define GLABEL(l) l##_sse42 +#endif + +#define LABEL(l) .L##l /* We use 0x1a: _SIDD_SBYTE_OPS diff --git a/sysdeps/x86_64/multiarch/strcmp-sse4_2.S b/sysdeps/x86_64/multiarch/strcmp-sse4_2.S new file mode 100644 index 0000000..acf0079 --- /dev/null +++ b/sysdeps/x86_64/multiarch/strcmp-sse4_2.S @@ -0,0 +1,21 @@ +/* strcmp optimized with SSE4.2. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#if IS_IN (libc) +# include "strcmp-sse42.S" +#endif diff --git a/sysdeps/x86_64/multiarch/strcmp.S b/sysdeps/x86_64/multiarch/strcmp.S deleted file mode 100644 index 54f8f7d..0000000 --- a/sysdeps/x86_64/multiarch/strcmp.S +++ /dev/null @@ -1,209 +0,0 @@ -/* Multiple versions of strcmp - Copyright (C) 2009-2017 Free Software Foundation, Inc. - Contributed by Intel Corporation. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -#ifdef USE_AS_STRNCMP -/* Since the counter, %r11, is unsigned, we branch to strcmp_exitz - if the new counter > the old one or is 0. */ -# define UPDATE_STRNCMP_COUNTER \ - /* calculate left number to compare */ \ - lea -16(%rcx, %r11), %r9; \ - cmp %r9, %r11; \ - jb LABEL(strcmp_exitz); \ - test %r9, %r9; \ - je LABEL(strcmp_exitz); \ - mov %r9, %r11 - -# define STRCMP_SSE42 __strncmp_sse42 -# define STRCMP_SSSE3 __strncmp_ssse3 -# define STRCMP_SSE2 __strncmp_sse2 -# define __GI_STRCMP __GI_strncmp -#elif defined USE_AS_STRCASECMP_L -# include "locale-defines.h" - -# define UPDATE_STRNCMP_COUNTER - -# define STRCMP_AVX __strcasecmp_l_avx -# define STRCMP_SSE42 __strcasecmp_l_sse42 -# define STRCMP_SSSE3 __strcasecmp_l_ssse3 -# define STRCMP_SSE2 __strcasecmp_l_sse2 -# define __GI_STRCMP __GI___strcasecmp_l -#elif defined USE_AS_STRNCASECMP_L -# include "locale-defines.h" - -/* Since the counter, %r11, is unsigned, we branch to strcmp_exitz - if the new counter > the old one or is 0. */ -# define UPDATE_STRNCMP_COUNTER \ - /* calculate left number to compare */ \ - lea -16(%rcx, %r11), %r9; \ - cmp %r9, %r11; \ - jb LABEL(strcmp_exitz); \ - test %r9, %r9; \ - je LABEL(strcmp_exitz); \ - mov %r9, %r11 - -# define STRCMP_AVX __strncasecmp_l_avx -# define STRCMP_SSE42 __strncasecmp_l_sse42 -# define STRCMP_SSSE3 __strncasecmp_l_ssse3 -# define STRCMP_SSE2 __strncasecmp_l_sse2 -# define __GI_STRCMP __GI___strncasecmp_l -#else -# define USE_AS_STRCMP -# define UPDATE_STRNCMP_COUNTER -# ifndef STRCMP -# define STRCMP strcmp -# define STRCMP_SSE42 __strcmp_sse42 -# define STRCMP_SSSE3 __strcmp_ssse3 -# define STRCMP_SSE2 __strcmp_sse2 -# define __GI_STRCMP __GI_strcmp -# endif -#endif - -/* Define multiple versions only for the definition in libc. Don't - define multiple versions for strncmp in static library since we - need strncmp before the initialization happened. */ -#if (defined SHARED || !defined USE_AS_STRNCMP) && IS_IN (libc) - .text -ENTRY(STRCMP) - .type STRCMP, @gnu_indirect_function - LOAD_RTLD_GLOBAL_RO_RDX -#ifdef USE_AS_STRCMP - leaq __strcmp_sse2_unaligned(%rip), %rax - HAS_ARCH_FEATURE (Fast_Unaligned_Load) - jnz 3f -#else - HAS_ARCH_FEATURE (Slow_SSE4_2) - jnz 2f - leaq STRCMP_SSE42(%rip), %rax - HAS_CPU_FEATURE (SSE4_2) - jnz 3f -#endif -2: leaq STRCMP_SSSE3(%rip), %rax - HAS_CPU_FEATURE (SSSE3) - jnz 3f - leaq STRCMP_SSE2(%rip), %rax -3: ret -END(STRCMP) - -# ifdef USE_AS_STRCASECMP_L -ENTRY(__strcasecmp) - .type __strcasecmp, @gnu_indirect_function - LOAD_RTLD_GLOBAL_RO_RDX - leaq __strcasecmp_avx(%rip), %rax - HAS_ARCH_FEATURE (AVX_Usable) - jnz 3f - HAS_ARCH_FEATURE (Slow_SSE4_2) - jnz 2f - leaq __strcasecmp_sse42(%rip), %rax - HAS_CPU_FEATURE (SSE4_2) - jnz 3f -2: leaq __strcasecmp_ssse3(%rip), %rax - HAS_CPU_FEATURE (SSSE3) - jnz 3f - leaq __strcasecmp_sse2(%rip), %rax -3: ret -END(__strcasecmp) -weak_alias (__strcasecmp, strcasecmp) -# endif -# ifdef USE_AS_STRNCASECMP_L -ENTRY(__strncasecmp) - .type __strncasecmp, @gnu_indirect_function - LOAD_RTLD_GLOBAL_RO_RDX - leaq __strncasecmp_avx(%rip), %rax - HAS_ARCH_FEATURE (AVX_Usable) - jnz 3f - HAS_ARCH_FEATURE (Slow_SSE4_2) - jnz 2f - leaq __strncasecmp_sse42(%rip), %rax - HAS_CPU_FEATURE (SSE4_2) - jnz 3f -2: leaq __strncasecmp_ssse3(%rip), %rax - HAS_CPU_FEATURE (SSSE3) - jnz 3f - leaq __strncasecmp_sse2(%rip), %rax -3: ret -END(__strncasecmp) -weak_alias (__strncasecmp, strncasecmp) -# endif - -# undef LABEL -# define LABEL(l) .L##l##_sse42 -# define GLABEL(l) l##_sse42 -# define SECTION sse4.2 -# include "strcmp-sse42.S" - - -# if defined USE_AS_STRCASECMP_L || defined USE_AS_STRNCASECMP_L -# define LABEL(l) .L##l##_avx -# define GLABEL(l) l##_avx -# define USE_AVX 1 -# undef STRCMP_SSE42 -# define STRCMP_SSE42 STRCMP_AVX -# define SECTION avx -# include "strcmp-sse42.S" -# endif - - -# undef ENTRY -# define ENTRY(name) \ - .type STRCMP_SSE2, @function; \ - .align 16; \ - .globl STRCMP_SSE2; \ - .hidden STRCMP_SSE2; \ - STRCMP_SSE2: cfi_startproc; \ - CALL_MCOUNT -# undef END -# define END(name) \ - cfi_endproc; .size STRCMP_SSE2, .-STRCMP_SSE2 - -# ifdef USE_AS_STRCASECMP_L -# define ENTRY2(name) \ - .type __strcasecmp_sse2, @function; \ - .align 16; \ - .globl __strcasecmp_sse2; \ - .hidden __strcasecmp_sse2; \ - __strcasecmp_sse2: cfi_startproc; \ - CALL_MCOUNT -# define END2(name) \ - cfi_endproc; .size __strcasecmp_sse2, .-__strcasecmp_sse2 -# endif - -# ifdef USE_AS_STRNCASECMP_L -# define ENTRY2(name) \ - .type __strncasecmp_sse2, @function; \ - .align 16; \ - .globl __strncasecmp_sse2; \ - .hidden __strncasecmp_sse2; \ - __strncasecmp_sse2: cfi_startproc; \ - CALL_MCOUNT -# define END2(name) \ - cfi_endproc; .size __strncasecmp_sse2, .-__strncasecmp_sse2 -# endif - -# undef libc_hidden_builtin_def -/* It doesn't make sense to send libc-internal strcmp calls through a PLT. - The speedup we get from using SSE4.2 instruction is likely eaten away - by the indirect call in the PLT. */ -# define libc_hidden_builtin_def(name) \ - .globl __GI_STRCMP; __GI_STRCMP = STRCMP_SSE2 -#endif - -#include "../strcmp.S" diff --git a/sysdeps/x86_64/multiarch/strcmp.c b/sysdeps/x86_64/multiarch/strcmp.c new file mode 100644 index 0000000..5c0fc5a --- /dev/null +++ b/sysdeps/x86_64/multiarch/strcmp.c @@ -0,0 +1,53 @@ +/* Multiple versions of strcmp. + All versions must be listed in ifunc-impl-list.c. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* Define multiple versions only for the definition in libc. */ +#if IS_IN (libc) +# define strcmp __redirect_strcmp +# include +# undef strcmp + +# define SYMBOL_NAME strcmp +# include + +extern __typeof (REDIRECT_NAME) OPTIMIZE (sse2) attribute_hidden; +extern __typeof (REDIRECT_NAME) OPTIMIZE (sse2_unaligned) attribute_hidden; +extern __typeof (REDIRECT_NAME) OPTIMIZE (ssse3) attribute_hidden; + +static inline void * +IFUNC_SELECTOR (void) +{ + const struct cpu_features* cpu_features = __get_cpu_features (); + + if (CPU_FEATURES_ARCH_P (cpu_features, Fast_Unaligned_Load)) + return OPTIMIZE (sse2_unaligned); + + if (CPU_FEATURES_CPU_P (cpu_features, SSSE3)) + return OPTIMIZE (ssse3); + + return OPTIMIZE (sse2); +} + +libc_ifunc_redirected (__redirect_strcmp, strcmp, IFUNC_SELECTOR ()); + +# ifdef SHARED +__hidden_ver1 (strcmp, __GI_strcmp, __redirect_strcmp) + __attribute__ ((visibility ("hidden"))); +# endif +#endif diff --git a/sysdeps/x86_64/multiarch/strncase.c b/sysdeps/x86_64/multiarch/strncase.c new file mode 100644 index 0000000..4bb4c61 --- /dev/null +++ b/sysdeps/x86_64/multiarch/strncase.c @@ -0,0 +1,35 @@ +/* Multiple versions of strncasecmp. + All versions must be listed in ifunc-impl-list.c. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* Define multiple versions only for the definition in libc. */ +#if IS_IN (libc) +# define strncasecmp __redirect_strncasecmp +# define __strncasecmp __redirect___strncasecmp +# include +# undef strncasecmp +# undef __strncasecmp + +# define SYMBOL_NAME strncasecmp +# include "ifunc-strcasecmp.h" + +libc_ifunc_redirected (__redirect_strncasecmp, __strncasecmp, + IFUNC_SELECTOR ()); + +weak_alias (__strncasecmp, strncasecmp) +#endif diff --git a/sysdeps/x86_64/multiarch/strncase_l-avx.S b/sysdeps/x86_64/multiarch/strncase_l-avx.S new file mode 100644 index 0000000..2a109f1 --- /dev/null +++ b/sysdeps/x86_64/multiarch/strncase_l-avx.S @@ -0,0 +1,22 @@ +/* strncasecmp_l optimized with AVX. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#define STRCMP_SSE42 __strncasecmp_l_avx +#define USE_AVX 1 +#define USE_AS_STRNCASECMP_L +#include "strcmp-sse42.S" diff --git a/sysdeps/x86_64/multiarch/strncase_l-sse2.S b/sysdeps/x86_64/multiarch/strncase_l-sse2.S new file mode 100644 index 0000000..6cd3d91 --- /dev/null +++ b/sysdeps/x86_64/multiarch/strncase_l-sse2.S @@ -0,0 +1,23 @@ +/* strncasecmp_l optimized with SSE2. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#define STRCMP __strncasecmp_l_sse2 +#define NO_NOLOCALE_ALIAS +#define USE_AS_STRNCASECMP_L +#define __strncasecmp __strncasecmp_sse2 +#include diff --git a/sysdeps/x86_64/multiarch/strncase_l-sse4_2.S b/sysdeps/x86_64/multiarch/strncase_l-sse4_2.S new file mode 100644 index 0000000..f381dcf --- /dev/null +++ b/sysdeps/x86_64/multiarch/strncase_l-sse4_2.S @@ -0,0 +1,21 @@ +/* strncasecmp_l optimized with SSE4.2. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#define STRCMP_SSE42 __strncasecmp_l_sse42 +#define USE_AS_STRNCASECMP_L +#include "strcmp-sse42.S" diff --git a/sysdeps/x86_64/multiarch/strncase_l.S b/sysdeps/x86_64/multiarch/strncase_l.S deleted file mode 100644 index 9c01497..0000000 --- a/sysdeps/x86_64/multiarch/strncase_l.S +++ /dev/null @@ -1,8 +0,0 @@ -/* Multiple versions of strncasecmp and strncasecmp_l - All versions must be listed in ifunc-impl-list.c. */ -#define STRCMP __strncasecmp_l -#define USE_AS_STRNCASECMP_L -#include "strcmp.S" - -weak_alias (__strncasecmp_l, strncasecmp_l) -libc_hidden_def (strncasecmp_l) diff --git a/sysdeps/x86_64/multiarch/strncase_l.c b/sysdeps/x86_64/multiarch/strncase_l.c new file mode 100644 index 0000000..e6ca6bb --- /dev/null +++ b/sysdeps/x86_64/multiarch/strncase_l.c @@ -0,0 +1,40 @@ +/* Multiple versions of strncasecmp_l. + All versions must be listed in ifunc-impl-list.c. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* Define multiple versions only for the definition in libc. */ +#if IS_IN (libc) +# define strncasecmp_l __redirect_strncasecmp_l +# define __strncasecmp_l __redirect___strncasecmp_l +# include +# undef strncasecmp_l +# undef __strncasecmp_l + +# define SYMBOL_NAME strncasecmp_l +# include "ifunc-strcasecmp.h" + +libc_ifunc_redirected (__redirect_strncasecmp_l, __strncasecmp_l, + IFUNC_SELECTOR ()); + +weak_alias (__strncasecmp_l, strncasecmp_l) +# ifdef SHARED +__hidden_ver1 (__strncasecmp_l, __GI___strncasecmp_l, + __redirect___strncasecmp_l) + __attribute__ ((visibility ("hidden"))); +# endif +#endif diff --git a/sysdeps/x86_64/multiarch/strncmp-sse2.S b/sysdeps/x86_64/multiarch/strncmp-sse2.S new file mode 100644 index 0000000..f16d33d --- /dev/null +++ b/sysdeps/x86_64/multiarch/strncmp-sse2.S @@ -0,0 +1,27 @@ +/* strcmp optimized with SSE2. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +#define STRCMP __strncmp_sse2 + +#undef libc_hidden_builtin_def +#define libc_hidden_builtin_def(strcmp) + +#define USE_AS_STRNCMP +#include diff --git a/sysdeps/x86_64/multiarch/strncmp-sse4_2.S b/sysdeps/x86_64/multiarch/strncmp-sse4_2.S new file mode 100644 index 0000000..21a03f2 --- /dev/null +++ b/sysdeps/x86_64/multiarch/strncmp-sse4_2.S @@ -0,0 +1,21 @@ +/* strncmp optimized with SSE4.2. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#define STRCMP_SSE42 __strncmp_sse42 +#define USE_AS_STRNCMP +#include "strcmp-sse42.S" diff --git a/sysdeps/x86_64/multiarch/strncmp-ssse3.S b/sysdeps/x86_64/multiarch/strncmp-ssse3.S index 96380a4..254cc74 100644 --- a/sysdeps/x86_64/multiarch/strncmp-ssse3.S +++ b/sysdeps/x86_64/multiarch/strncmp-ssse3.S @@ -1,6 +1,28 @@ -#ifdef SHARED -# define USE_SSSE3 1 -# define STRCMP __strncmp_ssse3 -# define USE_AS_STRNCMP -# include "../strcmp.S" -#endif +/* strcmp optimized with SSSE3. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +#define STRCMP __strncmp_ssse3 + +#undef libc_hidden_builtin_def +#define libc_hidden_builtin_def(strcmp) + +#define USE_SSSE3 1 +#define USE_AS_STRNCMP +#include diff --git a/sysdeps/x86_64/multiarch/strncmp.S b/sysdeps/x86_64/multiarch/strncmp.S deleted file mode 100644 index fd5eb13..0000000 --- a/sysdeps/x86_64/multiarch/strncmp.S +++ /dev/null @@ -1,5 +0,0 @@ -/* Multiple versions of strncmp - All versions must be listed in ifunc-impl-list.c. */ -#define STRCMP strncmp -#define USE_AS_STRNCMP -#include "strcmp.S" diff --git a/sysdeps/x86_64/multiarch/strncmp.c b/sysdeps/x86_64/multiarch/strncmp.c new file mode 100644 index 0000000..1457d42 --- /dev/null +++ b/sysdeps/x86_64/multiarch/strncmp.c @@ -0,0 +1,54 @@ +/* Multiple versions of strncmp. + All versions must be listed in ifunc-impl-list.c. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* Define multiple versions only for the definition in libc. */ +#if IS_IN (libc) +# define strncmp __redirect_strncmp +# include +# undef strncmp + +# define SYMBOL_NAME strncmp +# include + +extern __typeof (REDIRECT_NAME) OPTIMIZE (sse2) attribute_hidden; +extern __typeof (REDIRECT_NAME) OPTIMIZE (ssse3) attribute_hidden; +extern __typeof (REDIRECT_NAME) OPTIMIZE (sse42) attribute_hidden; + +static inline void * +IFUNC_SELECTOR (void) +{ + const struct cpu_features* cpu_features = __get_cpu_features (); + + if (CPU_FEATURES_CPU_P (cpu_features, SSE4_2) + && !CPU_FEATURES_ARCH_P (cpu_features, Slow_SSE4_2)) + return OPTIMIZE (sse42); + + if (CPU_FEATURES_CPU_P (cpu_features, SSSE3)) + return OPTIMIZE (ssse3); + + return OPTIMIZE (sse2); +} + +libc_ifunc_redirected (__redirect_strncmp, strncmp, IFUNC_SELECTOR ()); + +# ifdef SHARED +__hidden_ver1 (strncmp, __GI_strncmp, __redirect_strncmp) + __attribute__ ((visibility ("hidden"))); +# endif +#endif -- 2.9.4