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
96using intreg_t = int32_t;
97using uintreg_t = uint32_t;
98constexpr std::size_t hardware_destructive_interference_size = 128;
99constexpr std::size_t hardware_constructive_interference_size = 64;
100#elif HI_PROCESSOR == HI_CPU_X64
101using intreg_t = int64_t;
102using uintreg_t = uint64_t;
103constexpr std::size_t hardware_destructive_interference_size = 128;
104constexpr std::size_t hardware_constructive_interference_size = 64;
105#elif HI_PROCESSOR == HI_CPU_ARM
106using intreg_t = int32_t;
107using uintreg_t = uint32_t;
108constexpr std::size_t hardware_destructive_interference_size = 128;
109constexpr std::size_t hardware_constructive_interference_size = 64;
110#elif HI_PROCESSOR == HI_CPU_ARM64
111using intreg_t = int64_t;
112using uintreg_t = uint64_t;
113constexpr std::size_t hardware_destructive_interference_size = 128;
114constexpr std::size_t hardware_constructive_interference_size = 64;
115#else
116#error "missing implementation for CPU specific register and cache-line sizes"
117#endif
118
119#if defined(__AVX512BW__) && defined(__AVX512CD__) && defined(__AVX512DQ__) && defined(__AVX512F__) && defined(__AVX512VL__)
120#define HI_X86_64_V4 1
121#define HI_X86_64_V3 1
122#define HI_X86_64_V2_5 1
123#define HI_X86_64_V2 1
124#define HI_X86_64_V1 1
125#define HI_HAS_SSE 1
126#define HI_HAS_SSE2 1
127#define HI_HAS_SSE3 1
128#define HI_HAS_SSE4_1 1
129#define HI_HAS_SSE4_2 1
130#define HI_HAS_SSSE3 1
131#define HI_HAS_AVX 1
132#define HI_HAS_AVX2 1
133#define HI_HAS_BMI1 1
134#define HI_HAS_BMI2 1
135#define HI_HAS_AVX512F 1
136#define HI_HAS_AVX512BW 1
137#define HI_HAS_AVX512CD 1
138#define HI_HAS_AVX512DQ 1
139#define HI_HAS_AVX512VL 1
140
141#elif defined(__AVX2__)
142#define HI_X86_64_V3 1
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 1
147#define HI_HAS_SSE2 1
148#define HI_HAS_SSE3 1
149#define HI_HAS_SSE4_1 1
150#define HI_HAS_SSE4_2 1
151#define HI_HAS_SSSE3 1
152#define HI_HAS_AVX 1
153#define HI_HAS_AVX2 1
154#define HI_HAS_BMI1 1
155#define HI_HAS_BMI2 1
156
157#elif defined(__AVX__)
158#define HI_X86_64_V2_5 1
159#define HI_X86_64_V2 1
160#define HI_X86_64_V1 1
161#define HI_HAS_SSE 1
162#define HI_HAS_SSE2 1
163#define HI_HAS_SSE3 1
164#define HI_HAS_SSE4_1 1
165#define HI_HAS_SSE4_2 1
166#define HI_HAS_SSSE3 1
167#define HI_HAS_AVX 1
168
169// x86_64_v2 can not be selected in MSVC, but can be in gcc and clang.
170#elif defined(__SSE4_2__) && defined(__SSSE3__)
171#define HI_X86_64_V2 1
172#define HI_X86_64_V1 1
173#define HI_HAS_SSE 1
174#define HI_HAS_SSE2 1
175#define HI_HAS_SSE3 1
176#define HI_HAS_SSE4_1 1
177#define HI_HAS_SSE4_2 1
178#define HI_HAS_SSSE3 1
179
180#elif HI_PROCESSOR == HI_CPU_X64
181#define HI_X86_64_V1 1
182#define HI_HAS_SSE 1
183#define HI_HAS_SSE2 1
184
185#elif HI_PROCESSOR == HI_CPU_X86
186#elif HI_PROCESSOR == HI_CPU_ARM64
187#elif HI_PROCESSOR == HI_CPU_ARM
188#endif
189
190//#if defined(HI_X86_64_V1)
191//constexpr bool x86_64_v1 = true;
192//#else
193//constexpr bool x86_64_v1 = false;
194//#endif
195//
196//#if defined(HI_X86_64_V2)
197//constexpr bool x86_64_v2 = true;
198//#else
199//constexpr bool x86_64_v2 = false;
200//#endif
201//
202//#if defined(HI_X86_64_V2_5)
203//constexpr bool x86_64_v2_5 = true;
204//#else
205//constexpr bool x86_64_v2_5 = false;
206//#endif
207//
208//#if defined(HI_X86_64_V3)
209//constexpr bool x86_64_v3 = true;
210//#else
211//constexpr bool x86_64_v3 = false;
212//#endif
213//
214//#if defined(HI_X86_64_V4)
215//constexpr bool x86_64_v4 = true;
216//#else
217//constexpr bool x86_64_v4 = false;
218//#endif
219
220#if HI_PROCESSOR == HI_CPU_X64
228#elif HI_PROCESSOR == HI_CPU_ARM
232constexpr std::size_t hardware_destructive_interference_size = 64;
233
237constexpr std::size_t hardware_constructive_interference_size = 64;
238
239#elif HI_PROCESSOR == HI_CPU_UNKNOWN
240constexpr std::size_t hardware_destructive_interference_size = 128;
241constexpr std::size_t hardware_constructive_interference_size = 64;
242#else
243#error "Missing implementation of hardware_destructive_interference_size and hardware_constructive_interference_size"
244#endif
245
246#if HI_OPERATING_SYSTEM == HI_OS_WINDOWS
247using os_handle = void *;
248using file_handle = os_handle;
249
250#elif HI_OPERATING_SYSTEM == HI_OS_MACOS
251using os_handle = int;
252using file_handle = int;
253
254#elif HI_OPERATING_SYSTEM == HI_OS_LINUX
255using os_handle = int;
256using file_handle = int;
257
258#else
259#error "file_handle Not implemented."
260#endif
261
262} // 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:247