]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/x86/include/cpu-features.h
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / x86 / include / cpu-features.h
CommitLineData
96203980 1/* Data structure for x86 CPU features.
2b778ceb 2 Copyright (C) 2020-2021 Free Software Foundation, Inc.
96203980
L
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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 <https://www.gnu.org/licenses/>. */
18
19#ifndef _PRIVATE_CPU_FEATURES_H
20#define _PRIVATE_CPU_FEATURES_H 1
21
22#ifdef _CPU_FEATURES_H
23# error this should be impossible
24#endif
25
96203980
L
26/* Get most of the contents from the public header, but we define a
27 different `struct cpu_features' type for private use. */
f380868f
L
28#define cpu_features cpu_features_public
29#define __x86_get_cpu_features __x86_get_cpu_features_public
96203980
L
30
31#include <sysdeps/x86/sys/platform/x86.h>
32
f380868f
L
33#undef cpu_features
34#undef __x86_get_cpu_features
35#define __get_cpu_features() __x86_get_cpu_features (0)
96203980
L
36
37enum
38{
39 /* The integer bit array index for the first set of preferred feature
40 bits. */
41 PREFERRED_FEATURE_INDEX_1 = 0,
42 /* The current maximum size of the feature integer bit array. */
43 PREFERRED_FEATURE_INDEX_MAX
44};
45
46/* Only used directly in cpu-features.c. */
f380868f 47#define CPU_FEATURE_SET(ptr, name) \
96203980 48 ptr->features[index_cpu_##name].usable.reg_##name |= bit_cpu_##name;
f380868f 49#define CPU_FEATURE_UNSET(ptr, name) \
96203980 50 ptr->features[index_cpu_##name].usable.reg_##name &= ~bit_cpu_##name;
f380868f 51#define CPU_FEATURE_SET_USABLE(ptr, name) \
96203980
L
52 ptr->features[index_cpu_##name].usable.reg_##name \
53 |= ptr->features[index_cpu_##name].cpuid.reg_##name & bit_cpu_##name;
f380868f 54#define CPU_FEATURE_PREFERRED_P(ptr, name) \
96203980 55 ((ptr->preferred[index_arch_##name] & bit_arch_##name) != 0)
96203980
L
56
57/* HAS_CPU_FEATURE evaluates to true if CPU supports the feature. */
f380868f
L
58#undef HAS_CPU_FEATURE
59#define HAS_CPU_FEATURE(name) \
96203980
L
60 CPU_FEATURE_CPU_P (__x86_get_cpu_features (0), name)
61/* CPU_FEATURE_USABLE evaluates to true if the feature is usable. */
f380868f
L
62#undef CPU_FEATURE_USABLE
63#define CPU_FEATURE_USABLE(name) \
96203980
L
64 CPU_FEATURE_USABLE_P (__x86_get_cpu_features (0), name)
65/* CPU_FEATURE_PREFER evaluates to true if we prefer the feature at
66 runtime. */
f380868f 67#define CPU_FEATURE_PREFERRED(name) \
96203980
L
68 CPU_FEATURE_PREFERRED_P(__get_cpu_features (), name)
69
f380868f 70#define CPU_FEATURES_CPU_P(ptr, name) \
96203980 71 CPU_FEATURE_CPU_P (ptr, name)
f380868f 72#define CPU_FEATURES_ARCH_P(ptr, name) \
96203980 73 CPU_FEATURE_PREFERRED_P (ptr, name)
f380868f 74#define HAS_ARCH_FEATURE(name) \
96203980
L
75 CPU_FEATURE_PREFERRED (name)
76
77/* PREFERRED_FEATURE_INDEX_1. */
f380868f
L
78#define bit_arch_I586 (1u << 0)
79#define bit_arch_I686 (1u << 1)
80#define bit_arch_Fast_Rep_String (1u << 2)
81#define bit_arch_Fast_Copy_Backward (1u << 3)
82#define bit_arch_Fast_Unaligned_Load (1u << 4)
83#define bit_arch_Fast_Unaligned_Copy (1u << 5)
84#define bit_arch_Slow_BSF (1u << 6)
85#define bit_arch_Slow_SSE4_2 (1u << 7)
86#define bit_arch_AVX_Fast_Unaligned_Load (1u << 8)
87#define bit_arch_Prefer_MAP_32BIT_EXEC (1u << 9)
88#define bit_arch_Prefer_PMINUB_for_stringop (1u << 10)
89#define bit_arch_Prefer_No_VZEROUPPER (1u << 11)
90#define bit_arch_Prefer_ERMS (1u << 12)
91#define bit_arch_Prefer_FSRM (1u << 13)
92#define bit_arch_Prefer_No_AVX512 (1u << 14)
93#define bit_arch_MathVec_Prefer_No_AVX512 (1u << 15)
94
95#define index_arch_Fast_Rep_String PREFERRED_FEATURE_INDEX_1
96#define index_arch_Fast_Copy_Backward PREFERRED_FEATURE_INDEX_1
97#define index_arch_Slow_BSF PREFERRED_FEATURE_INDEX_1
98#define index_arch_Fast_Unaligned_Load PREFERRED_FEATURE_INDEX_1
99#define index_arch_Prefer_PMINUB_for_stringop PREFERRED_FEATURE_INDEX_1
100#define index_arch_Fast_Unaligned_Copy PREFERRED_FEATURE_INDEX_1
101#define index_arch_I586 PREFERRED_FEATURE_INDEX_1
102#define index_arch_I686 PREFERRED_FEATURE_INDEX_1
103#define index_arch_Slow_SSE4_2 PREFERRED_FEATURE_INDEX_1
104#define index_arch_AVX_Fast_Unaligned_Load PREFERRED_FEATURE_INDEX_1
105#define index_arch_Prefer_MAP_32BIT_EXEC PREFERRED_FEATURE_INDEX_1
106#define index_arch_Prefer_No_VZEROUPPER PREFERRED_FEATURE_INDEX_1
107#define index_arch_Prefer_ERMS PREFERRED_FEATURE_INDEX_1
108#define index_arch_Prefer_No_AVX512 PREFERRED_FEATURE_INDEX_1
109#define index_arch_MathVec_Prefer_No_AVX512 PREFERRED_FEATURE_INDEX_1
110#define index_arch_Prefer_FSRM PREFERRED_FEATURE_INDEX_1
96203980
L
111
112/* XCR0 Feature flags. */
f380868f
L
113#define bit_XMM_state (1u << 1)
114#define bit_YMM_state (1u << 2)
115#define bit_Opmask_state (1u << 5)
116#define bit_ZMM0_15_state (1u << 6)
117#define bit_ZMM16_31_state (1u << 7)
118#define bit_XTILECFG_state (1u << 17)
119#define bit_XTILEDATA_state (1u << 18)
96203980
L
120
121struct cpu_features
122{
123 struct cpu_features_basic basic;
124 struct cpuid_features features[COMMON_CPUID_INDEX_MAX];
125 unsigned int preferred[PREFERRED_FEATURE_INDEX_MAX];
126 /* The state size for XSAVEC or XSAVE. The type must be unsigned long
127 int so that we use
128
129 sub xsave_state_size_offset(%rip) %RSP_LP
130
131 in _dl_runtime_resolve. */
132 unsigned long int xsave_state_size;
133 /* The full state size for XSAVE when XSAVEC is disabled by
134
135 GLIBC_TUNABLES=glibc.cpu.hwcaps=-XSAVEC
136 */
137 unsigned int xsave_state_full_size;
138 /* Data cache size for use in memory and string routines, typically
139 L1 size. */
140 unsigned long int data_cache_size;
141 /* Shared cache size for use in memory and string routines, typically
142 L2 or L3 size. */
143 unsigned long int shared_cache_size;
144 /* Threshold to use non temporal store. */
145 unsigned long int non_temporal_threshold;
146 /* Threshold to use "rep movsb". */
147 unsigned long int rep_movsb_threshold;
148 /* Threshold to use "rep stosb". */
149 unsigned long int rep_stosb_threshold;
150};
151
f380868f 152#if defined (_LIBC) && !IS_IN (nonlib)
96203980 153/* Unused for x86. */
f380868f
L
154# define INIT_ARCH()
155# define __x86_get_cpu_features(max) (&GLRO(dl_x86_cpu_features))
0f09154c 156extern void _dl_x86_init_cpu_features (void) attribute_hidden;
f380868f 157#endif
96203980 158
f380868f
L
159#ifdef __x86_64__
160# define HAS_CPUID 1
161#elif (defined __i586__ || defined __pentium__ \
96203980 162 || defined __geode__ || defined __k6__)
f380868f
L
163# define HAS_CPUID 1
164# define HAS_I586 1
165# define HAS_I686 HAS_ARCH_FEATURE (I686)
166#elif defined __i486__
167# define HAS_CPUID 0
168# define HAS_I586 HAS_ARCH_FEATURE (I586)
169# define HAS_I686 HAS_ARCH_FEATURE (I686)
170#else
171# define HAS_CPUID 1
172# define HAS_I586 1
173# define HAS_I686 1
96203980
L
174# endif
175
96203980 176#endif /* include/cpu-features.h */