Update copyright dates with scripts/update-copyrights
[glibc.git] / sysdeps / x86 / sys / platform / x86.h
blob1ea2c5fc0b666d2367f706c56c66b2ce6b3f3a75
1 /* Data structure for x86 CPU features.
2 This file is part of the GNU C Library.
3 Copyright (C) 2008-2023 Free Software Foundation, Inc.
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.
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.
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/>. */
19 #ifndef _SYS_PLATFORM_X86_H
20 #define _SYS_PLATFORM_X86_H
22 #include <features.h>
23 #include <stdbool.h>
24 #include <bits/platform/x86.h>
26 __BEGIN_DECLS
28 /* Get a pointer to the CPU feature structure. */
29 extern const struct cpuid_feature *__x86_get_cpuid_feature_leaf (unsigned int)
30 __attribute__ ((pure));
32 static __inline__ _Bool
33 x86_cpu_present (unsigned int __index)
35 const struct cpuid_feature *__ptr = __x86_get_cpuid_feature_leaf
36 (__index / (8 * sizeof (unsigned int) * 4));
37 unsigned int __reg
38 = __index & (8 * sizeof (unsigned int) * 4 - 1);
39 unsigned int __bit = __reg & (8 * sizeof (unsigned int) - 1);
40 __reg /= 8 * sizeof (unsigned int);
42 return __ptr->cpuid_array[__reg] & (1 << __bit);
45 static __inline__ _Bool
46 x86_cpu_active (unsigned int __index)
48 const struct cpuid_feature *__ptr = __x86_get_cpuid_feature_leaf
49 (__index / (8 * sizeof (unsigned int) * 4));
50 unsigned int __reg
51 = __index & (8 * sizeof (unsigned int) * 4 - 1);
52 unsigned int __bit = __reg & (8 * sizeof (unsigned int) - 1);
53 __reg /= 8 * sizeof (unsigned int);
55 return __ptr->active_array[__reg] & (1 << __bit);
58 /* CPU_FEATURE_PRESENT evaluates to true if CPU supports the feature. */
59 #define CPU_FEATURE_PRESENT(name) x86_cpu_present (x86_cpu_##name)
60 /* CPU_FEATURE_ACTIVE evaluates to true if the feature is active. */
61 #define CPU_FEATURE_ACTIVE(name) x86_cpu_active (x86_cpu_##name)
63 __END_DECLS
65 #endif /* _SYS_PLATFORM_X86_H */