2
3
4
5
6
7
8
9#ifndef GIMBAL_PLATFORM_H
10#define GIMBAL_PLATFORM_H
18#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
31# include <TargetConditionals.h>
32# if TARGET_IPHONE_SIMULATOR
34# define GBL_IOS_SIMULATOR 1
35# elif TARGET_OS_MACCATALYST
37# define GBL_MACCATALYST 1
38# elif TARGET_OS_IPHONE
45# error "Unknown Apple platform"
51#elif defined(__DREAMCAST__)
52# define GBL_DREAMCAST 1
53#elif defined(__GAMECUBE__)
54# define GBL_GAMECUBE 1
64#elif defined(_POSIX_VERSION)
71#if defined(__x86_64__
) || defined(_M_X64)
73#elif defined(i386) || defined(__i386__) || defined(__i386) || defined(_M_IX86)
75#elif defined(__ARM_ARCH_2__)
77#elif defined(__ARM_ARCH_3__) || defined(__ARM_ARCH_3M__)
79#elif defined(__ARM_ARCH_4T__) || defined(__TARGET_ARM_4T)
81#elif defined(__ARM_ARCH_5_) || defined(__ARM_ARCH_5E_)
83#elif defined(__ARM_ARCH_6T2_) || defined(__ARM_ARCH_6T2_)
85#elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__)
87#elif defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__)
89#elif defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__)
91#elif defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__)
93#elif defined(__ARM_ARCH_7M__)
95#elif defined(__ARM_ARCH_7S__)
97#elif defined(__aarch64__) || defined(_M_ARM64)
99#elif defined(mips) || defined(__mips__) || defined(__mips)
103#elif defined(__powerpc) || defined(__powerpc__) || defined(__powerpc64__) || defined(__POWERPC__) || defined(__ppc__) || defined(__PPC__) || defined(_ARCH_PPC)
104# define GBL_POWERPC 1
105#elif defined(__PPC64__) || defined(__ppc64__) || defined(_ARCH_PPC64)
106# define GBL_POWERPC64 1
107#elif defined(__sparc__) || defined(__sparc)
109#elif defined(__m68k__)
115#if UINTPTR_MAX
== 0xffff
117#elif UINTPTR_MAX
== 0xffffffff
119#elif UINTPTR_MAX
== 0xffffffffffffffff
128# define GBL_INITIALIZER_PREFIX_ ""
130# define GBL_INITIALIZER_PREFIX_ "_"
133#if defined(__DREAMCAST__) || defined(__GAMECUBE__)
134# define GBL_THREAD_LOCAL_ _Thread_local
135#elif defined(__PSP__)
136# define GBL_THREAD_LOCAL_
138# define GBL_THREAD_LOCAL_ __thread
142# define GBL_INITIALIZER(f)
144 struct f##_t_ { f##_t_(void) { f(); } }; static f##_t_ f##_;
146#elif defined(_MSC_VER)
147# pragma section(".CRT$XCU",read)
148# define GBL_INITIALIZER2_(f,p)
150 __declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f;
151 __pragma(comment(linker,"/include:" p #f "_"))
153# define GBL_INITIALIZER(f) GBL_INITIALIZER2_(f, GBL_INITIALIZER_PREFIX_)
155# define GBL_INITIALIZER(f)
156 static void f(void) __attribute__((constructor));
161#if defined(TINYCTHREAD_ENABLE_THREADS) && !TINYCTHREAD_ENABLE_THREADS
162# define GBL_THREAD_LOCAL
163#elif defined(_MSC_VER)
164# define GBL_THREAD_LOCAL __declspec(thread)
169#if defined(_MSC_VER) || defined(__MINGW64__)
170# define GBL_ALIGNED_ALLOC(a, s) _aligned_malloc(s, a)
171# define GBL_ALIGNED_REALLOC(p, a, s) _aligned_realloc(p, s, a)
172# define GBL_ALIGNED_FREE(p) _aligned_free(p)
173#elif defined(__MINGW32__)
174# define GBL_ALIGNED_ALLOC(a, s) __mingw_aligned_malloc(s, a)
175# define GBL_ALIGNED_REALLOC(p, a, s) __mingw_aligned_realloc(p, s, a)
176# define GBL_ALIGNED_FREE(p) __mingw_aligned_free(p)
177#elif defined(GBL_C11) || defined(GBL_CPP17
)
179# define GBL_ALIGNED_ALLOC(a, s) aligned_alloc(a, s)
180# define GBL_ALIGNED_REALLOC(p, a, s) realloc(p, s)
181# define GBL_ALIGNED_FREE(p) free(p)
184#if GBL_CONFIG_PREFETCH_ENABLED
186# if defined(_MSC_VER) || defined(__MINGW64__)
187# if defined(_M_ARM64) || defined(_M_ARM64EC)
190# include <immintrin.h>
192# define GBL_PREFETCH(addr) _mm_prefetch(addr, _MM_HINT_T0)
193# elif defined(__GNUC__)
194# define GBL_PREFETCH __builtin_prefetch
197# define GBL_PREFETCH(...)
200# define GBL_PREFETCH(...)
205# if defined(__APPLE__) || defined(__GLIBC__
) ||
206 defined(__sun) || defined(__CYGWIN__) ||
207 defined(__EMSCRIPTEN__) || defined(VITA) ||
208 defined(__DREAMCAST__) || defined(PSP) ||
209 defined(__GAMECUBE__) || defined(GEKKO) ||
210 defined(__DEVKITARM__)
212# elif defined(_WIN32)
215# define alloca _alloca
220# define GBL_ALLOCA alloca
224# define GBL_QUICK_EXIT(c) exit(c)
225#elif defined(GBL_CPP11
)
226# define GBL_QUICK_EXIT(c) quick_exit(c)
227#elif defined(GBL_C11)
228# define GBL_QUICK_EXIT(c) quick_exit(c)
230# define GBL_QUICK_EXIT(c) exit(c)
234
235
236
237
238
239
240
241
242
243
244
245
247
248
249
250
251#if !(defined (GBL_STMT_START) && defined (GBL_STMT_END))
252# if defined (__GNUC__
) && !defined (__STRICT_ANSI__) && !defined (__cplusplus
)
253# define GBL_STMT_START do
254# define GBL_STMT_END while(0
)
256# if (defined (sun) || defined (__sun__))
257# define GBL_STMT_START if(1
)
258# define GBL_STMT_END else(void)0
260# define GBL_STMT_START do
261# define GBL_STMT_END while(0
)
269# define GBL_SIZE_TYPE GBL_UINT64_TYPE
270# define GBL_SIZE_BITS 64
272# define GBL_SIZE_TYPE GBL_UINT32_TYPE
273# define GBL_SIZE_BITS 32
278#if !defined(GBL_DREAMCAST) && !defined(GBL_GAMECUBE) && !defined(GBL_PSP)
279# define GBL_VARIANT_CONSTRUCT_GENERIC_PLATFORM_ENTRIES()
281# define GBL_VARIANT_CONSTRUCT_GENERIC_PLATFORM_ENTRIES()
282 (int, GblVariant_constructInt32),
290#if !defined(GBL_NO_TIMESPEC_)
291# if defined(ANDROID) || defined(__APPLE__) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(VITA) || defined(PSP)
292# define GBL_NO_TIMESPEC_
296#ifdef GBL_NO_TIMESPEC_
301GBL_INLINE
int gblTimespecGet_(
struct timespec* pSpec,
int base) {
305 if(clock_gettime(CLOCK_REALTIME, pSpec) == -1)
311# define timespec_get gblTimespecGet_
317# if defined(__APPLE__) || defined(__ANDROID__) || defined(__wasm__)
318# define GBL_PMR_HEADER_ <experimental/memory_resource>
319# define GBL_PMR_NAMESPACE_ std::experimental::pmr
321# define GBL_PMR_HEADER_ <memory_resource>
322# define GBL_PMR_NAMESPACE_ std::pmr
323# define GBL_PMR_VECTOR
324# define GBL_PMR_STRING
325# define GBL_LEX_CMP_3WAY
330# define GBL_PMR_VECTOR_ONLY_ GBL_EVAL0
336# define GBL_PMR_STRING_ONLY_ GBL_EVAL0
341#ifdef GBL_LEX_CMP_3WAY
342# define GBL_LEXICOGRAPHICAL_COMPARE_ std::lexicographical_compare_three_way
344# define GBL_LEXICOGRAPHICAL_COMPARE_ std::lexicographical_compare
350# define GBL_BIT_FIELDS_ENDIAN_XFORM_(...) (__VA_ARGS__)
352# define GBL_BIT_FIELDS_ENDIAN_XFORM_(...) (GBL_REVERSE(__VA_ARGS__))
357# define GBL_ENDIAN_SELECT_ GBL_ARG_1
358# define GBL_FROM_BIG_ENDIAN_U32_(value) (value)
359# define GBL_TO_LITTLE_ENDIAN_U16_(value) GBL_BSWAP_U16(value)
360# define GBL_TO_LITTLE_ENDIAN_U32_(value) GBL_BSWAP_U32(value)
364# define GBL_TO_LITTLE_ENDIAN_U16_(value) (value)
365# define GBL_TO_LITTLE_ENDIAN_U32_(value) (value)
372#if !defined(__DREAMCAST__) && !defined(__GAMECUBE__) && !defined(__VITA__)
373GBL_INLINE uint32_t gblLoadUnalignedU32_(
const void* pData) {
374 return *(
const uint32_t*)pData;
379GBL_INLINE uint32_t gblLoadUnalignedU32_(
const void* pData) {
381 memcpy(&value, pData,
sizeof(value));
#define GBL_MACRO_CALL_NULL(...)
#define GBL_ARG_2(_1, _2,...)