HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
architecture.hpp
Go to the documentation of this file.
1// Copyright Take Vos 2019-2022.
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_OS_WINDOWS 'W'
22#define HI_OS_MACOS 'A'
23#define HI_OS_MOBILE 'M'
24#define HI_OS_OTHER 'O'
25
26#if defined(_WIN32)
27#define HI_OPERATING_SYSTEM HI_OS_WINDOWS
28#elif defined(TARGET_OS_MAC) && !defined(TARGET_OS_IPHONE)
29#define HI_OPERATING_SYSTEM HI_OS_MACOS
30#elif defined(TARGET_OS_IPHONE) || defined(__ANDROID__)
31#define HI_OPERATING_SYSTEM HI_OS_MOBILE
32#else
33#define HI_OPERATING_SYSTEM HI_OS_OTHER
34#endif
35
36enum class operating_system {
37 windows = HI_OS_WINDOWS,
38 macos = HI_OS_MACOS,
39 mobile = HI_OS_MOBILE,
40 other = HI_OS_OTHER,
41
42 current = HI_OPERATING_SYSTEM
43};
44
45#define HI_CC_MSVC 'm'
46#define HI_CC_GCC 'g'
47#define HI_CC_CLANG 'c'
48
49#if defined(__clang__)
50#define HI_COMPILER HI_CC_CLANG
51#elif defined(_MSC_BUILD)
52#define HI_COMPILER HI_CC_MSVC
53#elif defined(__GNUC__)
54#define HI_COMPILER HI_CC_GCC
55#else
56#error "Could not detect the compiler."
57#endif
58
59enum class compiler {
60 msvc = HI_CC_MSVC,
61 gcc = HI_CC_GCC,
62 clang = HI_CC_CLANG,
63
64 current = HI_COMPILER
65};
66
67#define HI_CPU_X86 'i'
68#define HI_CPU_X64 'I'
69#define HI_CPU_ARM 'a'
70#define HI_CPU_ARM64 'A'
71#define HI_CPU_UNKNOWN '-'
72
73#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64) || defined(_M_X64)
74#define HI_PROCESSOR HI_CPU_X64
75#elif defined(__aarch64__) || defined(_M_ARM64)
76#define HI_PROCESSOR HI_CPU_ARM64
77#elif defined(__i386__) || defined(_M_IX86)
78#define HI_PROCESSOR HI_CPU_X86
79#elif defined(__arm__) || defined(__arm) || defeind(_ARM) || defined(_M_ARM)
80#define HI_PROCESSOR HI_CPU_ARM
81#else
82#define HI_PROCESSOR HI_CPU_UNKNOWN
83#endif
84
85enum class processor {
86 x86 = HI_CPU_X86,
87 x64 = HI_CPU_X64,
88 arm = HI_CPU_ARM,
89 arm64 = HI_CPU_ARM64,
90 unknown = HI_CPU_UNKNOWN,
91
92 current = HI_PROCESSOR
93};
94
95#if HI_PROCESSOR == HI_CPU_X86
96constexpr std::size_t hardware_destructive_interference_size = 128;
97constexpr std::size_t hardware_constructive_interference_size = 64;
98#elif HI_PROCESSOR == HI_CPU_X64
99constexpr std::size_t hardware_destructive_interference_size = 128;
100constexpr std::size_t hardware_constructive_interference_size = 64;
101#elif HI_PROCESSOR == HI_CPU_ARM
102constexpr std::size_t hardware_destructive_interference_size = 128;
103constexpr std::size_t hardware_constructive_interference_size = 64;
104#elif HI_PROCESSOR == HI_CPU_ARM64
105constexpr std::size_t hardware_destructive_interference_size = 128;
106constexpr std::size_t hardware_constructive_interference_size = 64;
107#else
108#error "missing implementation for CPU specific register and cache-line sizes"
109#endif
110
111#if defined(__AVX512BW__) && defined(__AVX512CD__) && defined(__AVX512DQ__) && defined(__AVX512F__) && defined(__AVX512VL__)
112#define HI_X86_64_V4 1
113#define HI_X86_64_V3 1
114#define HI_X86_64_V2_5 1
115#define HI_X86_64_V2 1
116#define HI_X86_64_V1 1
117#define HI_HAS_SSE 1
118#define HI_HAS_SSE2 1
119#define HI_HAS_SSE3 1
120#define HI_HAS_SSE4_1 1
121#define HI_HAS_SSE4_2 1
122#define HI_HAS_SSSE3 1
123#define HI_HAS_AVX 1
124#define HI_HAS_AVX2 1
125#define HI_HAS_BMI1 1
126#define HI_HAS_BMI2 1
127#define HI_HAS_AVX512F 1
128#define HI_HAS_AVX512BW 1
129#define HI_HAS_AVX512CD 1
130#define HI_HAS_AVX512DQ 1
131#define HI_HAS_AVX512VL 1
132
133#elif defined(__AVX2__)
134#define HI_X86_64_V3 1
135#define HI_X86_64_V2_5 1
136#define HI_X86_64_V2 1
137#define HI_X86_64_V1 1
138#define HI_HAS_SSE 1
139#define HI_HAS_SSE2 1
140#define HI_HAS_SSE3 1
141#define HI_HAS_SSE4_1 1
142#define HI_HAS_SSE4_2 1
143#define HI_HAS_SSSE3 1
144#define HI_HAS_AVX 1
145#define HI_HAS_AVX2 1
146#define HI_HAS_BMI1 1
147#define HI_HAS_BMI2 1
148
149#elif defined(__AVX__)
150#define HI_X86_64_V2_5 1
151#define HI_X86_64_V2 1
152#define HI_X86_64_V1 1
153#define HI_HAS_SSE 1
154#define HI_HAS_SSE2 1
155#define HI_HAS_SSE3 1
156#define HI_HAS_SSE4_1 1
157#define HI_HAS_SSE4_2 1
158#define HI_HAS_SSSE3 1
159#define HI_HAS_AVX 1
160
161// x86_64_v2 can not be selected in MSVC, but can be in gcc and clang.
162#elif defined(__SSE4_2__) && defined(__SSSE3__)
163#define HI_X86_64_V2 1
164#define HI_X86_64_V1 1
165#define HI_HAS_SSE 1
166#define HI_HAS_SSE2 1
167#define HI_HAS_SSE3 1
168#define HI_HAS_SSE4_1 1
169#define HI_HAS_SSE4_2 1
170#define HI_HAS_SSSE3 1
171
172#elif HI_PROCESSOR == HI_CPU_X64
173#define HI_X86_64_V1 1
174#define HI_HAS_SSE 1
175#define HI_HAS_SSE2 1
176
177#elif HI_PROCESSOR == HI_CPU_X86
178#elif HI_PROCESSOR == HI_CPU_ARM64
179#elif HI_PROCESSOR == HI_CPU_ARM
180#endif
181
182//#if defined(HI_X86_64_V1)
183//constexpr bool x86_64_v1 = true;
184//#else
185//constexpr bool x86_64_v1 = false;
186//#endif
187//
188//#if defined(HI_X86_64_V2)
189//constexpr bool x86_64_v2 = true;
190//#else
191//constexpr bool x86_64_v2 = false;
192//#endif
193//
194//#if defined(HI_X86_64_V2_5)
195//constexpr bool x86_64_v2_5 = true;
196//#else
197//constexpr bool x86_64_v2_5 = false;
198//#endif
199//
200//#if defined(HI_X86_64_V3)
201//constexpr bool x86_64_v3 = true;
202//#else
203//constexpr bool x86_64_v3 = false;
204//#endif
205//
206//#if defined(HI_X86_64_V4)
207//constexpr bool x86_64_v4 = true;
208//#else
209//constexpr bool x86_64_v4 = false;
210//#endif
211
212#if HI_PROCESSOR == HI_CPU_X64
220#elif HI_PROCESSOR == HI_CPU_ARM
224constexpr std::size_t hardware_destructive_interference_size = 64;
225
229constexpr std::size_t hardware_constructive_interference_size = 64;
230
231#elif HI_PROCESSOR == HI_CPU_UNKNOWN
232constexpr std::size_t hardware_destructive_interference_size = 128;
233constexpr std::size_t hardware_constructive_interference_size = 64;
234#else
235#error "Missing implementation of hardware_destructive_interference_size and hardware_constructive_interference_size"
236#endif
237
238#if HI_OPERATING_SYSTEM == HI_OS_WINDOWS
239using os_handle = void *;
240using file_handle = os_handle;
241
242#elif HI_OPERATING_SYSTEM == HI_OS_MACOS
243using os_handle = int;
244using file_handle = int;
245
246#elif HI_OPERATING_SYSTEM == HI_OS_LINUX
247using os_handle = int;
248using file_handle = int;
249
250#else
251#error "file_handle Not implemented."
252#endif
253
254} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:15
void * os_handle
Minimum offset between two objects to avoid false sharing.
Definition architecture.hpp:239