From 50ec29e549f0be35d80bef70903a210682a1806a Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Mon, 24 Aug 2015 13:01:12 -0700 Subject: Add i386 strlen family multiarch functions --- sysdeps/i386/i586/multiarch/rtld-strlen.S | 19 ++++ sysdeps/i386/i586/multiarch/static-strlen.S | 21 +++++ sysdeps/i386/i586/multiarch/strlen-i386.S | 4 + sysdeps/i386/i586/multiarch/strlen-i586.S | 7 ++ sysdeps/i386/i586/multiarch/strlen.c | 1 + sysdeps/i386/i686/multiarch/Makefile | 2 - sysdeps/i386/i686/multiarch/rtld-strnlen.c | 1 - sysdeps/i386/i686/multiarch/strlen-sse2-bsf.S | 125 -------------------------- sysdeps/i386/i686/multiarch/strlen.S | 60 ------------- sysdeps/i386/i686/multiarch/strnlen-c.c | 10 --- sysdeps/i386/i686/multiarch/strnlen-sse2.S | 3 - sysdeps/i386/i686/multiarch/strnlen.S | 37 -------- sysdeps/i386/multiarch/Makefile | 2 + sysdeps/i386/multiarch/ifunc-impl-list.c | 9 +- sysdeps/i386/multiarch/rtld-strlen.S | 19 ++++ sysdeps/i386/multiarch/rtld-strnlen.c | 1 + sysdeps/i386/multiarch/static-strlen.S | 21 +++++ sysdeps/i386/multiarch/strlen-i386.S | 7 ++ sysdeps/i386/multiarch/strlen-i586.S | 6 ++ sysdeps/i386/multiarch/strlen-sse2-bsf.S | 125 ++++++++++++++++++++++++++ sysdeps/i386/multiarch/strlen.c | 58 ++++++++++++ sysdeps/i386/multiarch/strnlen-i386.c | 10 +++ sysdeps/i386/multiarch/strnlen-sse2.S | 3 + sysdeps/i386/multiarch/strnlen.c | 50 +++++++++++ 24 files changed, 357 insertions(+), 244 deletions(-) create mode 100644 sysdeps/i386/i586/multiarch/rtld-strlen.S create mode 100644 sysdeps/i386/i586/multiarch/static-strlen.S create mode 100644 sysdeps/i386/i586/multiarch/strlen-i386.S create mode 100644 sysdeps/i386/i586/multiarch/strlen-i586.S create mode 100644 sysdeps/i386/i586/multiarch/strlen.c delete mode 100644 sysdeps/i386/i686/multiarch/rtld-strnlen.c delete mode 100644 sysdeps/i386/i686/multiarch/strlen-sse2-bsf.S delete mode 100644 sysdeps/i386/i686/multiarch/strlen.S delete mode 100644 sysdeps/i386/i686/multiarch/strnlen-c.c delete mode 100644 sysdeps/i386/i686/multiarch/strnlen-sse2.S delete mode 100644 sysdeps/i386/i686/multiarch/strnlen.S create mode 100644 sysdeps/i386/multiarch/rtld-strlen.S create mode 100644 sysdeps/i386/multiarch/rtld-strnlen.c create mode 100644 sysdeps/i386/multiarch/static-strlen.S create mode 100644 sysdeps/i386/multiarch/strlen-i386.S create mode 100644 sysdeps/i386/multiarch/strlen-i586.S create mode 100644 sysdeps/i386/multiarch/strlen-sse2-bsf.S create mode 100644 sysdeps/i386/multiarch/strlen.c create mode 100644 sysdeps/i386/multiarch/strnlen-i386.c create mode 100644 sysdeps/i386/multiarch/strnlen-sse2.S create mode 100644 sysdeps/i386/multiarch/strnlen.c diff --git a/sysdeps/i386/i586/multiarch/rtld-strlen.S b/sysdeps/i386/i586/multiarch/rtld-strlen.S new file mode 100644 index 0000000000..70fc5f3b01 --- /dev/null +++ b/sysdeps/i386/i586/multiarch/rtld-strlen.S @@ -0,0 +1,19 @@ +/* strlen for ld.so + Copyright (C) 2015 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 diff --git a/sysdeps/i386/i586/multiarch/static-strlen.S b/sysdeps/i386/i586/multiarch/static-strlen.S new file mode 100644 index 0000000000..96befd4a3a --- /dev/null +++ b/sysdeps/i386/i586/multiarch/static-strlen.S @@ -0,0 +1,21 @@ +/* strlen for libc.a + Copyright (C) 2015 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 !defined SHARED && IS_IN (libc) +# include +#endif diff --git a/sysdeps/i386/i586/multiarch/strlen-i386.S b/sysdeps/i386/i586/multiarch/strlen-i386.S new file mode 100644 index 0000000000..216bbf5e82 --- /dev/null +++ b/sysdeps/i386/i586/multiarch/strlen-i386.S @@ -0,0 +1,4 @@ +#define strlen __strlen_i386 +#undef libc_hidden_builtin_def +#define libc_hidden_builtin_def(name) +#include diff --git a/sysdeps/i386/i586/multiarch/strlen-i586.S b/sysdeps/i386/i586/multiarch/strlen-i586.S new file mode 100644 index 0000000000..69c3170292 --- /dev/null +++ b/sysdeps/i386/i586/multiarch/strlen-i586.S @@ -0,0 +1,7 @@ +#include + +#ifdef SHARED + .globl __GI_strlen + .hidden __GI_strlen + __GI_strlen = __strlen_i586 +#endif diff --git a/sysdeps/i386/i586/multiarch/strlen.c b/sysdeps/i386/i586/multiarch/strlen.c new file mode 100644 index 0000000000..fb40868acb --- /dev/null +++ b/sysdeps/i386/i586/multiarch/strlen.c @@ -0,0 +1 @@ +#include diff --git a/sysdeps/i386/i686/multiarch/Makefile b/sysdeps/i386/i686/multiarch/Makefile index 2733c2a880..77f01df193 100644 --- a/sysdeps/i386/i686/multiarch/Makefile +++ b/sysdeps/i386/i686/multiarch/Makefile @@ -1,6 +1,4 @@ ifeq ($(subdir),string) -sysdep_routines += strlen-sse2 strlen-sse2-bsf \ - strnlen-sse2 strnlen-c ifeq (yes,$(config-cflags-sse4)) sysdep_routines += strspn-c CFLAGS-strspn-c.c += -msse4 diff --git a/sysdeps/i386/i686/multiarch/rtld-strnlen.c b/sysdeps/i386/i686/multiarch/rtld-strnlen.c deleted file mode 100644 index 1aa5440644..0000000000 --- a/sysdeps/i386/i686/multiarch/rtld-strnlen.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/i386/i686/multiarch/strlen-sse2-bsf.S b/sysdeps/i386/i686/multiarch/strlen-sse2-bsf.S deleted file mode 100644 index 668a2a65fc..0000000000 --- a/sysdeps/i386/i686/multiarch/strlen-sse2-bsf.S +++ /dev/null @@ -1,125 +0,0 @@ -/* strlen with SSE2 and BSF - Copyright (C) 2010-2015 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 - . */ - -#if defined SHARED && IS_IN (libc) - -#include - -#define CFI_PUSH(REG) \ - cfi_adjust_cfa_offset (4); \ - cfi_rel_offset (REG, 0) - -#define CFI_POP(REG) \ - cfi_adjust_cfa_offset (-4); \ - cfi_restore (REG) - -#define PUSH(REG) pushl REG; CFI_PUSH (REG) -#define POP(REG) popl REG; CFI_POP (REG) -#define PARMS 4 + 8 /* Preserve ESI and EDI. */ -#define STR PARMS -#define ENTRANCE PUSH (%esi); PUSH (%edi); cfi_remember_state -#define RETURN POP (%edi); POP (%esi); ret; \ - cfi_restore_state; cfi_remember_state - - .text -ENTRY ( __strlen_sse2_bsf) - ENTRANCE - mov STR(%esp), %edi - xor %eax, %eax - mov %edi, %ecx - and $0x3f, %ecx - pxor %xmm0, %xmm0 - cmp $0x30, %ecx - ja L(next) - movdqu (%edi), %xmm1 - pcmpeqb %xmm1, %xmm0 - pmovmskb %xmm0, %edx - test %edx, %edx - jnz L(exit_less16) - mov %edi, %eax - and $-16, %eax - jmp L(align16_start) -L(next): - - mov %edi, %eax - and $-16, %eax - pcmpeqb (%eax), %xmm0 - mov $-1, %esi - sub %eax, %ecx - shl %cl, %esi - pmovmskb %xmm0, %edx - and %esi, %edx - jnz L(exit) -L(align16_start): - pxor %xmm0, %xmm0 - pxor %xmm1, %xmm1 - pxor %xmm2, %xmm2 - pxor %xmm3, %xmm3 - .p2align 4 -L(align16_loop): - pcmpeqb 16(%eax), %xmm0 - pmovmskb %xmm0, %edx - test %edx, %edx - jnz L(exit16) - - pcmpeqb 32(%eax), %xmm1 - pmovmskb %xmm1, %edx - test %edx, %edx - jnz L(exit32) - - pcmpeqb 48(%eax), %xmm2 - pmovmskb %xmm2, %edx - test %edx, %edx - jnz L(exit48) - - pcmpeqb 64(%eax), %xmm3 - pmovmskb %xmm3, %edx - lea 64(%eax), %eax - test %edx, %edx - jz L(align16_loop) -L(exit): - sub %edi, %eax -L(exit_less16): - bsf %edx, %edx - add %edx, %eax - RETURN -L(exit16): - sub %edi, %eax - bsf %edx, %edx - add %edx, %eax - add $16, %eax - RETURN -L(exit32): - sub %edi, %eax - bsf %edx, %edx - add %edx, %eax - add $32, %eax - RETURN -L(exit48): - sub %edi, %eax - bsf %edx, %edx - add %edx, %eax - add $48, %eax - POP (%edi) - POP (%esi) - ret - -END ( __strlen_sse2_bsf) - -#endif diff --git a/sysdeps/i386/i686/multiarch/strlen.S b/sysdeps/i386/i686/multiarch/strlen.S deleted file mode 100644 index 613559ca01..0000000000 --- a/sysdeps/i386/i686/multiarch/strlen.S +++ /dev/null @@ -1,60 +0,0 @@ -/* Multiple versions of strlen - All versions must be listed in ifunc-impl-list.c. - Copyright (C) 2009-2015 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 - -/* Define multiple versions only for the definition in libc and for the - DSO. In static binaries, we need strlen before the initialization - happened. */ -#if defined SHARED && IS_IN (libc) - .text -ENTRY(strlen) - .type strlen, @gnu_indirect_function - LOAD_GOT_AND_RTLD_GLOBAL_RO - LOAD_FUNC_GOT_EAX (__strlen_ia32) - HAS_CPU_FEATURE (SSE2) - jz 2f - LOAD_FUNC_GOT_EAX (__strlen_sse2_bsf) - HAS_ARCH_FEATURE (Slow_BSF) - jz 2f - LOAD_FUNC_GOT_EAX (__strlen_sse2) -2: ret -END(strlen) - -# undef ENTRY -# define ENTRY(name) \ - .type __strlen_ia32, @function; \ - .globl __strlen_ia32; \ - .p2align 4; \ - __strlen_ia32: cfi_startproc; \ - CALL_MCOUNT -# undef END -# define END(name) \ - cfi_endproc; .size __strlen_ia32, .-__strlen_ia32 -# undef libc_hidden_builtin_def -/* IFUNC doesn't work with the hidden functions in shared library since - they will be called without setting up EBX needed for PLT which is - used by IFUNC. */ -# define libc_hidden_builtin_def(name) \ - .globl __GI_strlen; __GI_strlen = __strlen_ia32 -#endif - -#include "../../i586/strlen.S" diff --git a/sysdeps/i386/i686/multiarch/strnlen-c.c b/sysdeps/i386/i686/multiarch/strnlen-c.c deleted file mode 100644 index 351e939a93..0000000000 --- a/sysdeps/i386/i686/multiarch/strnlen-c.c +++ /dev/null @@ -1,10 +0,0 @@ -#define STRNLEN __strnlen_ia32 -#ifdef SHARED -# undef libc_hidden_def -# define libc_hidden_def(name) \ - __hidden_ver1 (__strnlen_ia32, __GI_strnlen, __strnlen_ia32); \ - strong_alias (__strnlen_ia32, __strnlen_ia32_1); \ - __hidden_ver1 (__strnlen_ia32_1, __GI___strnlen, __strnlen_ia32_1); -#endif - -#include "string/strnlen.c" diff --git a/sysdeps/i386/i686/multiarch/strnlen-sse2.S b/sysdeps/i386/i686/multiarch/strnlen-sse2.S deleted file mode 100644 index 56b6ae2a5c..0000000000 --- a/sysdeps/i386/i686/multiarch/strnlen-sse2.S +++ /dev/null @@ -1,3 +0,0 @@ -#define USE_AS_STRNLEN -#define STRLEN __strnlen_sse2 -#include "strlen-sse2.S" diff --git a/sysdeps/i386/i686/multiarch/strnlen.S b/sysdeps/i386/i686/multiarch/strnlen.S deleted file mode 100644 index baf21fc205..0000000000 --- a/sysdeps/i386/i686/multiarch/strnlen.S +++ /dev/null @@ -1,37 +0,0 @@ -/* Multiple versions of strnlen - All versions must be listed in ifunc-impl-list.c. - Copyright (C) 2011-2015 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 - -#if IS_IN (libc) - .text -ENTRY(__strnlen) - .type __strnlen, @gnu_indirect_function - LOAD_GOT_AND_RTLD_GLOBAL_RO - LOAD_FUNC_GOT_EAX (__strnlen_ia32) - HAS_CPU_FEATURE (SSE2) - jz 2f - LOAD_FUNC_GOT_EAX (__strnlen_sse2) -2: ret -END(__strnlen) - -weak_alias(__strnlen, strnlen) -#endif diff --git a/sysdeps/i386/multiarch/Makefile b/sysdeps/i386/multiarch/Makefile index a4161b0f33..5e636edfa5 100644 --- a/sysdeps/i386/multiarch/Makefile +++ b/sysdeps/i386/multiarch/Makefile @@ -36,6 +36,8 @@ sysdep_routines += bcopy-i386 bcopy-i686 bcopy-sse2-unaligned \ strncat-i386 strncat-sse2 strncat-ssse3 \ strchr-i386 strchr-i586 strchr-sse2-bsf strchr-sse2 \ strcspn-i386 strpbrk-i386 \ + strlen-i386 strlen-i586 strlen-sse2 strlen-sse2-bsf \ + strnlen-sse2 strnlen-i386 static-strlen \ strrchr-i386 strrchr-sse2-bsf strrchr-sse2 ifeq (yes,$(config-cflags-sse4)) sysdep_routines += varshift strcspn-sse4 strpbrk-sse4 diff --git a/sysdeps/i386/multiarch/ifunc-impl-list.c b/sysdeps/i386/multiarch/ifunc-impl-list.c index f3bea9c9a5..a53c49f280 100644 --- a/sysdeps/i386/multiarch/ifunc-impl-list.c +++ b/sysdeps/i386/multiarch/ifunc-impl-list.c @@ -290,13 +290,11 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, __strncpy_sse2) IFUNC_IMPL_ADD (array, i, strncpy, 1, __strncpy_i386)) -#if 0 /* Support sysdeps/i386/i686/multiarch/strnlen.S. */ IFUNC_IMPL (i, name, strnlen, IFUNC_IMPL_ADD (array, i, strnlen, HAS_CPU_FEATURE (SSE2), __strnlen_sse2) - IFUNC_IMPL_ADD (array, i, strnlen, 1, __strnlen_ia32)) -#endif + IFUNC_IMPL_ADD (array, i, strnlen, 1, __strnlen_i386)) /* Support sysdeps/i386/i686/multiarch/strpbrk.S. */ IFUNC_IMPL (i, name, strpbrk, @@ -431,15 +429,14 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, # endif ) -#if 0 /* Support sysdeps/i386/i686/multiarch/strlen.S. */ IFUNC_IMPL (i, name, strlen, IFUNC_IMPL_ADD (array, i, strlen, HAS_CPU_FEATURE (SSE2), __strlen_sse2_bsf) IFUNC_IMPL_ADD (array, i, strlen, HAS_CPU_FEATURE (SSE2), __strlen_sse2) - IFUNC_IMPL_ADD (array, i, strlen, 1, __strlen_ia32)) -#endif + IFUNC_IMPL_ADD (array, i, strlen, HAS_I586, __strlen_i586) + IFUNC_IMPL_ADD (array, i, strlen, 1, __strlen_i386)) /* Support sysdeps/i386/i686/multiarch/strncmp.S. */ IFUNC_IMPL (i, name, strncmp, diff --git a/sysdeps/i386/multiarch/rtld-strlen.S b/sysdeps/i386/multiarch/rtld-strlen.S new file mode 100644 index 0000000000..9ee1dbc35a --- /dev/null +++ b/sysdeps/i386/multiarch/rtld-strlen.S @@ -0,0 +1,19 @@ +/* strlen for ld.so + Copyright (C) 2015 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 diff --git a/sysdeps/i386/multiarch/rtld-strnlen.c b/sysdeps/i386/multiarch/rtld-strnlen.c new file mode 100644 index 0000000000..1aa5440644 --- /dev/null +++ b/sysdeps/i386/multiarch/rtld-strnlen.c @@ -0,0 +1 @@ +#include diff --git a/sysdeps/i386/multiarch/static-strlen.S b/sysdeps/i386/multiarch/static-strlen.S new file mode 100644 index 0000000000..f4318e1423 --- /dev/null +++ b/sysdeps/i386/multiarch/static-strlen.S @@ -0,0 +1,21 @@ +/* strlen for libc.a + Copyright (C) 2015 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 !defined SHARED && IS_IN (libc) +# include +#endif diff --git a/sysdeps/i386/multiarch/strlen-i386.S b/sysdeps/i386/multiarch/strlen-i386.S new file mode 100644 index 0000000000..15dbe7d354 --- /dev/null +++ b/sysdeps/i386/multiarch/strlen-i386.S @@ -0,0 +1,7 @@ +#include + +#ifdef SHARED + .globl __GI_strlen + .hidden __GI_strlen + __GI_strlen = __strlen_i386 +#endif diff --git a/sysdeps/i386/multiarch/strlen-i586.S b/sysdeps/i386/multiarch/strlen-i586.S new file mode 100644 index 0000000000..2f5349074e --- /dev/null +++ b/sysdeps/i386/multiarch/strlen-i586.S @@ -0,0 +1,6 @@ +#define strlen __strlen_i586 +#undef libc_hidden_builtin_def +#define libc_hidden_builtin_def(name) +#undef weak_alias +#define weak_alias(name, aliasname) +#include diff --git a/sysdeps/i386/multiarch/strlen-sse2-bsf.S b/sysdeps/i386/multiarch/strlen-sse2-bsf.S new file mode 100644 index 0000000000..668a2a65fc --- /dev/null +++ b/sysdeps/i386/multiarch/strlen-sse2-bsf.S @@ -0,0 +1,125 @@ +/* strlen with SSE2 and BSF + Copyright (C) 2010-2015 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 + . */ + +#if defined SHARED && IS_IN (libc) + +#include + +#define CFI_PUSH(REG) \ + cfi_adjust_cfa_offset (4); \ + cfi_rel_offset (REG, 0) + +#define CFI_POP(REG) \ + cfi_adjust_cfa_offset (-4); \ + cfi_restore (REG) + +#define PUSH(REG) pushl REG; CFI_PUSH (REG) +#define POP(REG) popl REG; CFI_POP (REG) +#define PARMS 4 + 8 /* Preserve ESI and EDI. */ +#define STR PARMS +#define ENTRANCE PUSH (%esi); PUSH (%edi); cfi_remember_state +#define RETURN POP (%edi); POP (%esi); ret; \ + cfi_restore_state; cfi_remember_state + + .text +ENTRY ( __strlen_sse2_bsf) + ENTRANCE + mov STR(%esp), %edi + xor %eax, %eax + mov %edi, %ecx + and $0x3f, %ecx + pxor %xmm0, %xmm0 + cmp $0x30, %ecx + ja L(next) + movdqu (%edi), %xmm1 + pcmpeqb %xmm1, %xmm0 + pmovmskb %xmm0, %edx + test %edx, %edx + jnz L(exit_less16) + mov %edi, %eax + and $-16, %eax + jmp L(align16_start) +L(next): + + mov %edi, %eax + and $-16, %eax + pcmpeqb (%eax), %xmm0 + mov $-1, %esi + sub %eax, %ecx + shl %cl, %esi + pmovmskb %xmm0, %edx + and %esi, %edx + jnz L(exit) +L(align16_start): + pxor %xmm0, %xmm0 + pxor %xmm1, %xmm1 + pxor %xmm2, %xmm2 + pxor %xmm3, %xmm3 + .p2align 4 +L(align16_loop): + pcmpeqb 16(%eax), %xmm0 + pmovmskb %xmm0, %edx + test %edx, %edx + jnz L(exit16) + + pcmpeqb 32(%eax), %xmm1 + pmovmskb %xmm1, %edx + test %edx, %edx + jnz L(exit32) + + pcmpeqb 48(%eax), %xmm2 + pmovmskb %xmm2, %edx + test %edx, %edx + jnz L(exit48) + + pcmpeqb 64(%eax), %xmm3 + pmovmskb %xmm3, %edx + lea 64(%eax), %eax + test %edx, %edx + jz L(align16_loop) +L(exit): + sub %edi, %eax +L(exit_less16): + bsf %edx, %edx + add %edx, %eax + RETURN +L(exit16): + sub %edi, %eax + bsf %edx, %edx + add %edx, %eax + add $16, %eax + RETURN +L(exit32): + sub %edi, %eax + bsf %edx, %edx + add %edx, %eax + add $32, %eax + RETURN +L(exit48): + sub %edi, %eax + bsf %edx, %edx + add %edx, %eax + add $48, %eax + POP (%edi) + POP (%esi) + ret + +END ( __strlen_sse2_bsf) + +#endif diff --git a/sysdeps/i386/multiarch/strlen.c b/sysdeps/i386/multiarch/strlen.c new file mode 100644 index 0000000000..9e376a3cc3 --- /dev/null +++ b/sysdeps/i386/multiarch/strlen.c @@ -0,0 +1,58 @@ +/* Multiple versions of strlen. + All versions must be listed in ifunc-impl-list.c. + Copyright (C) 2015 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 defined SHARED && IS_IN (libc) +/* Redefine strlen so that the compiler won't complain about the type + mismatch with the IFUNC selector in strong_alias, below. */ +# undef strlen +# define strlen __redirect_strlen +# include +# undef strlen + +# include + +extern __typeof (__redirect_strlen) __strlen_i386 attribute_hidden; +extern __typeof (__redirect_strlen) __strlen_i586 attribute_hidden; +extern __typeof (__redirect_strlen) __strlen_sse2 attribute_hidden; +extern __typeof (__redirect_strlen) __strlen_sse2_bsf attribute_hidden; + +/* Avoid DWARF definition DIE on ifunc symbol so that GDB can handle + ifunc symbol properly. */ +extern __typeof (__redirect_strlen) strlen; +extern void *strlen_ifunc (void) __asm__ ("strlen"); + +void * +strlen_ifunc (void) +{ + if (HAS_CPU_FEATURE (SSE2)) + { + if (HAS_ARCH_FEATURE (Slow_BSF)) + return __strlen_sse2; + else + return __strlen_sse2_bsf; + } + + if (USE_I586) + return __strlen_i586; + else + return __strlen_i386; +} +__asm__ (".type strlen, %gnu_indirect_function"); +#endif diff --git a/sysdeps/i386/multiarch/strnlen-i386.c b/sysdeps/i386/multiarch/strnlen-i386.c new file mode 100644 index 0000000000..dd4dbda896 --- /dev/null +++ b/sysdeps/i386/multiarch/strnlen-i386.c @@ -0,0 +1,10 @@ +#define STRNLEN __strnlen_i386 +#ifdef SHARED +# undef libc_hidden_def +# define libc_hidden_def(name) \ + __hidden_ver1 (__strnlen_i386, __GI_strnlen, __strnlen_i386); \ + strong_alias (__strnlen_i386, __strnlen_i386_1); \ + __hidden_ver1 (__strnlen_i386_1, __GI___strnlen, __strnlen_i386_1); +#endif + +#include "string/strnlen.c" diff --git a/sysdeps/i386/multiarch/strnlen-sse2.S b/sysdeps/i386/multiarch/strnlen-sse2.S new file mode 100644 index 0000000000..56b6ae2a5c --- /dev/null +++ b/sysdeps/i386/multiarch/strnlen-sse2.S @@ -0,0 +1,3 @@ +#define USE_AS_STRNLEN +#define STRLEN __strnlen_sse2 +#include "strlen-sse2.S" diff --git a/sysdeps/i386/multiarch/strnlen.c b/sysdeps/i386/multiarch/strnlen.c new file mode 100644 index 0000000000..3e97c9e0e6 --- /dev/null +++ b/sysdeps/i386/multiarch/strnlen.c @@ -0,0 +1,50 @@ +/* Multiple versions of strnlen. + All versions must be listed in ifunc-impl-list.c. + Copyright (C) 2015 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) +/* Redefine strnlen so that the compiler won't complain about the type + mismatch with the IFUNC selector in strong_alias, below. */ +# undef strnlen +# define strnlen __redirect_strnlen +# include +# undef strnlen + +# include + +extern __typeof (__redirect_strnlen) __strnlen_i386 attribute_hidden; +extern __typeof (__redirect_strnlen) __strnlen_sse2 attribute_hidden; + +/* Avoid DWARF definition DIE on ifunc symbol so that GDB can handle + ifunc symbol properly. */ +extern __typeof (__redirect_strnlen) __strnlen; +extern void *strnlen_ifunc (void) __asm__ ("__strnlen"); + +void * +strnlen_ifunc (void) +{ + if (HAS_CPU_FEATURE (SSE2)) + return __strnlen_sse2; + + return __strnlen_i386; +} +__asm__ (".type __strnlen, %gnu_indirect_function"); + +weak_alias (__strnlen, strnlen) +#endif -- cgit 1.4.1