RISC-V: Use an autoconf template to produce `preconfigure'
[glibc.git] / sysdeps / x86_64 / multiarch / bzero.c
blob58a14b2c334051ea5ec62cbb5d817858f29ee092
1 /* Multiple versions of bzero.
2 All versions must be listed in ifunc-impl-list.c.
3 Copyright (C) 2022 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
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.
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.
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/>. */
20 /* Define multiple versions only for the definition in libc. */
21 #if IS_IN (libc)
22 # define __bzero __redirect___bzero
23 # include <string.h>
24 # undef __bzero
26 # define SYMBOL_NAME __bzero
27 # include <init-arch.h>
29 extern __typeof (REDIRECT_NAME) OPTIMIZE1 (sse2_unaligned)
30 attribute_hidden;
31 extern __typeof (REDIRECT_NAME) OPTIMIZE1 (sse2_unaligned_erms)
32 attribute_hidden;
33 extern __typeof (REDIRECT_NAME) OPTIMIZE1 (avx2_unaligned) attribute_hidden;
34 extern __typeof (REDIRECT_NAME) OPTIMIZE1 (avx2_unaligned_erms)
35 attribute_hidden;
36 extern __typeof (REDIRECT_NAME) OPTIMIZE1 (avx2_unaligned_rtm)
37 attribute_hidden;
38 extern __typeof (REDIRECT_NAME) OPTIMIZE1 (avx2_unaligned_erms_rtm)
39 attribute_hidden;
40 extern __typeof (REDIRECT_NAME) OPTIMIZE1 (evex_unaligned)
41 attribute_hidden;
42 extern __typeof (REDIRECT_NAME) OPTIMIZE1 (evex_unaligned_erms)
43 attribute_hidden;
44 extern __typeof (REDIRECT_NAME) OPTIMIZE1 (avx512_unaligned)
45 attribute_hidden;
46 extern __typeof (REDIRECT_NAME) OPTIMIZE1 (avx512_unaligned_erms)
47 attribute_hidden;
49 static inline void *
50 IFUNC_SELECTOR (void)
52 const struct cpu_features* cpu_features = __get_cpu_features ();
54 if (CPU_FEATURE_USABLE_P (cpu_features, AVX512F)
55 && !CPU_FEATURES_ARCH_P (cpu_features, Prefer_No_AVX512))
57 if (CPU_FEATURE_USABLE_P (cpu_features, AVX512VL)
58 && CPU_FEATURE_USABLE_P (cpu_features, AVX512BW)
59 && CPU_FEATURE_USABLE_P (cpu_features, BMI2))
61 if (CPU_FEATURE_USABLE_P (cpu_features, ERMS))
62 return OPTIMIZE1 (avx512_unaligned_erms);
64 return OPTIMIZE1 (avx512_unaligned);
68 if (CPU_FEATURE_USABLE_P (cpu_features, AVX2))
70 if (CPU_FEATURE_USABLE_P (cpu_features, AVX512VL)
71 && CPU_FEATURE_USABLE_P (cpu_features, AVX512BW)
72 && CPU_FEATURE_USABLE_P (cpu_features, BMI2))
74 if (CPU_FEATURE_USABLE_P (cpu_features, ERMS))
75 return OPTIMIZE1 (evex_unaligned_erms);
77 return OPTIMIZE1 (evex_unaligned);
80 if (CPU_FEATURE_USABLE_P (cpu_features, RTM))
82 if (CPU_FEATURE_USABLE_P (cpu_features, ERMS))
83 return OPTIMIZE1 (avx2_unaligned_erms_rtm);
85 return OPTIMIZE1 (avx2_unaligned_rtm);
88 if (!CPU_FEATURES_ARCH_P (cpu_features, Prefer_No_VZEROUPPER))
90 if (CPU_FEATURE_USABLE_P (cpu_features, ERMS))
91 return OPTIMIZE1 (avx2_unaligned_erms);
93 return OPTIMIZE1 (avx2_unaligned);
97 if (CPU_FEATURE_USABLE_P (cpu_features, ERMS))
98 return OPTIMIZE1 (sse2_unaligned_erms);
100 return OPTIMIZE1 (sse2_unaligned);
103 libc_ifunc_redirected (__redirect___bzero, __bzero, IFUNC_SELECTOR ());
105 weak_alias (__bzero, bzero)
106 #endif