Use IFUNC memmove/memset in x86-64 bcopy/bzero
[glibc.git] / sysdeps / x86_64 / multiarch / memset.S
blob10f00bf9e96496cb6c391050004dd7cd1ce51af5
1 /* Multiple versions of memset
2    Copyright (C) 2010-2012 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <http://www.gnu.org/licenses/>.  */
19 #include <sysdep.h>
20 #include <init-arch.h>
22 /* Define multiple versions only for the definition in lib.  */
23 #ifndef NOT_IN_libc
24 ENTRY(memset)
25         .type   memset, @gnu_indirect_function
26         cmpl    $0, __cpu_features+KIND_OFFSET(%rip)
27         jne     1f
28         call    __init_cpu_features
29 1:      leaq    __memset_x86_64(%rip), %rax
30         testl   $bit_Prefer_SSE_for_memop, __cpu_features+FEATURE_OFFSET+index_Prefer_SSE_for_memop(%rip)
31         jz      2f
32         leaq    __memset_sse2(%rip), %rax
33 2:      ret
34 END(memset)
36 /* Define internal IFUNC memset for bzero.  */
37         .globl __libc_memset
38         .hidden __libc_memset
39         __libc_memset = memset
41 # define USE_SSE2 1
43 # undef ENTRY
44 # define ENTRY(name) \
45         .type __memset_sse2, @function; \
46         .globl __memset_sse2; \
47         .p2align 4; \
48         __memset_sse2: cfi_startproc; \
49         CALL_MCOUNT
50 # undef END
51 # define END(name) \
52         cfi_endproc; .size __memset_sse2, .-__memset_sse2
54 # undef ENTRY_CHK
55 # define ENTRY_CHK(name) \
56         .type __memset_chk_sse2, @function; \
57         .globl __memset_chk_sse2; \
58         .p2align 4; \
59         __memset_chk_sse2: cfi_startproc; \
60         CALL_MCOUNT
61 # undef END_CHK
62 # define END_CHK(name) \
63         cfi_endproc; .size __memset_chk_sse2, .-__memset_chk_sse2
65 # ifdef SHARED
66 #  undef libc_hidden_builtin_def
67 /* It doesn't make sense to send libc-internal memset calls through a PLT.
68    The speedup we get from using GPR instruction is likely eaten away
69    by the indirect call in the PLT.  */
70 #  define libc_hidden_builtin_def(name) \
71         .globl __GI_memset; __GI_memset = __memset_sse2
72 # endif
74 # undef strong_alias
75 # define strong_alias(original, alias)
76 #endif
78 #include "../memset.S"