forked from TerensTare/detector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetector.hpp
More file actions
288 lines (229 loc) · 7.15 KB
/
detector.hpp
File metadata and controls
288 lines (229 loc) · 7.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#ifndef DETECTOR_HPP
#define DETECTOR_HPP
#ifdef __APPLE__
#include <TargetConditionals.h> // needed for detecting if on mac or on ios
#endif
#if (defined(_M_AMD64) || defined(_M_X64) || defined(__amd64)) && !defined(__x86_64__)
#define DETECTED_X86_64
#endif
// MSVC doesn't correctly report __cplusplus unless you pass /Zc:__cplusplus
#ifdef _MSVC_LANG
#define DETECTED_CXX _MSVC_LANG
#else
#define DETECTED_CXX __cplusplus
#endif
#if DETECTED_CXX >= 201703L
#define DETECT_INLINE inline
#else
#define DETECT_INLINE
#endif
namespace detect
{
//////////////////////
// os-related stuff //
//////////////////////
struct windows_t;
struct linux_t;
struct macos_t;
struct ios_t;
struct android_t;
struct unix_t;
template <typename O>
static constexpr bool is_os_v = false;
#if defined(_WIN32) || defined(WIN32) || defined(_WIN64)
template <>
DETECT_INLINE constexpr bool is_os_v<windows_t> = true;
#endif
#if defined(__linux__) && !defined(__android__)
template <>
DETECT_INLINE constexpr bool is_os_v<linux_t> = true;
#endif
#ifdef TARGET_OS_MAC
template <>
DETECT_INLINE constexpr bool is_os_v<macos_t> = true;
#endif
#if defined(TARGET_IPHONE_SIMULATOR) || defined(TARGET_OS_IPHONE)
template <>
DETECT_INLINE constexpr bool is_os_v<ios_t> = true;
#endif
#ifdef __android__
template <>
DETECT_INLINE constexpr bool is_os_v<android_t> = true;
#endif
#if !defined(__linux__) && defined(__unix__)
template <>
DETECT_INLINE constexpr bool is_os_v<linux_t> = true;
#endif
static constexpr bool is_windows_v = is_os_v<windows_t>;
static constexpr bool is_linux_v = is_os_v<linux_t>;
static constexpr bool is_macos_v = is_os_v<macos_t>;
static constexpr bool is_ios_v = is_os_v<ios_t>;
static constexpr bool is_android_v = is_os_v<android_t>;
static constexpr bool is_unix_v = is_os_v<unix_t>;
template <typename O>
struct is_os
{
static constexpr bool value = is_os_v<O>;
};
////////////////////////////
// compiler-related stuff //
////////////////////////////
struct gcc_t;
struct clang_t;
struct msvc_t;
struct mingw_t;
template <typename C>
static constexpr bool is_compiler_v = false;
#if defined(__GNUC__) && !defined(__clang__)
template <>
DETECT_INLINE constexpr bool is_compiler_v<gcc_t> = true;
#endif
#ifdef __clang__
template <>
DETECT_INLINE constexpr bool is_compiler_v<clang_t> = true;
#endif
#if defined(_MSC_VER) && !defined(__clang__)
template <>
DETECT_INLINE constexpr bool is_compiler_v<msvc_t> = true;
#endif
#if defined(__MINGW32__) || !defined(__MINGW64__)
template <>
DETECT_INLINE constexpr bool is_compiler_v<mingw_t> = true;
#endif
static constexpr bool is_gcc_v = is_compiler_v<gcc_t>;
static constexpr bool is_clang_v = is_compiler_v<clang_t>;
static constexpr bool is_msvc_v = is_compiler_v<msvc_t>;
static constexpr bool is_mingw_v = is_compiler_v<mingw_t>;
template <typename C>
struct is_compiler
{
static constexpr bool value = is_compiler_v<C>;
};
////////////////////////////////
// C++ standard-related stuff //
////////////////////////////////
struct cxx_11;
struct cxx_14;
struct cxx_17;
struct cxx_20;
struct cxx_23;
template <typename T>
static constexpr bool is_std_v = false;
template <>
DETECT_INLINE constexpr bool is_std_v<cxx_11> = DETECTED_CXX == 201103L;
template <>
DETECT_INLINE constexpr bool is_std_v<cxx_14> = DETECTED_CXX == 201402L;
template <>
DETECT_INLINE constexpr bool is_std_v<cxx_17> = DETECTED_CXX == 201703L;
template <>
DETECT_INLINE constexpr bool is_std_v<cxx_20> = DETECTED_CXX == 202002L;
template <>
DETECT_INLINE constexpr bool is_std_v<cxx_23> = DETECTED_CXX == 202302L;
static constexpr bool is_cxx_11 = is_std_v<cxx_11>;
static constexpr bool is_cxx_14 = is_std_v<cxx_14>;
static constexpr bool is_cxx_17 = is_std_v<cxx_17>;
static constexpr bool is_cxx_20 = is_std_v<cxx_20>;
static constexpr bool is_cxx_23 = is_std_v<cxx_23>;
template <typename S>
struct is_std
{
static constexpr bool value = is_std_v<S>;
};
/////////////////////////////////
// debug/release related stuff //
/////////////////////////////////
struct debug_t;
struct release_t;
template <typename B>
static constexpr bool is_build_v = false;
#if defined(_DEBUG) || defined(DEBUG)
template <>
DETECT_INLINE constexpr bool is_build_v<debug_t> = true;
#endif
#if defined(NDEBUG) || !(defined(DEBUG) && defined(_DEBUG))
template <>
DETECT_INLINE constexpr bool is_build_v<release_t> = true;
#endif
static constexpr bool is_debug_v = is_build_v<debug_t>;
static constexpr bool is_release_v = is_build_v<release_t>;
template <typename B>
struct is_build
{
static constexpr bool value = is_build_v<B>;
};
///////////////////////
// simd instructions //
///////////////////////
struct x86sse_t;
struct x86sse2_t;
struct sse_t;
struct sse2_t;
struct sse3_t;
struct ssse3_t;
struct sse4_1_t;
struct sse4_2_t;
struct avx_t;
struct avx2_t;
template <typename S>
static constexpr bool is_simd_v = false;
#if defined(_M_IX86_FP) && (_M_IX86_FP == 1)
template <>
DETECT_INLINE constexpr bool is_simd_v<x86sse_t> = true;
#endif
#if defined(_M_IX86_FP) && (_M_IX86_FP == 2)
template <>
DETECT_INLINE constexpr bool is_simd_v<x86sse2_t> = true;
#endif
#ifdef __SSE__
template <>
DETECT_INLINE constexpr bool is_simd_v<sse_t> = true;
#endif
#if defined(__SSE2__) || defined(__x86_x64__) || defined(DETECTED_X86_64)
template <>
DETECT_INLINE constexpr bool is_simd_v<sse2_t> = true;
#endif
#ifdef __SSE3__
template <>
DETECT_INLINE constexpr bool is_simd_v<sse3_t> = true;
#endif
#ifdef __SSSE3__
template <>
DETECT_INLINE constexpr bool is_simd_v<ssse3_t> = true;
#endif
#ifdef __SSE4_1__
template <>
DETECT_INLINE constexpr bool is_simd_v<sse4_1_t> = true;
#endif
#ifdef __SSE4_2__
template <>
DETECT_INLINE constexpr bool is_simd_v<sse4_2_t> = true;
#endif
#ifdef __AVX__
template <>
DETECT_INLINE constexpr bool is_simd_v<avx_t> = true;
#endif
#ifdef __AVX2__
template <>
DETECT_INLINE constexpr bool is_simd_v<avx2_t> = true;
#endif
static constexpr bool is_x86_sse_v = is_simd_v<x86sse_t>;
static constexpr bool is_x86_sse2_v = is_simd_v<x86sse2_t>;
static constexpr bool is_sse_v = is_simd_v<sse_t>;
static constexpr bool is_sse2_v = is_simd_v<sse2_t>;
static constexpr bool is_sse3_v = is_simd_v<sse3_t>;
static constexpr bool is_ssse3_v = is_simd_v<ssse3_t>;
static constexpr bool is_sse4_1_v = is_simd_v<sse4_1_t>;
static constexpr bool is_sse4_2_v = is_simd_v<sse4_2_t>;
static constexpr bool is_avx_v = is_simd_v<avx_t>;
static constexpr bool is_avx2_v = is_simd_v<avx2_t>;
template <typename S>
struct is_simd
{
static constexpr bool value = is_simd_v<S>;
};
} // namespace detect
#ifdef DETECTED_X86_64
#undef DETECTED_X86_64
#endif
#undef DETECTED_CXX
#endif // !DETECTOR_HPP