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_X86 'i'
84#define HI_CPU_X64 'I'
85#define HI_CPU_ARM 'a'
86#define HI_CPU_ARM64 'A'
87#define HI_CPU_UNKNOWN '-'
88
89#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64) || defined(_M_X64)
90#define HI_PROCESSOR HI_CPU_X64
91#elif defined(__aarch64__) || defined(_M_ARM64)
92#define HI_PROCESSOR HI_CPU_ARM64
93#elif defined(__i386__) || defined(_M_IX86)
94#define HI_PROCESSOR HI_CPU_X86
95#elif defined(__arm__) || defined(__arm) || defeind(_ARM) || defined(_M_ARM)
96#define HI_PROCESSOR HI_CPU_ARM
97#else
98#define HI_PROCESSOR HI_CPU_UNKNOWN
99#endif
100
101enum class processor {
102 x86 = HI_CPU_X86,
103 x64 = HI_CPU_X64,
104 arm = HI_CPU_ARM,
105 arm64 = HI_CPU_ARM64,
106 unknown = HI_CPU_UNKNOWN,
107
108 current = HI_PROCESSOR
109};
110
111#if HI_PROCESSOR == HI_CPU_X86
112using intreg_t = int32_t;
113using uintreg_t = uint32_t;
114constexpr std::size_t hardware_destructive_interference_size = 128;
115constexpr std::size_t hardware_constructive_interference_size = 64;
116#elif HI_PROCESSOR == HI_CPU_X64
117using intreg_t = int64_t;
118using uintreg_t = uint64_t;
119constexpr std::size_t hardware_destructive_interference_size = 128;
120constexpr std::size_t hardware_constructive_interference_size = 64;
121#elif HI_PROCESSOR == HI_CPU_ARM
122using intreg_t = int32_t;
123using uintreg_t = uint32_t;
124constexpr std::size_t hardware_destructive_interference_size = 128;
125constexpr std::size_t hardware_constructive_interference_size = 64;
126#elif HI_PROCESSOR == HI_CPU_ARM64
127using intreg_t = int64_t;
128using uintreg_t = uint64_t;
129constexpr std::size_t hardware_destructive_interference_size = 128;
130constexpr std::size_t hardware_constructive_interference_size = 64;
131#else
132#error "missing implementation for CPU specific register and cache-line sizes"
133#endif
134
135#if defined(__AVX512BW__) && defined(__AVX512CD__) && defined(__AVX512DQ__) && defined(__AVX512F__) && defined(__AVX512VL__)
136#define HI_X86_64_V4 1
137#define HI_X86_64_V3 1
138#define HI_X86_64_V2_5 1
139#define HI_X86_64_V2 1
140#define HI_X86_64_V1 1
141#define HI_HAS_SSE 1
142#define HI_HAS_SSE2 1
143#define HI_HAS_SSE3 1
144#define HI_HAS_SSE4_1 1
145#define HI_HAS_SSE4_2 1
146#define HI_HAS_SSSE3 1
147#define HI_HAS_AVX 1
148#define HI_HAS_AVX2 1
149#define HI_HAS_BMI1 1
150#define HI_HAS_BMI2 1
151#define HI_HAS_AVX512F 1
152#define HI_HAS_AVX512BW 1
153#define HI_HAS_AVX512CD 1
154#define HI_HAS_AVX512DQ 1
155#define HI_HAS_AVX512VL 1
156
157#elif defined(__AVX2__)
158#define HI_X86_64_V3 1
159#define HI_X86_64_V2_5 1
160#define HI_X86_64_V2 1
161#define HI_X86_64_V1 1
162#define HI_HAS_SSE 1
163#define HI_HAS_SSE2 1
164#define HI_HAS_SSE3 1
165#define HI_HAS_SSE4_1 1
166#define HI_HAS_SSE4_2 1
167#define HI_HAS_SSSE3 1
168#define HI_HAS_AVX 1
169#define HI_HAS_AVX2 1
170#define HI_HAS_BMI1 1
171#define HI_HAS_BMI2 1
172
173#elif defined(__AVX__)
174#define HI_X86_64_V2_5 1
175#define HI_X86_64_V2 1
176#define HI_X86_64_V1 1
177#define HI_HAS_SSE 1
178#define HI_HAS_SSE2 1
179#define HI_HAS_SSE3 1
180#define HI_HAS_SSE4_1 1
181#define HI_HAS_SSE4_2 1
182#define HI_HAS_SSSE3 1
183#define HI_HAS_AVX 1
184
185// x86_64_v2 can not be selected in MSVC, but can be in gcc and clang.
186#elif defined(__SSE4_2__) && defined(__SSSE3__)
187#define HI_X86_64_V2 1
188#define HI_X86_64_V1 1
189#define HI_HAS_SSE 1
190#define HI_HAS_SSE2 1
191#define HI_HAS_SSE3 1
192#define HI_HAS_SSE4_1 1
193#define HI_HAS_SSE4_2 1
194#define HI_HAS_SSSE3 1
195
196#elif HI_PROCESSOR == HI_CPU_X64
197#define HI_X86_64_V1 1
198#define HI_HAS_SSE 1
199#define HI_HAS_SSE2 1
200
201#elif HI_PROCESSOR == HI_CPU_X86
202#elif HI_PROCESSOR == HI_CPU_ARM64
203#elif HI_PROCESSOR == HI_CPU_ARM
204#endif
205
206//#if defined(HI_X86_64_V1)
207//constexpr bool x86_64_v1 = true;
208//#else
209//constexpr bool x86_64_v1 = false;
210//#endif
211//
212//#if defined(HI_X86_64_V2)
213//constexpr bool x86_64_v2 = true;
214//#else
215//constexpr bool x86_64_v2 = false;
216//#endif
217//
218//#if defined(HI_X86_64_V2_5)
219//constexpr bool x86_64_v2_5 = true;
220//#else
221//constexpr bool x86_64_v2_5 = false;
222//#endif
223//
224//#if defined(HI_X86_64_V3)
225//constexpr bool x86_64_v3 = true;
226//#else
227//constexpr bool x86_64_v3 = false;
228//#endif
229//
230//#if defined(HI_X86_64_V4)
231//constexpr bool x86_64_v4 = true;
232//#else
233//constexpr bool x86_64_v4 = false;
234//#endif
235
236#if HI_PROCESSOR == HI_CPU_X64
244#elif HI_PROCESSOR == HI_CPU_ARM
248constexpr std::size_t hardware_destructive_interference_size = 64;
249
253constexpr std::size_t hardware_constructive_interference_size = 64;
254
255#elif HI_PROCESSOR == HI_CPU_UNKNOWN
256constexpr std::size_t hardware_destructive_interference_size = 128;
257constexpr std::size_t hardware_constructive_interference_size = 64;
258#else
259#error "Missing implementation of hardware_destructive_interference_size and hardware_constructive_interference_size"
260#endif
261
262#if HI_OPERATING_SYSTEM == HI_OS_WINDOWS
263using os_handle = void *;
264using file_handle = os_handle;
265
266#elif HI_OPERATING_SYSTEM == HI_OS_MACOS
267using os_handle = int;
268using file_handle = int;
269
270#elif HI_OPERATING_SYSTEM == HI_OS_LINUX
271using os_handle = int;
272using file_handle = int;
273
274#else
275#error "file_handle Not implemented."
276#endif
277
278} // namespace hi::inline v1
void * os_handle
Minimum offset between two objects to avoid false sharing.
Definition architecture.hpp:263