Define bit_XXX and index_XXX.
[glibc.git] / sysdeps / x86_64 / multiarch / init-arch.h
blob9e8915fa40d5dccb9d1c239fa8c33e2cf2a50f75
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
17 02111-1307 USA. */
19 #ifdef __ASSEMBLER__
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>
33 enum
35 COMMON_CPUID_INDEX_1 = 0,
36 /* Keep the following line at the end. */
37 COMMON_CPUID_INDEX_MAX
40 extern struct cpu_features
42 enum
44 arch_kind_unknown = 0,
45 arch_kind_intel,
46 arch_kind_amd,
47 arch_kind_other
48 } kind;
49 int max_cpuid;
50 struct cpuid_registers
52 unsigned int eax;
53 unsigned int ebx;
54 unsigned int ecx;
55 unsigned int edx;
56 } cpuid[COMMON_CPUID_INDEX_MAX];
57 unsigned int family;
58 unsigned int model;
59 } __cpu_features attribute_hidden;
62 extern void __init_cpu_features (void) attribute_hidden;
63 #define INIT_ARCH()\
64 do \
65 if (__cpu_features.kind == arch_kind_unknown) \
66 __init_cpu_features (); \
67 while (0)
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));
73 #ifndef NOT_IN_libc
74 # define __get_cpu_features() (&__cpu_features)
75 #endif
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__ */