• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef CPU_FEATURES_INCLUDE_CPU_FEATURES_MACROS_H_
16 #define CPU_FEATURES_INCLUDE_CPU_FEATURES_MACROS_H_
17 
18 ////////////////////////////////////////////////////////////////////////////////
19 // Architectures
20 ////////////////////////////////////////////////////////////////////////////////
21 
22 #if defined(__pnacl__) || defined(__CLR_VER)
23 #define CPU_FEATURES_ARCH_VM
24 #endif
25 
26 #if (defined(_M_IX86) || defined(__i386__)) && !defined(CPU_FEATURES_ARCH_VM)
27 #define CPU_FEATURES_ARCH_X86_32
28 #endif
29 
30 #if (defined(_M_X64) || defined(__x86_64__)) && !defined(CPU_FEATURES_ARCH_VM)
31 #define CPU_FEATURES_ARCH_X86_64
32 #endif
33 
34 #if defined(CPU_FEATURES_ARCH_X86_32) || defined(CPU_FEATURES_ARCH_X86_64)
35 #define CPU_FEATURES_ARCH_X86
36 #endif
37 
38 #if (defined(__arm__) || defined(_M_ARM))
39 #define CPU_FEATURES_ARCH_ARM
40 #endif
41 
42 #if defined(__aarch64__)
43 #define CPU_FEATURES_ARCH_AARCH64
44 #endif
45 
46 #if (defined(CPU_FEATURES_ARCH_AARCH64) || defined(CPU_FEATURES_ARCH_ARM))
47 #define CPU_FEATURES_ARCH_ANY_ARM
48 #endif
49 
50 #if defined(__mips64)
51 #define CPU_FEATURES_ARCH_MIPS64
52 #endif
53 
54 #if defined(__mips__) && !defined(__mips64)  // mips64 also declares __mips__
55 #define CPU_FEATURES_ARCH_MIPS32
56 #endif
57 
58 #if defined(CPU_FEATURES_ARCH_MIPS32) || defined(CPU_FEATURES_ARCH_MIPS64)
59 #define CPU_FEATURES_ARCH_MIPS
60 #endif
61 
62 #if defined(__powerpc__)
63 #define CPU_FEATURES_ARCH_PPC
64 #endif
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 // Os
68 ////////////////////////////////////////////////////////////////////////////////
69 
70 #if defined(__linux__)
71 #define CPU_FEATURES_OS_LINUX_OR_ANDROID
72 #endif
73 
74 #if defined(__ANDROID__)
75 #define CPU_FEATURES_OS_ANDROID
76 #endif
77 
78 #if (defined(_WIN64) || defined(_WIN32))
79 #define CPU_FEATURES_OS_WINDOWS
80 #endif
81 
82 #if (defined(__apple__) || defined(__APPLE__) || defined(__MACH__))
83 #define CPU_FEATURES_OS_DARWIN
84 #endif
85 
86 ////////////////////////////////////////////////////////////////////////////////
87 // Compilers
88 ////////////////////////////////////////////////////////////////////////////////
89 
90 #if defined(__clang__)
91 #define CPU_FEATURES_COMPILER_CLANG
92 #endif
93 
94 #if defined(__GNUC__) && !defined(__clang__)
95 #define CPU_FEATURES_COMPILER_GCC
96 #endif
97 
98 #if defined(_MSC_VER)
99 #define CPU_FEATURES_COMPILER_MSC
100 #endif
101 
102 ////////////////////////////////////////////////////////////////////////////////
103 // Cpp
104 ////////////////////////////////////////////////////////////////////////////////
105 
106 #if defined(__cplusplus)
107 #define CPU_FEATURES_START_CPP_NAMESPACE \
108   namespace cpu_features {               \
109   extern "C" {
110 #define CPU_FEATURES_END_CPP_NAMESPACE \
111   }                                    \
112   }
113 #else
114 #define CPU_FEATURES_START_CPP_NAMESPACE
115 #define CPU_FEATURES_END_CPP_NAMESPACE
116 #endif
117 
118 ////////////////////////////////////////////////////////////////////////////////
119 // Compiler flags
120 ////////////////////////////////////////////////////////////////////////////////
121 
122 // Use the following to check if a feature is known to be available at
123 // compile time. See README.md for an example.
124 #if defined(CPU_FEATURES_ARCH_X86)
125 
126 #if defined(__AES__)
127 #define CPU_FEATURES_COMPILED_X86_AES 1
128 #else
129 #define CPU_FEATURES_COMPILED_X86_AES 0
130 #endif  //  defined(__AES__)
131 
132 #if defined(__F16C__)
133 #define CPU_FEATURES_COMPILED_X86_F16C 1
134 #else
135 #define CPU_FEATURES_COMPILED_X86_F16C 0
136 #endif  //  defined(__F16C__)
137 
138 #if defined(__BMI__)
139 #define CPU_FEATURES_COMPILED_X86_BMI 1
140 #else
141 #define CPU_FEATURES_COMPILED_X86_BMI 0
142 #endif  //  defined(__BMI__)
143 
144 #if defined(__BMI2__)
145 #define CPU_FEATURES_COMPILED_X86_BMI2 1
146 #else
147 #define CPU_FEATURES_COMPILED_X86_BMI2 0
148 #endif  //  defined(__BMI2__)
149 
150 #if (defined(__SSE__) || (_M_IX86_FP >= 1))
151 #define CPU_FEATURES_COMPILED_X86_SSE 1
152 #else
153 #define CPU_FEATURES_COMPILED_X86_SSE 0
154 #endif
155 
156 #if (defined(__SSE2__) || (_M_IX86_FP >= 2))
157 #define CPU_FEATURES_COMPILED_X86_SSE2 1
158 #else
159 #define CPU_FEATURES_COMPILED_X86_SSE2 0
160 #endif
161 
162 #if defined(__SSE3__)
163 #define CPU_FEATURES_COMPILED_X86_SSE3 1
164 #else
165 #define CPU_FEATURES_COMPILED_X86_SSE3 0
166 #endif  //  defined(__SSE3__)
167 
168 #if defined(__SSSE3__)
169 #define CPU_FEATURES_COMPILED_X86_SSSE3 1
170 #else
171 #define CPU_FEATURES_COMPILED_X86_SSSE3 0
172 #endif  //  defined(__SSSE3__)
173 
174 #if defined(__SSE4_1__)
175 #define CPU_FEATURES_COMPILED_X86_SSE4_1 1
176 #else
177 #define CPU_FEATURES_COMPILED_X86_SSE4_1 0
178 #endif  //  defined(__SSE4_1__)
179 
180 #if defined(__SSE4_2__)
181 #define CPU_FEATURES_COMPILED_X86_SSE4_2 1
182 #else
183 #define CPU_FEATURES_COMPILED_X86_SSE4_2 0
184 #endif  //  defined(__SSE4_2__)
185 
186 #if defined(__AVX__)
187 #define CPU_FEATURES_COMPILED_X86_AVX 1
188 #else
189 #define CPU_FEATURES_COMPILED_X86_AVX 0
190 #endif  //  defined(__AVX__)
191 
192 #if defined(__AVX2__)
193 #define CPU_FEATURES_COMPILED_X86_AVX2 1
194 #else
195 #define CPU_FEATURES_COMPILED_X86_AVX2 0
196 #endif  //  defined(__AVX2__)
197 
198 #endif  // defined(CPU_FEATURES_ARCH_X86)
199 
200 #if defined(CPU_FEATURES_ARCH_ANY_ARM)
201 #if defined(__ARM_NEON__)
202 #define CPU_FEATURES_COMPILED_ANY_ARM_NEON 1
203 #else
204 #define CPU_FEATURES_COMPILED_ANY_ARM_NEON 0
205 #endif  //  defined(__ARM_NEON__)
206 #endif  //  defined(CPU_FEATURES_ARCH_ANY_ARM)
207 
208 #if defined(CPU_FEATURES_ARCH_MIPS)
209 #if defined(__mips_msa)
210 #define CPU_FEATURES_COMPILED_MIPS_MSA 1
211 #else
212 #define CPU_FEATURES_COMPILED_MIPS_MSA 0
213 #endif  //  defined(__mips_msa)
214 #endif  //  defined(CPU_FEATURES_ARCH_MIPS)
215 
216 #endif  // CPU_FEATURES_INCLUDE_CPU_FEATURES_MACROS_H_
217