Optimized st{r,p}{,n}cpy for SSE2/SSSE3 on x86-32

This commit is contained in:
H.J. Lu 2011-06-24 14:15:32 -04:00 committed by Ulrich Drepper
parent 07f494a027
commit 0b1cbaaef5
18 changed files with 6585 additions and 5 deletions

View File

@ -1,3 +1,28 @@
2011-06-22 H.J. Lu <hongjiu.lu@intel.com>
* sysdeps/i386/i686/multiarch/Makefile (sysdep_routines): Add
strncpy-c strcpy-ssse3 strncpy-ssse3 stpcpy-ssse3 stpncpy-ssse3
strcpy-sse2 strncpy-sse2 stpcpy-sse2 stpncpy-sse2.
* sysdeps/i386/i686/multiarch/stpcpy-sse2.S: New file.
* sysdeps/i386/i686/multiarch/stpcpy-ssse3.S: New file.
* sysdeps/i386/i686/multiarch/stpncpy-sse2.S: New file.
* sysdeps/i386/i686/multiarch/stpncpy-ssse3.S: New file.
* sysdeps/i386/i686/multiarch/stpncpy.S : New file.
* sysdeps/i386/i686/multiarch/strcpy-sse2.S : New file.
* sysdeps/i386/i686/multiarch/strcpy-ssse3.S: New file.
* sysdeps/i386/i686/multiarch/strcpy.S: New file.
* sysdeps/i386/i686/multiarch/strncpy-c.c: New file.
* sysdeps/i386/i686/multiarch/strncpy-sse2.S: New file.
* sysdeps/i386/i686/multiarch/strncpy-ssse3.S: New file.
* sysdeps/i386/i686/multiarch/strncpy.S: New file.
* sysdeps/x86_64/multiarch/init-arch.c (__init_cpu_features):
Enable unaligned load optimization for Intel Core i3, i5 and i7
processors.
* sysdeps/x86_64/multiarch/init-arch.h (bit_Fast_Unaligned_Load):
Define.
(index_Fast_Unaligned_Load): Define.
(HAS_FAST_UNALIGNED_LOAD): Define.
2011-06-23 Marek Polacek <mpolacek@redhat.com>
* nss/nss_db/db-open.c: Include <unistd.h> for read declaration.

5
NEWS
View File

@ -1,4 +1,4 @@
GNU C Library NEWS -- history of user-visible changes. 2011-6-22
GNU C Library NEWS -- history of user-visible changes. 2011-6-24
Copyright (C) 1992-2009, 2010, 2011 Free Software Foundation, Inc.
See the end for copying conditions.
@ -17,6 +17,9 @@ Version 2.15
* Add nss_db support back to glibc. No more dependency on Berkeley db
and support for initgroups lookups.
Implemented by Ulrich Drepper.
* Optimized strcpy, strncpy, stpcpy, stpncpy for SSE2 and SSSE3 on x86-32.
Contributed by HJ Lu.
Version 2.14

View File

@ -10,7 +10,9 @@ sysdep_routines += bzero-sse2 memset-sse2 memcpy-ssse3 mempcpy-ssse3 \
memset-sse2-rep bzero-sse2-rep strcmp-ssse3 \
strcmp-sse4 strncmp-c strncmp-ssse3 strncmp-sse4 \
memcmp-ssse3 memcmp-sse4 strcasestr-nonascii varshift \
strlen-sse2 strlen-sse2-bsf
strlen-sse2 strlen-sse2-bsf strncpy-c strcpy-ssse3 \
strncpy-ssse3 stpcpy-ssse3 stpncpy-ssse3 strcpy-sse2 \
strncpy-sse2 stpcpy-sse2 stpncpy-sse2
ifeq (yes,$(config-cflags-sse4))
sysdep_routines += strcspn-c strpbrk-c strspn-c strstr-c strcasestr-c
CFLAGS-varshift.c += -msse4

View File

@ -0,0 +1,3 @@
#define USE_AS_STPCPY
#define STRCPY __stpcpy_sse2
#include "strcpy-sse2.S"

View File

@ -0,0 +1,3 @@
#define USE_AS_STPCPY
#define STRCPY __stpcpy_ssse3
#include "strcpy-ssse3.S"

View File

@ -0,0 +1,7 @@
#define USE_AS_STPCPY
#define STRCPY __stpcpy
#include "strcpy.S"
weak_alias (__stpcpy, stpcpy)
libc_hidden_def (__stpcpy)
libc_hidden_builtin_def (stpcpy)

View File

@ -0,0 +1,4 @@
#define USE_AS_STPCPY
#define USE_AS_STRNCPY
#define STRCPY __stpncpy_sse2
#include "strcpy-sse2.S"

View File

@ -0,0 +1,4 @@
#define USE_AS_STPCPY
#define USE_AS_STRNCPY
#define STRCPY __stpncpy_ssse3
#include "strcpy-ssse3.S"

View File

@ -0,0 +1,6 @@
#define STRCPY __stpncpy
#define USE_AS_STPCPY
#define USE_AS_STRNCPY
#include "strcpy.S"
weak_alias (__stpncpy, stpncpy)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,154 @@
/* Multiple versions of strcpy
Copyright (C) 2011 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, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <sysdep.h>
#include <init-arch.h>
#if !defined (USE_AS_STPCPY) && !defined (USE_AS_STRNCPY)
# ifndef STRCPY
# define STRCPY strcpy
# endif
#endif
#ifdef USE_AS_STPCPY
# ifdef USE_AS_STRNCPY
# define STRCPY_SSSE3 __stpncpy_ssse3
# define STRCPY_SSE2 __stpncpy_sse2
# define STRCPY_IA32 __stpncpy_ia32
# define __GI_STRCPY __GI_stpncpy
# define __GI___STRCPY __GI___stpncpy
# else
# define STRCPY_SSSE3 __stpcpy_ssse3
# define STRCPY_SSE2 __stpcpy_sse2
# define STRCPY_IA32 __stpcpy_ia32
# define __GI_STRCPY __GI_stpcpy
# define __GI___STRCPY __GI___stpcpy
# endif
#else
# ifdef USE_AS_STRNCPY
# define STRCPY_SSSE3 __strncpy_ssse3
# define STRCPY_SSE2 __strncpy_sse2
# define STRCPY_IA32 __strncpy_ia32
# define __GI_STRCPY __GI_strncpy
# else
# define STRCPY_SSSE3 __strcpy_ssse3
# define STRCPY_SSE2 __strcpy_sse2
# define STRCPY_IA32 __strcpy_ia32
# define __GI_STRCPY __GI_strcpy
# endif
#endif
/* Define multiple versions only for the definition in libc. Don't
define multiple versions for strncpy in static library since we
need strncpy before the initialization happened. */
#ifndef NOT_IN_libc
# ifdef SHARED
.section .gnu.linkonce.t.__i686.get_pc_thunk.bx,"ax",@progbits
.globl __i686.get_pc_thunk.bx
.hidden __i686.get_pc_thunk.bx
.p2align 4
.type __i686.get_pc_thunk.bx,@function
__i686.get_pc_thunk.bx:
movl (%esp), %ebx
ret
.text
ENTRY(STRCPY)
.type STRCPY, @gnu_indirect_function
pushl %ebx
cfi_adjust_cfa_offset (4)
cfi_rel_offset (ebx, 0)
call __i686.get_pc_thunk.bx
addl $_GLOBAL_OFFSET_TABLE_, %ebx
cmpl $0, KIND_OFFSET+__cpu_features@GOTOFF(%ebx)
jne 1f
call __init_cpu_features
1: leal STRCPY_IA32@GOTOFF(%ebx), %eax
testl $bit_SSE2, CPUID_OFFSET+index_SSE2+__cpu_features@GOTOFF(%ebx)
jz 2f
leal STRCPY_SSE2@GOTOFF(%ebx), %eax
testl $bit_Fast_Unaligned_Load, FEATURE_OFFSET+index_Fast_Unaligned_Load+__cpu_features@GOTOFF(%ebx)
jnz 2f
testl $bit_SSSE3, CPUID_OFFSET+index_SSSE3+__cpu_features@GOTOFF(%ebx)
jz 2f
leal STRCPY_SSSE3@GOTOFF(%ebx), %eax
2: popl %ebx
cfi_adjust_cfa_offset (-4)
cfi_restore (ebx)
ret
END(STRCPY)
# else
ENTRY(STRCPY)
.type STRCPY, @gnu_indirect_function
cmpl $0, KIND_OFFSET+__cpu_features
jne 1f
call __init_cpu_features
1: leal STRCPY_IA32, %eax
testl $bit_SSE2, CPUID_OFFSET+index_SSE2+__cpu_features
jz 2f
leal STRCPY_SSE2, %eax
testl $bit_Fast_Unaligned_Load, FEATURE_OFFSET+index_Fast_Unaligned_Load+__cpu_features
jnz 2f
testl $bit_SSSE3, CPUID_OFFSET+index_SSSE3+__cpu_features
jz 2f
leal STRCPY_SSSE3, %eax
2: ret
END(STRCPY)
# endif
# undef ENTRY
# define ENTRY(name) \
.type STRCPY_IA32, @function; \
.align 16; \
STRCPY_IA32: cfi_startproc; \
CALL_MCOUNT
# undef END
# define END(name) \
cfi_endproc; .size STRCPY_IA32, .-STRCPY_IA32
# ifdef SHARED
# undef libc_hidden_builtin_def
/* It doesn't make sense to send libc-internal strcpy calls through a PLT.
The speedup we get from using SSSE3 instruction is likely eaten away
by the indirect call in the PLT. */
# define libc_hidden_builtin_def(name) \
.globl __GI_STRCPY; __GI_STRCPY = STRCPY_IA32
# undef libc_hidden_def
# define libc_hidden_def(name) \
.globl __GI___STRCPY; __GI___STRCPY = STRCPY_IA32
# endif
#endif
#ifdef USE_AS_STPCPY
# ifdef USE_AS_STRNCPY
# include "../../stpncpy.S"
# else
# include "../../i586/stpcpy.S"
# endif
#else
# ifndef USE_AS_STRNCPY
# include "../../i586/strcpy.S"
# endif
#endif

View File

@ -0,0 +1,8 @@
#define STRNCPY __strncpy_ia32
#ifdef SHARED
# undef libc_hidden_builtin_def
# define libc_hidden_builtin_def(name) \
__hidden_ver1 (__strncpy_ia32, __GI_strncpy, __strncpy_ia32);
#endif
#include "string/strncpy.c"

View File

@ -0,0 +1,3 @@
#define USE_AS_STRNCPY
#define STRCPY __strncpy_sse2
#include "strcpy-sse2.S"

View File

@ -0,0 +1,3 @@
#define USE_AS_STRNCPY
#define STRCPY __strncpy_ssse3
#include "strcpy-ssse3.S"

View File

@ -0,0 +1,3 @@
#define USE_AS_STRNCPY
#define STRCPY strncpy
#include "strcpy.S"

View File

@ -97,13 +97,18 @@ __init_cpu_features (void)
case 0x2c:
case 0x2e:
case 0x2f:
/* Rep string instructions and copy backward are fast on
Intel Core i3, i5 and i7. */
/* Rep string instructions, copy backward and unaligned loads
are fast on Intel Core i3, i5 and i7. */
#if index_Fast_Rep_String != index_Fast_Copy_Backward
# error index_Fast_Rep_String != index_Fast_Copy_Backward
#endif
#if index_Fast_Rep_String != index_Fast_Unaligned_Load
# error index_Fast_Rep_String != index_Fast_Unaligned_Load
#endif
__cpu_features.feature[index_Fast_Rep_String]
|= bit_Fast_Rep_String | bit_Fast_Copy_Backward;
|= (bit_Fast_Rep_String
| bit_Fast_Copy_Backward
| bit_Fast_Unaligned_Load);
break;
}
}

View File

@ -20,6 +20,7 @@
#define bit_Fast_Copy_Backward (1 << 1)
#define bit_Slow_BSF (1 << 2)
#define bit_Prefer_SSE_for_memop (1 << 3)
#define bit_Fast_Unaligned_Load (1 << 4)
#ifdef __ASSEMBLER__
@ -39,6 +40,7 @@
# define index_Fast_Copy_Backward FEATURE_INDEX_1*FEATURE_SIZE
# define index_Slow_BSF FEATURE_INDEX_1*FEATURE_SIZE
# define index_Prefer_SSE_for_memop FEATURE_INDEX_1*FEATURE_SIZE
# define index_Fast_Unaligned_Load FEATURE_INDEX_1*FEATURE_SIZE
#else /* __ASSEMBLER__ */
@ -112,6 +114,7 @@ extern const struct cpu_features *__get_cpu_features (void)
# define index_Fast_Copy_Backward FEATURE_INDEX_1
# define index_Slow_BSF FEATURE_INDEX_1
# define index_Prefer_SSE_for_memop FEATURE_INDEX_1
# define index_Fast_Unaligned_Load FEATURE_INDEX_1
#define HAS_ARCH_FEATURE(idx, bit) \
((__get_cpu_features ()->feature[idx] & (bit)) != 0)
@ -128,4 +131,7 @@ extern const struct cpu_features *__get_cpu_features (void)
#define HAS_PREFER_SSE_FOR_MEMOP \
HAS_ARCH_FEATURE (index_Prefer_SSE_for_memop, bit_Prefer_SSE_for_memop)
#define HAS_FAST_UNALIGNED_LOAD \
HAS_ARCH_FEATURE (index_Fast_Unaligned_Load, bit_Fast_Unaligned_Load)
#endif /* __ASSEMBLER__ */