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."
82#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64)
83#define TT_PROCESSOR TT_CPU_X64
84#elif defined(__arm__) || defined(_M_ARM)
85#define TT_PROCESSOR TT_CPU_ARM
87#error "Could not detect processor."
94 current = TT_PROCESSOR
97#if TT_PROCESSOR == TT_CPU_X64
98#if defined(__AVX512BW__) && defined(__AVX512CD__) && defined(__AVX512DQ__) && defined(__AVX512F__) && defined(__AVX512VL__)
100#define TT_X86_64_V3 1
101#define TT_X86_64_V2_5 1
102#define TT_X86_64_V2 1
103#define TT_X86_64_V1 1
105#elif defined(__AVX2__)
106#define TT_X86_64_V3 1
107#define TT_X86_64_V2_5 1
108#define TT_X86_64_V2 1
109#define TT_X86_64_V1 1
111#elif defined(__AVX__)
112#define TT_X86_64_V2_5 1
113#define TT_X86_64_V2 1
114#define TT_X86_64_V1 1
117#elif defined(__SSE4_2__) && defined(__SSSE3__)
118#define TT_X86_64_V2 1
119#define TT_X86_64_V1 1
122#define TT_X86_64_V1 1
126#if defined(TT_X86_64_V1)
127constexpr bool x86_64_v1 =
true;
129constexpr bool x86_64_v1 =
false;
132#if defined(TT_X86_64_V2)
133constexpr bool x86_64_v2 =
true;
135constexpr bool x86_64_v2 =
false;
138#if defined(TT_X86_64_V2_5)
139constexpr bool x86_64_v2_5 =
true;
141constexpr bool x86_64_v2_5 =
false;
144#if defined(TT_X86_64_V3)
145constexpr bool x86_64_v3 =
true;
147constexpr bool x86_64_v3 =
false;
150#if defined(TT_X86_64_V4)
151constexpr bool x86_64_v4 =
true;
153constexpr bool x86_64_v4 =
false;
156#if TT_COMPILER == TT_CC_MSVC
157#define tt_unreachable() __assume(0)
158#define tt_assume(condition) __assume(condition)
159#define tt_assume2(condition, msg) __assume(condition)
160#define tt_force_inline __forceinline
161#define tt_no_inline __declspec(noinline)
162#define tt_restrict __restrict
163#define clang_suppress(a)
164#define msvc_pragma(a) _Pragma(a)
166#elif TT_COMPILER == TT_CC_CLANG
167#define tt_unreachable() __builtin_unreachable()
168#define tt_assume(condition) __builtin_assume(static_cast<bool>(condition))
169#define tt_assume2(condition, msg) __builtin_assume(static_cast<bool>(condition))
170#define tt_force_inline inline __attribute__((always_inline))
171#define tt_no_inline __attribute__((noinline))
172#define tt_restrict __restrict__
173#define clang_suppress(a) _Pragma(tt_stringify(clang diagnostic ignored a))
174#define msvc_pragma(a)
176#elif TT_COMPILER == TT_CC_GCC
177#define tt_unreachable() __builtin_unreachable()
178#define tt_assume(condition) do { if (!(condition)) tt_unreachable(); } while (false)
179#define tt_assume2(condition, msg) do { if (!(condition)) tt_unreachable(); } while (false)
180#define tt_force_inline inline __attribute__((always_inline))
181#define tt_no_inline __attribute__((noinline))
182#define tt_restrict __restrict__
183#define clang_suppress(a)
184#define msvc_pragma(a)
187#define tt_unreachable() std::terminate()
188#define tt_assume(condition) static_assert(sizeof(condition) == 1)
189#define tt_assume2(condition, msg) static_assert(sizeof(condition) == 1, msg)
190#define tt_force_inline inline
193#define clang_suppress(a)
194#define msvc_pragma(a)
198#if TT_PROCESSOR == TT_CPU_X64
202constexpr size_t hardware_destructive_interference_size = 128;
207constexpr size_t hardware_constructive_interference_size = 64;
208#elif TT_PROCESSOR == TT_CPU_ARM
212constexpr size_t hardware_destructive_interference_size = 64;
217constexpr size_t hardware_constructive_interference_size = 64;
219#error "Missing implementation of hardware_destructive_interference_size and hardware_constructive_interference_size"
222#if TT_OPERATING_SYSTEM == TT_OS_WINDOWS
223using os_handle =
void *;
224using file_handle = os_handle;
226#elif TT_OPERATING_SYSTEM == TT_OS_MACOS
227using os_handle = int;
228using file_handle = int;
230#elif TT_OPERATING_SYSTEM == TT_OS_LINUX
231using os_handle = int;
232using file_handle = int;
235#error "file_handle Not implemented."