1/* Data structure for x86 CPU features.
2 This file is part of the GNU C Library.
3 Copyright (C) 2008-2024 Free Software Foundation, Inc.
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 _SYS_PLATFORM_X86_H
20#define _SYS_PLATFORM_X86_H
21
22#include <features.h>
23#include <stdbool.h>
24#include <bits/platform/x86.h>
25#include <bits/platform/features.h>
26
27__BEGIN_DECLS
28
29/* Get a pointer to the CPU feature structure. */
30extern const struct cpuid_feature *__x86_get_cpuid_feature_leaf (unsigned int)
31 __attribute__ ((pure));
32
33static __inline__ _Bool
34x86_cpu_present (unsigned int __index)
35{
36 const struct cpuid_feature *__ptr = __x86_get_cpuid_feature_leaf
37 (__index / (8 * sizeof (unsigned int) * 4));
38 unsigned int __reg
39 = __index & (8 * sizeof (unsigned int) * 4 - 1);
40 unsigned int __bit = __reg & (8 * sizeof (unsigned int) - 1);
41 __reg /= 8 * sizeof (unsigned int);
42
43 return __ptr->cpuid_array[__reg] & (1 << __bit);
44}
45
46static __inline__ _Bool
47x86_cpu_active (unsigned int __index)
48{
49 if (__index == x86_cpu_IBT || __index == x86_cpu_SHSTK)
50 return x86_cpu_cet_active (__index);
51
52 const struct cpuid_feature *__ptr = __x86_get_cpuid_feature_leaf
53 (__index / (8 * sizeof (unsigned int) * 4));
54 unsigned int __reg
55 = __index & (8 * sizeof (unsigned int) * 4 - 1);
56 unsigned int __bit = __reg & (8 * sizeof (unsigned int) - 1);
57 __reg /= 8 * sizeof (unsigned int);
58
59 return __ptr->active_array[__reg] & (1 << __bit);
60}
61
62/* CPU_FEATURE_PRESENT evaluates to true if CPU supports the feature. */
63#define CPU_FEATURE_PRESENT(name) x86_cpu_present (x86_cpu_##name)
64/* CPU_FEATURE_ACTIVE evaluates to true if the feature is active. */
65#define CPU_FEATURE_ACTIVE(name) x86_cpu_active (x86_cpu_##name)
66
67__END_DECLS
68
69#endif /* _SYS_PLATFORM_X86_H */
70

source code of glibc/sysdeps/x86/sys/platform/x86.h