]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/x86_64/multiarch/init-arch.h
Skip SSE4.2 versions on Intel Silvermont
[thirdparty/glibc.git] / sysdeps / x86_64 / multiarch / init-arch.h
1 /* This file is part of the GNU C Library.
2 Copyright (C) 2008-2013 Free Software Foundation, Inc.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #define bit_Fast_Rep_String (1 << 0)
19 #define bit_Fast_Copy_Backward (1 << 1)
20 #define bit_Slow_BSF (1 << 2)
21 #define bit_Fast_Unaligned_Load (1 << 4)
22 #define bit_Prefer_PMINUB_for_stringop (1 << 5)
23 #define bit_AVX_Usable (1 << 6)
24 #define bit_FMA_Usable (1 << 7)
25 #define bit_FMA4_Usable (1 << 8)
26 #define bit_Slow_SSE4_2 (1 << 9)
27
28 /* CPUID Feature flags. */
29
30 /* COMMON_CPUID_INDEX_1. */
31 #define bit_SSE2 (1 << 26)
32 #define bit_SSSE3 (1 << 9)
33 #define bit_SSE4_1 (1 << 19)
34 #define bit_SSE4_2 (1 << 20)
35 #define bit_OSXSAVE (1 << 27)
36 #define bit_AVX (1 << 28)
37 #define bit_POPCOUNT (1 << 23)
38 #define bit_FMA (1 << 12)
39 #define bit_FMA4 (1 << 16)
40
41 /* COMMON_CPUID_INDEX_7. */
42 #define bit_RTM (1 << 11)
43
44 /* XCR0 Feature flags. */
45 #define bit_XMM_state (1 << 1)
46 #define bit_YMM_state (2 << 1)
47
48 #ifdef __ASSEMBLER__
49
50 # include <ifunc-defines.h>
51
52 # define index_SSE2 COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_EDX_OFFSET
53 # define index_SSSE3 COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_ECX_OFFSET
54 # define index_SSE4_1 COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_ECX_OFFSET
55 # define index_SSE4_2 COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_ECX_OFFSET
56 # define index_AVX COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_ECX_OFFSET
57
58 # define index_Fast_Rep_String FEATURE_INDEX_1*FEATURE_SIZE
59 # define index_Fast_Copy_Backward FEATURE_INDEX_1*FEATURE_SIZE
60 # define index_Slow_BSF FEATURE_INDEX_1*FEATURE_SIZE
61 # define index_Fast_Unaligned_Load FEATURE_INDEX_1*FEATURE_SIZE
62 # define index_Prefer_PMINUB_for_stringop FEATURE_INDEX_1*FEATURE_SIZE
63 # define index_AVX_Usable FEATURE_INDEX_1*FEATURE_SIZE
64 # define index_FMA_Usable FEATURE_INDEX_1*FEATURE_SIZE
65 # define index_FMA4_Usable FEATURE_INDEX_1*FEATURE_SIZE
66 # define index_Slow_SSE4_2 FEATURE_INDEX_1*FEATURE_SIZE
67
68 #else /* __ASSEMBLER__ */
69
70 # include <sys/param.h>
71
72 enum
73 {
74 COMMON_CPUID_INDEX_1 = 0,
75 COMMON_CPUID_INDEX_7,
76 COMMON_CPUID_INDEX_80000001, /* for AMD */
77 /* Keep the following line at the end. */
78 COMMON_CPUID_INDEX_MAX
79 };
80
81 enum
82 {
83 FEATURE_INDEX_1 = 0,
84 /* Keep the following line at the end. */
85 FEATURE_INDEX_MAX
86 };
87
88 extern struct cpu_features
89 {
90 enum cpu_features_kind
91 {
92 arch_kind_unknown = 0,
93 arch_kind_intel,
94 arch_kind_amd,
95 arch_kind_other
96 } kind;
97 int max_cpuid;
98 struct cpuid_registers
99 {
100 unsigned int eax;
101 unsigned int ebx;
102 unsigned int ecx;
103 unsigned int edx;
104 } cpuid[COMMON_CPUID_INDEX_MAX];
105 unsigned int family;
106 unsigned int model;
107 unsigned int feature[FEATURE_INDEX_MAX];
108 } __cpu_features attribute_hidden;
109
110
111 extern void __init_cpu_features (void) attribute_hidden;
112 # define INIT_ARCH() \
113 do \
114 if (__cpu_features.kind == arch_kind_unknown) \
115 __init_cpu_features (); \
116 while (0)
117
118 /* Used from outside libc.so to get access to the CPU features structure. */
119 extern const struct cpu_features *__get_cpu_features (void)
120 __attribute__ ((const));
121
122 # ifndef NOT_IN_libc
123 # define __get_cpu_features() (&__cpu_features)
124 # endif
125
126 # define HAS_CPU_FEATURE(idx, reg, bit) \
127 ((__get_cpu_features ()->cpuid[idx].reg & (bit)) != 0)
128
129 /* Following are the feature tests used throughout libc. */
130
131 /* CPUID_* evaluates to true if the feature flag is enabled.
132 We always use &__cpu_features because the HAS_CPUID_* macros
133 are called only within __init_cpu_features, where we can't
134 call __get_cpu_features without infinite recursion. */
135 # define HAS_CPUID_FLAG(idx, reg, bit) \
136 (((&__cpu_features)->cpuid[idx].reg & (bit)) != 0)
137
138 # define CPUID_OSXSAVE \
139 HAS_CPUID_FLAG (COMMON_CPUID_INDEX_1, ecx, bit_OSXSAVE)
140 # define CPUID_AVX \
141 HAS_CPUID_FLAG (COMMON_CPUID_INDEX_1, ecx, bit_AVX)
142 # define CPUID_FMA \
143 HAS_CPUID_FLAG (COMMON_CPUID_INDEX_1, ecx, bit_FMA)
144 # define CPUID_FMA4 \
145 HAS_CPUID_FLAG (COMMON_CPUID_INDEX_80000001, ecx, bit_FMA4)
146 # define CPUID_RTM \
147 HAS_CPUID_FLAG (COMMON_CPUID_INDEX_7, ebx, bit_RTM)
148
149 /* HAS_* evaluates to true if we may use the feature at runtime. */
150 # define HAS_SSE2 HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, edx, bit_SSE2)
151 # define HAS_POPCOUNT HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, bit_POPCOUNT)
152 # define HAS_SSSE3 HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, bit_SSSE3)
153 # define HAS_SSE4_1 HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, bit_SSE4_1)
154 # define HAS_SSE4_2 HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, bit_SSE4_2)
155 # define HAS_RTM HAS_CPU_FEATURE (COMMON_CPUID_INDEX_7, ebx, bit_RTM)
156
157 # define index_Fast_Rep_String FEATURE_INDEX_1
158 # define index_Fast_Copy_Backward FEATURE_INDEX_1
159 # define index_Slow_BSF FEATURE_INDEX_1
160 # define index_Fast_Unaligned_Load FEATURE_INDEX_1
161 # define index_Prefer_PMINUB_for_stringop FEATURE_INDEX_1
162 # define index_AVX_Usable FEATURE_INDEX_1
163 # define index_FMA_Usable FEATURE_INDEX_1
164 # define index_FMA4_Usable FEATURE_INDEX_1
165 # define index_Slow_SSE4_2 FEATURE_INDEX_1
166
167 # define HAS_ARCH_FEATURE(name) \
168 ((__get_cpu_features ()->feature[index_##name] & (bit_##name)) != 0)
169
170 # define HAS_FAST_REP_STRING HAS_ARCH_FEATURE (Fast_Rep_String)
171 # define HAS_FAST_COPY_BACKWARD HAS_ARCH_FEATURE (Fast_Copy_Backward)
172 # define HAS_SLOW_BSF HAS_ARCH_FEATURE (Slow_BSF)
173 # define HAS_FAST_UNALIGNED_LOAD HAS_ARCH_FEATURE (Fast_Unaligned_Load)
174 # define HAS_AVX HAS_ARCH_FEATURE (AVX_Usable)
175 # define HAS_FMA HAS_ARCH_FEATURE (FMA_Usable)
176 # define HAS_FMA4 HAS_ARCH_FEATURE (FMA4_Usable)
177
178 #endif /* __ASSEMBLER__ */