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_SSE2 (1 << 26)
24 #define bit_SSSE3 (1 << 9)
25 #define bit_SSE4_2 (1 << 20)
27 #define index_SSE2 COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_EDX_OFFSET
28 #define index_SSSE3 COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_ECX_OFFSET
29 #define index_SSE4_2 COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_ECX_OFFSET
31 #else /* __ASSEMBLER__ */
33 #include <sys/param.h>
37 COMMON_CPUID_INDEX_1
= 0,
38 /* Keep the following line at the end. */
39 COMMON_CPUID_INDEX_MAX
42 extern struct cpu_features
46 arch_kind_unknown
= 0,
52 struct cpuid_registers
58 } cpuid
[COMMON_CPUID_INDEX_MAX
];
61 } __cpu_features attribute_hidden
;
64 extern void __init_cpu_features (void) attribute_hidden
;
67 if (__cpu_features.kind == arch_kind_unknown) \
68 __init_cpu_features (); \
71 /* Used from outside libc.so to get access to the CPU features structure. */
72 extern const struct cpu_features
*__get_cpu_features (void)
73 __attribute__ ((const));
76 # define __get_cpu_features() (&__cpu_features)
79 #define HAS_CPU_FEATURE(idx, reg, bit) \
80 ((__get_cpu_features ()->cpuid[idx].reg & (1 << (bit))) != 0)
82 /* Following are the feature tests used throughout libc. */
84 #define HAS_SSE2 HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, edx, 26)
85 #define HAS_POPCOUNT HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, 23)
86 #define HAS_SSE4_2 HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, 20)
87 #define HAS_FMA HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, 12)
89 #endif /* __ASSEMBLER__ */