Define bit_SSE2 and index_SSE2.
[glibc.git] / sysdeps / x86_64 / multiarch / init-arch.h
blob0f8f77a8a1cb2903175b00945fbbc9469088290e
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_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>
35 enum
37 COMMON_CPUID_INDEX_1 = 0,
38 /* Keep the following line at the end. */
39 COMMON_CPUID_INDEX_MAX
42 extern struct cpu_features
44 enum
46 arch_kind_unknown = 0,
47 arch_kind_intel,
48 arch_kind_amd,
49 arch_kind_other
50 } kind;
51 int max_cpuid;
52 struct cpuid_registers
54 unsigned int eax;
55 unsigned int ebx;
56 unsigned int ecx;
57 unsigned int edx;
58 } cpuid[COMMON_CPUID_INDEX_MAX];
59 unsigned int family;
60 unsigned int model;
61 } __cpu_features attribute_hidden;
64 extern void __init_cpu_features (void) attribute_hidden;
65 #define INIT_ARCH()\
66 do \
67 if (__cpu_features.kind == arch_kind_unknown) \
68 __init_cpu_features (); \
69 while (0)
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));
75 #ifndef NOT_IN_libc
76 # define __get_cpu_features() (&__cpu_features)
77 #endif
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__ */