1 // Copyright 2017 Google Inc.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 #ifndef CPU_FEATURES_INCLUDE_CPU_FEATURES_MACROS_H_
16 #define CPU_FEATURES_INCLUDE_CPU_FEATURES_MACROS_H_
18 ////////////////////////////////////////////////////////////////////////////////
20 ////////////////////////////////////////////////////////////////////////////////
22 #if ((defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || \
23 defined(__x86_64__)) && \
24 !defined(__pnacl__) && !defined(__CLR_VER))
25 #define CPU_FEATURES_ARCH_X86
28 #if (defined(__arm__) || defined(_M_ARM))
29 #define CPU_FEATURES_ARCH_ARM
32 #if defined(__aarch64__)
33 #define CPU_FEATURES_ARCH_AARCH64
36 #if (defined(CPU_FEATURES_ARCH_AARCH64) || defined(CPU_FEATURES_ARCH_ARM))
37 #define CPU_FEATURES_ARCH_ANY_ARM
41 #define CPU_FEATURES_ARCH_MIPS
44 #if defined(__powerpc__)
45 #define CPU_FEATURES_ARCH_PPC
48 ////////////////////////////////////////////////////////////////////////////////
50 ////////////////////////////////////////////////////////////////////////////////
52 #if defined(__linux__)
53 #define CPU_FEATURES_OS_LINUX_OR_ANDROID
56 #if defined(__ANDROID__)
57 #define CPU_FEATURES_OS_ANDROID
60 #if (defined(_WIN64) || defined(_WIN32))
61 #define CPU_FEATURES_OS_WINDOWS
64 ////////////////////////////////////////////////////////////////////////////////
66 ////////////////////////////////////////////////////////////////////////////////
68 #if defined(__clang__)
69 #define CPU_FEATURES_COMPILER_CLANG
72 #if defined(__GNUC__) && !defined(__clang__)
73 #define CPU_FEATURES_COMPILER_GCC
77 #define CPU_FEATURES_COMPILER_MSC
80 ////////////////////////////////////////////////////////////////////////////////
82 ////////////////////////////////////////////////////////////////////////////////
84 #if defined(__cplusplus)
85 #define CPU_FEATURES_START_CPP_NAMESPACE \
86 namespace cpu_features { \
88 #define CPU_FEATURES_END_CPP_NAMESPACE \
92 #define CPU_FEATURES_START_CPP_NAMESPACE
93 #define CPU_FEATURES_END_CPP_NAMESPACE
96 ////////////////////////////////////////////////////////////////////////////////
98 ////////////////////////////////////////////////////////////////////////////////
100 // Use the following to check if a feature is known to be available at compile
101 // time. See README.md for an example.
102 #if defined(CPU_FEATURES_ARCH_X86)
103 #define CPU_FEATURES_COMPILED_X86_AES defined(__AES__)
104 #define CPU_FEATURES_COMPILED_X86_F16C defined(__F16C__)
105 #define CPU_FEATURES_COMPILED_X86_BMI defined(__BMI__)
106 #define CPU_FEATURES_COMPILED_X86_BMI2 defined(__BMI2__)
107 #define CPU_FEATURES_COMPILED_X86_SSE (defined(__SSE__) || (_M_IX86_FP >= 1))
108 #define CPU_FEATURES_COMPILED_X86_SSE2 (defined(__SSE2__) || (_M_IX86_FP >= 2))
109 #define CPU_FEATURES_COMPILED_X86_SSE3 defined(__SSE3__)
110 #define CPU_FEATURES_COMPILED_X86_SSSE3 defined(__SSSE3__)
111 #define CPU_FEATURES_COMPILED_X86_SSE4_1 defined(__SSE4_1__)
112 #define CPU_FEATURES_COMPILED_X86_SSE4_2 defined(__SSE4_2__)
113 #define CPU_FEATURES_COMPILED_X86_AVX defined(__AVX__)
114 #define CPU_FEATURES_COMPILED_x86_AVX2 defined(__AVX2__)
117 #if defined(CPU_FEATURES_ARCH_ANY_ARM)
118 #define CPU_FEATURES_COMPILED_ANY_ARM_NEON defined(__ARM_NEON__)
121 #if defined(CPU_FEATURES_ARCH_MIPS)
122 #define CPU_FEATURES_COMPILED_MIPS_MSA defined(__mips_msa)
125 #endif // CPU_FEATURES_INCLUDE_CPU_FEATURES_MACROS_H_