11#include <TargetConditionals.h>
16#define TT_BT_DEBUG 'D'
17#define TT_BT_RELEASE 'R'
20#define TT_BUILD_TYPE TT_BT_RELEASE
22#define TT_BUILD_TYPE TT_BT_DEBUG
25enum class build_type {
27 release = TT_BT_RELEASE,
29 current = TT_BUILD_TYPE
32#define TT_OS_WINDOWS 'W'
33#define TT_OS_MACOS 'A'
34#define TT_OS_MOBILE 'M'
35#define TT_OS_OTHER 'O'
38#define TT_OPERATING_SYSTEM TT_OS_WINDOWS
39#elif defined(TARGET_OS_MAC) && !defined(TARGET_OS_IPHONE)
40#define TT_OPERATING_SYSTEM TT_OS_MACOS
41#elif defined(TARGET_OS_IPHONE) || defined(__ANDROID__)
42#define TT_OPERATING_SYSTEM TT_OS_MOBILE
44#define TT_OPERATING_SYSTEM TT_OS_OTHER
47enum class operating_system {
48 windows = TT_OS_WINDOWS,
50 mobile = TT_OS_MOBILE,
53 current = TT_OPERATING_SYSTEM
58#define TT_CC_CLANG 'c'
61#define TT_COMPILER TT_CC_CLANG
62#elif defined(_MSC_BUILD)
63#define TT_COMPILER TT_CC_MSVC
64#elif defined(__GNUC__)
65#define TT_COMPILER TT_CC_GCC
67#error "Could not detect the compiler."
81#define TT_CPU_UNKNOWN 'u'
83#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64)
84#define TT_PROCESSOR TT_CPU_X64
85#elif defined(__arm__) || defined(_M_ARM)
86#define TT_PROCESSOR TT_CPU_ARM
88#define TT_PROCESSOR TT_CPU_UNKNOWN
94 unknown = TT_CPU_UNKNOWN,
96 current = TT_PROCESSOR
99#if TT_PROCESSOR == TT_CPU_X64
100#if defined(__AVX512BW__) && defined(__AVX512CD__) && defined(__AVX512DQ__) && defined(__AVX512F__) && defined(__AVX512VL__)
101#define TT_X86_64_V4 1
102#define TT_X86_64_V3 1
103#define TT_X86_64_V2_5 1
104#define TT_X86_64_V2 1
105#define TT_X86_64_V1 1
114#define TT_HAS_AVX512F
115#define TT_HAS_AVX512BW
116#define TT_HAS_AVX512CD
117#define TT_HAS_AVX512DQ
118#define TT_HAS_AVX512VL
120#elif defined(__AVX2__)
121#define TT_X86_64_V3 1
122#define TT_X86_64_V2_5 1
123#define TT_X86_64_V2 1
124#define TT_X86_64_V1 1
134#elif defined(__AVX__)
135#define TT_X86_64_V2_5 1
136#define TT_X86_64_V2 1
137#define TT_X86_64_V1 1
147#elif defined(__SSE4_2__) && defined(__SSSE3__)
148#define TT_X86_64_V2 1
149#define TT_X86_64_V1 1
158#define TT_X86_64_V1 1
164#if defined(TT_X86_64_V1)
165constexpr bool x86_64_v1 =
true;
167constexpr bool x86_64_v1 =
false;
170#if defined(TT_X86_64_V2)
171constexpr bool x86_64_v2 =
true;
173constexpr bool x86_64_v2 =
false;
176#if defined(TT_X86_64_V2_5)
177constexpr bool x86_64_v2_5 =
true;
179constexpr bool x86_64_v2_5 =
false;
182#if defined(TT_X86_64_V3)
183constexpr bool x86_64_v3 =
true;
185constexpr bool x86_64_v3 =
false;
188#if defined(TT_X86_64_V4)
189constexpr bool x86_64_v4 =
true;
191constexpr bool x86_64_v4 =
false;
194#if TT_COMPILER == TT_CC_MSVC
195#define tt_unreachable() __assume(0)
196#define tt_assume(condition) __assume(condition)
197#define tt_assume2(condition, msg) __assume(condition)
198#define tt_force_inline __forceinline
199#define tt_no_inline __declspec(noinline)
200#define tt_restrict __restrict
201#define tt_warning_push() _Pragma("warning( push )")
202#define tt_warning_pop() _Pragma("warning( pop )")
203#define tt_msvc_pragma(a) _Pragma(a)
204#define clang_suppress(a)
206#elif TT_COMPILER == TT_CC_CLANG
207#define tt_unreachable() __builtin_unreachable()
208#define tt_assume(condition) __builtin_assume(static_cast<bool>(condition))
209#define tt_assume2(condition, msg) __builtin_assume(static_cast<bool>(condition))
210#define tt_force_inline inline __attribute__((always_inline))
211#define tt_no_inline __attribute__((noinline))
212#define tt_restrict __restrict__
213#define tt_warning_push() _Pragma("warning(push)")
214#define tt_warning_pop() _Pragma("warning(push)")
215#define tt_msvc_pragma(a)
216#define clang_suppress(a) _Pragma(tt_stringify(clang diagnostic ignored a))
218#elif TT_COMPILER == TT_CC_GCC
219#define tt_unreachable() __builtin_unreachable()
220#define tt_assume(condition) do { if (!(condition)) tt_unreachable(); } while (false)
221#define tt_assume2(condition, msg) do { if (!(condition)) tt_unreachable(); } while (false)
222#define tt_force_inline inline __attribute__((always_inline))
223#define tt_no_inline __attribute__((noinline))
224#define tt_restrict __restrict__
225#define tt_warning_push() _Pragma("warning(push)")
226#define tt_warning_pop() _Pragma("warning(pop)")
227#define tt_msvc_pragma(a)
228#define clang_suppress(a)
229#define msvc_pragma(a)
232#define tt_unreachable() std::terminate()
233#define tt_assume(condition) static_assert(sizeof(condition) == 1)
234#define tt_assume2(condition, msg) static_assert(sizeof(condition) == 1, msg)
235#define tt_force_inline inline
238#define tt_warning_push()
239#define tt_warning_pop()
240#define tt_msvc_pragma(a)
241#define clang_suppress(a)
242#define msvc_pragma(a)
246#if TT_PROCESSOR == TT_CPU_X64
250constexpr size_t hardware_destructive_interference_size = 128;
255constexpr size_t hardware_constructive_interference_size = 64;
256#elif TT_PROCESSOR == TT_CPU_ARM
260constexpr size_t hardware_destructive_interference_size = 64;
265constexpr size_t hardware_constructive_interference_size = 64;
267#elif TT_PROCESSOR == TT_CPU_UNKNOWN
268constexpr size_t hardware_destructive_interference_size = 128;
269constexpr size_t hardware_constructive_interference_size = 64;
271#error "Missing implementation of hardware_destructive_interference_size and hardware_constructive_interference_size"
274#if TT_OPERATING_SYSTEM == TT_OS_WINDOWS
275using os_handle =
void *;
276using file_handle = os_handle;
278#elif TT_OPERATING_SYSTEM == TT_OS_MACOS
279using os_handle = int;
280using file_handle = int;
282#elif TT_OPERATING_SYSTEM == TT_OS_LINUX
283using os_handle = int;
284using file_handle = int;
287#error "file_handle Not implemented."