]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/x86_64/multiarch/strstr.c
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / x86_64 / multiarch / strstr.c
1 /* Multiple versions of strstr.
2 All versions must be listed in ifunc-impl-list.c.
3 Copyright (C) 2012-2023 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
19
20 /* Redefine strstr so that the compiler won't complain about the type
21 mismatch with the IFUNC selector in strong_alias, below. */
22 #undef strstr
23 #define strstr __redirect_strstr
24 #include <string.h>
25 #undef strstr
26
27 #define STRSTR __strstr_generic
28 #ifdef SHARED
29 # undef libc_hidden_builtin_def
30 # define libc_hidden_builtin_def(name) \
31 __hidden_ver1 (__strstr_generic, __GI_strstr, __strstr_generic);
32 #endif
33
34 #include "string/strstr.c"
35
36 extern __typeof (__redirect_strstr) __strstr_sse2_unaligned attribute_hidden;
37 extern __typeof (__redirect_strstr) __strstr_generic attribute_hidden;
38 extern __typeof (__redirect_strstr) __strstr_avx512 attribute_hidden;
39
40 #include "init-arch.h"
41
42 /* Avoid DWARF definition DIE on ifunc symbol so that GDB can handle
43 ifunc symbol properly. */
44 extern __typeof (__redirect_strstr) __libc_strstr;
45
46 static inline void *
47 IFUNC_SELECTOR (void)
48 {
49 const struct cpu_features *cpu_features = __get_cpu_features ();
50
51 if (!CPU_FEATURES_ARCH_P (cpu_features, Prefer_No_AVX512)
52 && CPU_FEATURE_USABLE_P (cpu_features, AVX512VL)
53 && CPU_FEATURE_USABLE_P (cpu_features, AVX512BW)
54 && CPU_FEATURE_USABLE_P (cpu_features, AVX512DQ)
55 && CPU_FEATURE_USABLE_P (cpu_features, BMI2))
56 return __strstr_avx512;
57
58 if (CPU_FEATURES_ARCH_P (cpu_features, Fast_Unaligned_Load))
59 return __strstr_sse2_unaligned;
60
61 return __strstr_generic;
62 }
63
64 libc_ifunc_redirected (__redirect_strstr, __libc_strstr, IFUNC_SELECTOR ());
65 #undef strstr
66 strong_alias (__libc_strstr, strstr)