Fix whitespace issue.
[glibc.git] / sysdeps / x86_64 / multiarch / init-arch.h
blob6e409b8f17a86db6f2d3e5539dbe254aa0381693
1 /* This file is part of the GNU C Library.
2 Copyright (C) 2008, 2009, 2010 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 #define bit_Fast_Rep_String (1 << 0)
20 #define bit_Fast_Copy_Backward (1 << 1)
21 #define bit_Slow_BSF (1 << 2)
22 #define bit_Prefer_SSE_for_memop (1 << 3)
24 #ifdef __ASSEMBLER__
26 # include <ifunc-defines.h>
28 # define bit_SSE2 (1 << 26)
29 # define bit_SSSE3 (1 << 9)
30 # define bit_SSE4_1 (1 << 19)
31 # define bit_SSE4_2 (1 << 20)
33 # define index_SSE2 COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_EDX_OFFSET
34 # define index_SSSE3 COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_ECX_OFFSET
35 # define index_SSE4_1 COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_ECX_OFFSET
36 # define index_SSE4_2 COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_ECX_OFFSET
38 # define index_Fast_Rep_String FEATURE_INDEX_1*FEATURE_SIZE
39 # define index_Fast_Copy_Backward FEATURE_INDEX_1*FEATURE_SIZE
40 # define index_Slow_BSF FEATURE_INDEX_1*FEATURE_SIZE
41 # define index_Prefer_SSE_for_memop FEATURE_INDEX_1*FEATURE_SIZE
43 #else /* __ASSEMBLER__ */
45 # include <sys/param.h>
47 enum
49 COMMON_CPUID_INDEX_1 = 0,
50 /* Keep the following line at the end. */
51 COMMON_CPUID_INDEX_MAX
54 enum
56 FEATURE_INDEX_1 = 0,
57 /* Keep the following line at the end. */
58 FEATURE_INDEX_MAX
61 extern struct cpu_features
63 enum cpu_features_kind
65 arch_kind_unknown = 0,
66 arch_kind_intel,
67 arch_kind_amd,
68 arch_kind_other
69 } kind;
70 int max_cpuid;
71 struct cpuid_registers
73 unsigned int eax;
74 unsigned int ebx;
75 unsigned int ecx;
76 unsigned int edx;
77 } cpuid[COMMON_CPUID_INDEX_MAX];
78 unsigned int family;
79 unsigned int model;
80 unsigned int feature[FEATURE_INDEX_MAX];
81 } __cpu_features attribute_hidden;
84 extern void __init_cpu_features (void) attribute_hidden;
85 #define INIT_ARCH()\
86 do \
87 if (__cpu_features.kind == arch_kind_unknown) \
88 __init_cpu_features (); \
89 while (0)
91 /* Used from outside libc.so to get access to the CPU features structure. */
92 extern const struct cpu_features *__get_cpu_features (void)
93 __attribute__ ((const));
95 # ifndef NOT_IN_libc
96 # define __get_cpu_features() (&__cpu_features)
97 # endif
99 # define HAS_CPU_FEATURE(idx, reg, bit) \
100 ((__get_cpu_features ()->cpuid[idx].reg & (1 << (bit))) != 0)
102 /* Following are the feature tests used throughout libc. */
104 # define HAS_SSE2 HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, edx, 26)
105 # define HAS_POPCOUNT HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, 23)
106 # define HAS_SSSE3 HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, 9)
107 # define HAS_SSE4_1 HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, 19)
108 # define HAS_SSE4_2 HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, 20)
109 # define HAS_FMA HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, 12)
111 # define index_Fast_Rep_String FEATURE_INDEX_1
112 # define index_Fast_Copy_Backward FEATURE_INDEX_1
113 # define index_Slow_BSF FEATURE_INDEX_1
114 # define index_Prefer_SSE_for_memop FEATURE_INDEX_1
116 #define HAS_ARCH_FEATURE(idx, bit) \
117 ((__get_cpu_features ()->feature[idx] & (bit)) != 0)
119 #define HAS_FAST_REP_STRING \
120 HAS_ARCH_FEATURE (index_Fast_Rep_String, bit_Fast_Rep_String)
122 #define HAS_FAST_COPY_BACKWARD \
123 HAS_ARCH_FEATURE (index_Fast_Copy_Backward, bit_Fast_Copy_Backward)
125 #define HAS_SLOW_BSF \
126 HAS_ARCH_FEATURE (index_Slow_BSF, bit_Slow_BSF)
128 #define HAS_PREFER_SSE_FOR_MEMOP \
129 HAS_ARCH_FEATURE (index_Prefer_SSE_for_memop, bit_Prefer_SSE_for_memop)
131 #endif /* __ASSEMBLER__ */