1 /* This file is part of the GNU C Library.
2 Copyright (C) 2008, 2009 Free Software Foundation, Inc.
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.
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.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 #include <ifunc-defines.h>
23 #define bit_SSSE3 (1 << 9)
24 #define bit_SSE4_2 (1 << 20)
26 #define index_SSSE3 COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_ECX_OFFSET
27 #define index_SSE4_2 COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_ECX_OFFSET
29 #else /* __ASSEMBLER__ */
31 #include <sys/param.h>
35 COMMON_CPUID_INDEX_1
= 0,
36 /* Keep the following line at the end. */
37 COMMON_CPUID_INDEX_MAX
40 extern struct cpu_features
44 arch_kind_unknown
= 0,
50 struct cpuid_registers
56 } cpuid
[COMMON_CPUID_INDEX_MAX
];
59 } __cpu_features attribute_hidden
;
62 extern void __init_cpu_features (void) attribute_hidden
;
65 if (__cpu_features.kind == arch_kind_unknown) \
66 __init_cpu_features (); \
69 /* Used from outside libc.so to get access to the CPU features structure. */
70 extern const struct cpu_features
*__get_cpu_features (void)
71 __attribute__ ((const));
74 # define __get_cpu_features() (&__cpu_features)
77 #define HAS_CPU_FEATURE(idx, reg, bit) \
78 ((__get_cpu_features ()->cpuid[idx].reg & (1 << (bit))) != 0)
80 /* Following are the feature tests used throughout libc. */
82 #define HAS_SSE2 HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, edx, 26)
83 #define HAS_POPCOUNT HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, 23)
84 #define HAS_SSE4_2 HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, 20)
85 #define HAS_FMA HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, 12)
87 #endif /* __ASSEMBLER__ */