Bug 1861709 replace AudioCallbackDriver::ThreadRunning() assertions that mean to...
[gecko.git] / third_party / highway / hwy / detect_compiler_arch.h
blob1e4ff5d9eb4bd2e8e83ad2d48ce7c14abc61c92d
1 // Copyright 2020 Google LLC
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
16 #ifndef HIGHWAY_HWY_DETECT_COMPILER_ARCH_H_
17 #define HIGHWAY_HWY_DETECT_COMPILER_ARCH_H_
19 // Detects compiler and arch from predefined macros. Zero dependencies for
20 // inclusion by foreach_target.h.
22 // Add to #if conditions to prevent IDE from graying out code.
23 #if (defined __CDT_PARSER__) || (defined __INTELLISENSE__) || \
24 (defined Q_CREATOR_RUN) || (defined __CLANGD__) || \
25 (defined GROK_ELLIPSIS_BUILD)
26 #define HWY_IDE 1
27 #else
28 #define HWY_IDE 0
29 #endif
31 //------------------------------------------------------------------------------
32 // Compiler
34 // Actual MSVC, not clang-cl, which defines _MSC_VER but doesn't behave like
35 // MSVC in other aspects (e.g. HWY_DIAGNOSTICS).
36 #if defined(_MSC_VER) && !defined(__clang__)
37 #define HWY_COMPILER_MSVC _MSC_VER
38 #else
39 #define HWY_COMPILER_MSVC 0
40 #endif
42 #if defined(_MSC_VER) && defined(__clang__)
43 #define HWY_COMPILER_CLANGCL _MSC_VER
44 #else
45 #define HWY_COMPILER_CLANGCL 0
46 #endif
48 #ifdef __INTEL_COMPILER
49 #define HWY_COMPILER_ICC __INTEL_COMPILER
50 #else
51 #define HWY_COMPILER_ICC 0
52 #endif
54 #ifdef __INTEL_LLVM_COMPILER
55 #define HWY_COMPILER_ICX __INTEL_LLVM_COMPILER
56 #else
57 #define HWY_COMPILER_ICX 0
58 #endif
60 // HWY_COMPILER_GCC is a generic macro for all compilers implementing the GNU
61 // compiler extensions (eg. Clang, Intel...)
62 #ifdef __GNUC__
63 #define HWY_COMPILER_GCC (__GNUC__ * 100 + __GNUC_MINOR__)
64 #else
65 #define HWY_COMPILER_GCC 0
66 #endif
68 // Clang or clang-cl, not GCC.
69 #ifdef __clang__
70 // In case of Apple LLVM (whose version number is unrelated to that of LLVM) or
71 // an invalid version number, deduce it from the presence of warnings.
72 // Originally based on
73 // https://github.com/simd-everywhere/simde/blob/47d6e603de9d04ee05cdfbc57cf282a02be1bf2a/simde/simde-detect-clang.h#L59.
74 // Please send updates below to them as well, thanks!
75 #if defined(__apple_build_version__) || __clang_major__ >= 999
76 #if __has_attribute(nouwtable) // no new warnings in 16.0
77 #define HWY_COMPILER_CLANG 1600
78 #elif __has_warning("-Warray-parameter")
79 #define HWY_COMPILER_CLANG 1500
80 #elif __has_warning("-Wbitwise-instead-of-logical")
81 #define HWY_COMPILER_CLANG 1400
82 #elif __has_warning("-Wreserved-identifier")
83 #define HWY_COMPILER_CLANG 1300
84 #elif __has_warning("-Wformat-insufficient-args")
85 #define HWY_COMPILER_CLANG 1200
86 #elif __has_warning("-Wimplicit-const-int-float-conversion")
87 #define HWY_COMPILER_CLANG 1100
88 #elif __has_warning("-Wmisleading-indentation")
89 #define HWY_COMPILER_CLANG 1000
90 #elif defined(__FILE_NAME__)
91 #define HWY_COMPILER_CLANG 900
92 #elif __has_warning("-Wextra-semi-stmt") || \
93 __has_builtin(__builtin_rotateleft32)
94 #define HWY_COMPILER_CLANG 800
95 // For reasons unknown, XCode 10.3 (Apple LLVM version 10.0.1) is apparently
96 // based on Clang 7, but does not support the warning we test.
97 // See https://en.wikipedia.org/wiki/Xcode#Toolchain_versions and
98 // https://trac.macports.org/wiki/XcodeVersionInfo.
99 #elif __has_warning("-Wc++98-compat-extra-semi") || \
100 (defined(__apple_build_version__) && __apple_build_version__ >= 10010000)
101 #define HWY_COMPILER_CLANG 700
102 #else // Anything older than 7.0 is not recommended for Highway.
103 #define HWY_COMPILER_CLANG 600
104 #endif // __has_warning chain
105 #define HWY_COMPILER3_CLANG (HWY_COMPILER_CLANG * 100)
106 #else // use normal version
107 #define HWY_COMPILER_CLANG (__clang_major__ * 100 + __clang_minor__)
108 #define HWY_COMPILER3_CLANG \
109 (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
110 #endif
111 #else // Not clang
112 #define HWY_COMPILER_CLANG 0
113 #define HWY_COMPILER3_CLANG 0
114 #endif
116 #if HWY_COMPILER_GCC && !HWY_COMPILER_CLANG
117 #define HWY_COMPILER_GCC_ACTUAL HWY_COMPILER_GCC
118 #else
119 #define HWY_COMPILER_GCC_ACTUAL 0
120 #endif
122 // More than one may be nonzero, but we want at least one.
123 #if 0 == (HWY_COMPILER_MSVC + HWY_COMPILER_CLANGCL + HWY_COMPILER_ICC + \
124 HWY_COMPILER_GCC + HWY_COMPILER_CLANG)
125 #error "Unsupported compiler"
126 #endif
128 // We should only detect one of these (only clang/clangcl overlap)
129 #if 1 < \
130 (!!HWY_COMPILER_MSVC + !!HWY_COMPILER_ICC + !!HWY_COMPILER_GCC_ACTUAL + \
131 !!(HWY_COMPILER_CLANGCL | HWY_COMPILER_CLANG))
132 #error "Detected multiple compilers"
133 #endif
135 #ifdef __has_builtin
136 #define HWY_HAS_BUILTIN(name) __has_builtin(name)
137 #else
138 #define HWY_HAS_BUILTIN(name) 0
139 #endif
141 #ifdef __has_attribute
142 #define HWY_HAS_ATTRIBUTE(name) __has_attribute(name)
143 #else
144 #define HWY_HAS_ATTRIBUTE(name) 0
145 #endif
147 #ifdef __has_cpp_attribute
148 #define HWY_HAS_CPP_ATTRIBUTE(name) __has_cpp_attribute(name)
149 #else
150 #define HWY_HAS_CPP_ATTRIBUTE(name) 0
151 #endif
153 #ifdef __has_feature
154 #define HWY_HAS_FEATURE(name) __has_feature(name)
155 #else
156 #define HWY_HAS_FEATURE(name) 0
157 #endif
159 //------------------------------------------------------------------------------
160 // Architecture
162 #if defined(__i386__) || defined(_M_IX86)
163 #define HWY_ARCH_X86_32 1
164 #else
165 #define HWY_ARCH_X86_32 0
166 #endif
168 #if defined(__x86_64__) || defined(_M_X64)
169 #define HWY_ARCH_X86_64 1
170 #else
171 #define HWY_ARCH_X86_64 0
172 #endif
174 #if HWY_ARCH_X86_32 && HWY_ARCH_X86_64
175 #error "Cannot have both x86-32 and x86-64"
176 #endif
178 #if HWY_ARCH_X86_32 || HWY_ARCH_X86_64
179 #define HWY_ARCH_X86 1
180 #else
181 #define HWY_ARCH_X86 0
182 #endif
184 #if defined(__powerpc64__) || defined(_M_PPC) || defined(__powerpc__)
185 #define HWY_ARCH_PPC 1
186 #else
187 #define HWY_ARCH_PPC 0
188 #endif
190 // aarch32 is currently not supported; please raise an issue if you want it.
191 #if defined(__ARM_ARCH_ISA_A64) || defined(__aarch64__) || defined(_M_ARM64)
192 #define HWY_ARCH_ARM_A64 1
193 #else
194 #define HWY_ARCH_ARM_A64 0
195 #endif
197 #if (defined(__ARM_ARCH) && __ARM_ARCH == 7) || (defined(_M_ARM) && _M_ARM == 7)
198 #define HWY_ARCH_ARM_V7 1
199 #else
200 #define HWY_ARCH_ARM_V7 0
201 #endif
203 #if HWY_ARCH_ARM_A64 && HWY_ARCH_ARM_V7
204 #error "Cannot have both A64 and V7"
205 #endif
207 // Any *supported* version of Arm, i.e. 7 or later
208 #if HWY_ARCH_ARM_A64 || HWY_ARCH_ARM_V7
209 #define HWY_ARCH_ARM 1
210 #else
211 #define HWY_ARCH_ARM 0
212 #endif
214 // Older than Armv7 (e.g. armel aka Armv5) => we do not support SIMD.
215 #if (defined(__arm__) || defined(_M_ARM)) && !HWY_ARCH_ARM
216 #define HWY_ARCH_ARM_OLD 1
217 #else
218 #define HWY_ARCH_ARM_OLD 0
219 #endif
221 #if defined(__EMSCRIPTEN__) || defined(__wasm__) || defined(__WASM__)
222 #define HWY_ARCH_WASM 1
223 #else
224 #define HWY_ARCH_WASM 0
225 #endif
227 #ifdef __riscv
228 #define HWY_ARCH_RVV 1
229 #else
230 #define HWY_ARCH_RVV 0
231 #endif
233 // It is an error to detect multiple architectures at the same time, but OK to
234 // detect none of the above.
235 #if (HWY_ARCH_X86 + HWY_ARCH_PPC + HWY_ARCH_ARM + HWY_ARCH_ARM_OLD + \
236 HWY_ARCH_WASM + HWY_ARCH_RVV) > 1
237 #error "Must not detect more than one architecture"
238 #endif
240 #if defined(_WIN32) || defined(_WIN64)
241 #define HWY_OS_WIN 1
242 #else
243 #define HWY_OS_WIN 0
244 #endif
246 #if defined(linux) || defined(__linux__)
247 #define HWY_OS_LINUX 1
248 #else
249 #define HWY_OS_LINUX 0
250 #endif
252 //------------------------------------------------------------------------------
253 // Endianness
255 #if HWY_COMPILER_MSVC
256 #if HWY_ARCH_PPC && defined(_XBOX_VER) && _XBOX_VER >= 200
257 // XBox 360 is big-endian
258 #define HWY_IS_LITTLE_ENDIAN 0
259 #define HWY_IS_BIG_ENDIAN 1
260 #else
261 // All other targets supported by MSVC are little-endian
262 #define HWY_IS_LITTLE_ENDIAN 1
263 #define HWY_IS_BIG_ENDIAN 0
264 #endif // HWY_ARCH_PPC && defined(_XBOX_VER) && _XBOX_VER >= 200
265 #elif defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
266 __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
267 #define HWY_IS_LITTLE_ENDIAN 1
268 #define HWY_IS_BIG_ENDIAN 0
269 #elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
270 __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
271 #define HWY_IS_LITTLE_ENDIAN 0
272 #define HWY_IS_BIG_ENDIAN 1
273 #else
274 #error "Unable to detect endianness or unsupported byte order"
275 #endif
277 #if (HWY_IS_LITTLE_ENDIAN + HWY_IS_BIG_ENDIAN) != 1
278 #error "Must only detect one byte order"
279 #endif
281 #endif // HIGHWAY_HWY_DETECT_COMPILER_ARCH_H_