HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
architecture.hpp
Go to the documentation of this file.
1// Copyright Take Vos 2019-2020.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
10#pragma once
11
12#include <exception>
13#include <cstddef>
14#include <type_traits>
15#if defined(__APPLE__)
16#include <TargetConditionals.h>
17#endif
18
19namespace hi::inline v1 {
20
21#define HI_BT_DEBUG 'D'
22#define HI_BT_RELEASE 'R'
23
24#if defined(NDEBUG)
25#define HI_BUILD_TYPE HI_BT_RELEASE
26#else
27#define HI_BUILD_TYPE HI_BT_DEBUG
28#endif
29
30enum class build_type {
31 debug = HI_BT_DEBUG,
32 release = HI_BT_RELEASE,
33
34 current = HI_BUILD_TYPE
35};
36
37#define HI_OS_WINDOWS 'W'
38#define HI_OS_MACOS 'A'
39#define HI_OS_MOBILE 'M'
40#define HI_OS_OTHER 'O'
41
42#if defined(_WIN32)
43#define HI_OPERATING_SYSTEM HI_OS_WINDOWS
44#elif defined(TARGET_OS_MAC) && !defined(TARGET_OS_IPHONE)
45#define HI_OPERATING_SYSTEM HI_OS_MACOS
46#elif defined(TARGET_OS_IPHONE) || defined(__ANDROID__)
47#define HI_OPERATING_SYSTEM HI_OS_MOBILE
48#else
49#define HI_OPERATING_SYSTEM HI_OS_OTHER
50#endif
51
52enum class operating_system {
53 windows = HI_OS_WINDOWS,
54 macos = HI_OS_MACOS,
55 mobile = HI_OS_MOBILE,
56 other = HI_OS_OTHER,
57
58 current = HI_OPERATING_SYSTEM
59};
60
61#define HI_CC_MSVC 'm'
62#define HI_CC_GCC 'g'
63#define HI_CC_CLANG 'c'
64
65#if defined(__clang__)
66#define HI_COMPILER HI_CC_CLANG
67#elif defined(_MSC_BUILD)
68#define HI_COMPILER HI_CC_MSVC
69#elif defined(__GNUC__)
70#define HI_COMPILER HI_CC_GCC
71#else
72#error "Could not detect the compiler."
73#endif
74
75enum class compiler {
76 msvc = HI_CC_MSVC,
77 gcc = HI_CC_GCC,
78 clang = HI_CC_CLANG,
79
80 current = HI_COMPILER
81};
82
83#define HI_CPU_X64 'i'
84#define HI_CPU_ARM 'a'
85#define HI_CPU_UNKNOWN 'u'
86
87#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64)
88#define HI_PROCESSOR HI_CPU_X64
89#elif defined(__arm__) || defined(_M_ARM)
90#define HI_PROCESSOR HI_CPU_ARM
91#else
92#define HI_PROCESSOR HI_CPU_UNKNOWN
93#endif
94
95enum class processor {
96 x64 = HI_CPU_X64,
97 arm = HI_CPU_ARM,
98 unknown = HI_CPU_UNKNOWN,
99
100 current = HI_PROCESSOR
101};
102
103#if HI_PROCESSOR == HI_CPU_X64
104#if defined(__AVX512BW__) && defined(__AVX512CD__) && defined(__AVX512DQ__) && defined(__AVX512F__) && defined(__AVX512VL__)
105#define HI_X86_64_V4 1
106#define HI_X86_64_V3 1
107#define HI_X86_64_V2_5 1
108#define HI_X86_64_V2 1
109#define HI_X86_64_V1 1
110#define HI_HAS_SSE
111#define HI_HAS_SSE2
112#define HI_HAS_SSE3
113#define HI_HAS_SSE4_1
114#define HI_HAS_SSE4_2
115#define HI_HAS_SSSE3
116#define HI_HAS_AVX
117#define HI_HAS_AVX2
118#define HI_HAS_BMI1
119#define HI_HAS_BMI2
120#define HI_HAS_AVX512F
121#define HI_HAS_AVX512BW
122#define HI_HAS_AVX512CD
123#define HI_HAS_AVX512DQ
124#define HI_HAS_AVX512VL
125
126#elif defined(__AVX2__)
127#define HI_X86_64_V3 1
128#define HI_X86_64_V2_5 1
129#define HI_X86_64_V2 1
130#define HI_X86_64_V1 1
131#define HI_HAS_SSE
132#define HI_HAS_SSE2
133#define HI_HAS_SSE3
134#define HI_HAS_SSE4_1
135#define HI_HAS_SSE4_2
136#define HI_HAS_SSSE3
137#define HI_HAS_AVX
138#define HI_HAS_AVX2
139#define HI_HAS_BMI1
140#define HI_HAS_BMI2
141
142#elif defined(__AVX__)
143#define HI_X86_64_V2_5 1
144#define HI_X86_64_V2 1
145#define HI_X86_64_V1 1
146#define HI_HAS_SSE
147#define HI_HAS_SSE2
148#define HI_HAS_SSE3
149#define HI_HAS_SSE4_1
150#define HI_HAS_SSE4_2
151#define HI_HAS_SSSE3
152#define HI_HAS_AVX
153
154// x86_64_v2 can not be selected in MSVC, but can be in gcc and clang.
155#elif defined(__SSE4_2__) && defined(__SSSE3__)
156#define HI_X86_64_V2 1
157#define HI_X86_64_V1 1
158#define HI_HAS_SSE
159#define HI_HAS_SSE2
160#define HI_HAS_SSE3
161#define HI_HAS_SSE4_1
162#define HI_HAS_SSE4_2
163#define HI_HAS_SSSE3
164
165#else
166#define HI_X86_64_V1 1
167#define HI_HAS_SSE
168#define HI_HAS_SSE2
169#endif
170#endif
171
172#if defined(HI_X86_64_V1)
173constexpr bool x86_64_v1 = true;
174#else
175constexpr bool x86_64_v1 = false;
176#endif
177
178#if defined(HI_X86_64_V2)
179constexpr bool x86_64_v2 = true;
180#else
181constexpr bool x86_64_v2 = false;
182#endif
183
184#if defined(HI_X86_64_V2_5)
185constexpr bool x86_64_v2_5 = true;
186#else
187constexpr bool x86_64_v2_5 = false;
188#endif
189
190#if defined(HI_X86_64_V3)
191constexpr bool x86_64_v3 = true;
192#else
193constexpr bool x86_64_v3 = false;
194#endif
195
196#if defined(HI_X86_64_V4)
197constexpr bool x86_64_v4 = true;
198#else
199constexpr bool x86_64_v4 = false;
200#endif
201
202#define hi_stringify_(x) #x
203#define hi_stringify(x) hi_stringify_(x)
204
205#define hi_cat_(a, b) a ## b
206#define hi_cat(a, b) hi_cat_(a, b)
207
208#if HI_COMPILER == HI_CC_MSVC
209
214#define hi_unreachable() __assume(0)
215
222#define hi_assume(condition) __assume(condition)
223
226#define hi_force_inline __forceinline
227#define hi_no_inline __declspec(noinline)
228#define hi_restrict __restrict
229#define hi_warning_push() _Pragma("warning( push )")
230#define hi_warning_pop() _Pragma("warning( pop )")
231#define hi_msvc_pragma(a) _Pragma(a)
232#define hi_msvc_suppress(code) _Pragma(hi_stringify(warning(disable:code)))
233#define hi_clang_suppress(a)
234
237#define hi_export __declspec(dllexport)
238
239#elif HI_COMPILER == HI_CC_CLANG
240#define hi_unreachable() __builtin_unreachable()
241#define hi_assume(condition) __builtin_assume(static_cast<bool>(condition))
242#define hi_force_inline inline __attribute__((always_inline))
243#define hi_no_inline __attribute__((noinline))
244#define hi_restrict __restrict__
245#define hi_warning_push() _Pragma("warning(push)")
246#define hi_warning_pop() _Pragma("warning(push)")
247#define hi_msvc_pragma(a)
248#define hi_clang_suppress(a) _Pragma(hi_stringify(clang diagnostic ignored a))
249#define hi_export
250
251#elif HI_COMPILER == HI_CC_GCC
252#define hi_unreachable() __builtin_unreachable()
253#define hi_assume(condition) \
254 do { \
255 if (!(condition)) \
256 hi_unreachable(); \
257 } while (false)
258#define hi_force_inline inline __attribute__((always_inline))
259#define hi_no_inline __attribute__((noinline))
260#define hi_restrict __restrict__
261#define hi_warning_push() _Pragma("warning(push)")
262#define hi_warning_pop() _Pragma("warning(pop)")
263#define hi_msvc_pragma(a)
264#define hi_clang_suppress(a)
265#define msvc_pragma(a)
266
267#else
268#define hi_unreachable() std::terminate()
269#define hi_assume(condition) static_assert(sizeof(condition) == 1)
270#define hi_force_inline inline
271#define hi_no_inline
272#define hi_restrict
273#define hi_warning_push()
274#define hi_warning_pop()
275#define hi_msvc_pragma(a)
276#define hi_clang_suppress(a)
277#define msvc_pragma(a)
278
279#endif
280
281#if HI_PROCESSOR == HI_CPU_X64
286
291#elif HI_PROCESSOR == HI_CPU_ARM
296
301
302#elif HI_PROCESSOR == HI_CPU_UNKNOWN
305#else
306#error "Missing implementation of hardware_destructive_interference_size and hardware_constructive_interference_size"
307#endif
308
309#if HI_OPERATING_SYSTEM == HI_OS_WINDOWS
310using os_handle = void *;
311using file_handle = os_handle;
312
313#elif HI_OPERATING_SYSTEM == HI_OS_MACOS
314using os_handle = int;
315using file_handle = int;
316
317#elif HI_OPERATING_SYSTEM == HI_OS_LINUX
318using os_handle = int;
319using file_handle = int;
320
321#else
322#error "file_handle Not implemented."
323#endif
324
325} // namespace hi::inline v1
constexpr std::size_t hardware_constructive_interference_size
Maximum size of contiguous memory to promote true sharing.
Definition architecture.hpp:290
constexpr std::size_t hardware_destructive_interference_size
Minimum offset between two objects to avoid false sharing.
Definition architecture.hpp:285