Loading...
Searching...
No Matches
Go to the documentation of this file.
32#ifndef ZYCORE_DEFINES_H
33#define ZYCORE_DEFINES_H
47#define ZYAN_MACRO_CONCAT(x, y) x ## y
58#define ZYAN_MACRO_CONCAT_EXPAND(x, y) ZYAN_MACRO_CONCAT(x, y)
67#elif defined(__ICC) || defined(__INTEL_COMPILER)
69#elif defined(__GNUC__) || defined(__GNUG__)
72#elif defined(_MSC_VER)
74#elif defined(__BORLANDC__)
77# define ZYAN_UNKNOWN_COMPILER
86#elif defined(__EMSCRIPTEN__)
87# define ZYAN_EMSCRIPTEN
88#elif defined(__wasi__) || defined(__WASI__)
91#elif defined(__APPLE__)
97#elif defined(__FreeBSD__)
100#elif defined(sun) || defined(__sun)
106#elif defined(__posix)
109# define ZYAN_UNKNOWN_PLATFORM
116#if (defined(ZYAN_WINDOWS) && defined(_KERNEL_MODE)) || \
117 (defined(ZYAN_APPLE) && defined(KERNEL)) || \
118 (defined(ZYAN_LINUX) && defined(__KERNEL__)) || \
119 (defined(__FreeBSD_kernel__))
129#if defined(_M_AMD64) || defined(__x86_64__)
131#elif defined(_M_IX86) || defined(__i386__)
133#elif defined(_M_ARM64) || defined(__aarch64__)
135#elif defined(_M_ARM) || defined(_M_ARMT) || defined(__arm__) || defined(__thumb__)
137#elif defined(__EMSCRIPTEN__) || defined(__wasm__) || defined(__WASM__)
139#elif defined(__powerpc64__)
141#elif defined(__powerpc__)
143#elif defined(__riscv) && __riscv_xlen == 64
146# error "Unsupported architecture detected"
153#if defined(ZYAN_MSVC) || defined(ZYAN_BORLAND)
159#elif defined(ZYAN_GNUC) || defined(ZYAN_ICC)
173#if defined(ZYAN_GCC) || defined(ZYAN_CLANG)
174# define ZYAN_DEPRECATED __attribute__((__deprecated__))
175#elif defined(ZYAN_MSVC)
176# define ZYAN_DEPRECATED __declspec(deprecated)
178# define ZYAN_DEPRECATED
185#if defined(ZYAN_MSVC)
186# define ZYAN_DLLEXPORT __declspec(dllexport)
187# define ZYAN_DLLIMPORT __declspec(dllimport)
189# define ZYAN_DLLEXPORT
190# define ZYAN_DLLIMPORT
209#if defined(ZYCORE_STATIC_DEFINE)
210# pragma message("ZYCORE_STATIC_DEFINE was renamed to ZYCORE_STATIC_BUILD.")
211# define ZYCORE_STATIC_BUILD
213#if defined(Zycore_EXPORTS)
214# pragma message("Zycore_EXPORTS was renamed to ZYCORE_SHOULD_EXPORT.")
215# define ZYCORE_SHOULD_EXPORT
221#if defined(ZYCORE_STATIC_BUILD)
222# define ZYCORE_EXPORT
224# if defined(ZYCORE_SHOULD_EXPORT)
225# define ZYCORE_EXPORT ZYAN_DLLEXPORT
227# define ZYCORE_EXPORT ZYAN_DLLIMPORT
234#define ZYCORE_NO_EXPORT
240#if defined(ZYAN_CLANG)
241# define ZYAN_NO_SANITIZE(what) __attribute__((no_sanitize(what)))
243# define ZYAN_NO_SANITIZE(what)
246#if defined(ZYAN_MSVC) || defined(ZYAN_BORLAND)
247# define ZYAN_INLINE __inline
249# define ZYAN_INLINE static inline
252#if defined(ZYAN_MSVC)
253# define ZYAN_NOINLINE __declspec(noinline)
254#elif defined(ZYAN_GCC) || defined(ZYAN_CLANG)
255# define ZYAN_NOINLINE __attribute__((noinline))
257# define ZYAN_NOINLINE
267#if defined(ZYAN_NO_LIBC)
268# define ZYAN_ASSERT(condition) (void)(condition)
269#elif defined(ZYAN_WINDOWS) && defined(ZYAN_KERNEL)
271# define ZYAN_ASSERT(condition) NT_ASSERT(condition)
274# define ZYAN_ASSERT(condition) assert(condition)
280#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
281# define ZYAN_STATIC_ASSERT(x) _Static_assert(x, #x)
282#elif (defined(__cplusplus) && __cplusplus >= 201103L) || \
283 (defined(__cplusplus) && defined (_MSC_VER) && (_MSC_VER >= 1600)) || \
284 (defined (_MSC_VER) && (_MSC_VER >= 1800))
285# define ZYAN_STATIC_ASSERT(x) static_assert(x, #x)
287# define ZYAN_STATIC_ASSERT(x) \
288 typedef int ZYAN_MACRO_CONCAT_EXPAND(ZYAN_SASSERT_, __COUNTER__) [(x) ? 1 : -1]
294#if defined(ZYAN_RELEASE)
295# if defined(ZYAN_CLANG)
296# if __has_builtin(__builtin_unreachable)
297# define ZYAN_UNREACHABLE __builtin_unreachable()
299# define ZYAN_UNREACHABLE for(;;)
301# elif defined(ZYAN_GCC) && ((__GNUC__ == 4 && __GNUC_MINOR__ > 4) || __GNUC__ > 4)
302# define ZYAN_UNREACHABLE __builtin_unreachable()
303# elif defined(ZYAN_ICC)
306# define ZYAN_UNREACHABLE __assume(0); (void)abort()
308# define ZYAN_UNREACHABLE __builtin_unreachable()
310# elif defined(ZYAN_MSVC)
311# define ZYAN_UNREACHABLE __assume(0)
313# define ZYAN_UNREACHABLE for(;;)
315#elif defined(ZYAN_NO_LIBC)
316# define ZYAN_UNREACHABLE for(;;)
317#elif defined(ZYAN_WINDOWS) && defined(ZYAN_KERNEL)
318# define ZYAN_UNREACHABLE { __fastfail(0); for(;;){} }
321# define ZYAN_UNREACHABLE { assert(0); abort(); }
337#define ZYAN_UNUSED(x) (void)(x)
342#if defined(ZYAN_GCC) && __GNUC__ >= 7
343# define ZYAN_FALLTHROUGH ; __attribute__((__fallthrough__))
345# define ZYAN_FALLTHROUGH
353#define ZYAN_BITFIELD(x) : x
358#define ZYAN_REQUIRES_LIBC
366#if defined(__RESHARPER__)
367# define ZYAN_PRINTF_ATTR(format_index, first_to_check) \
368 [[gnu::format(printf, format_index, first_to_check)]]
369#elif defined(ZYAN_GCC)
370# define ZYAN_PRINTF_ATTR(format_index, first_to_check) \
371 __attribute__((format(printf, format_index, first_to_check)))
373# define ZYAN_PRINTF_ATTR(format_index, first_to_check)
382#if defined(__RESHARPER__)
383# define ZYAN_WPRINTF_ATTR(format_index, first_to_check) \
384 [[rscpp::format(wprintf, format_index, first_to_check)]]
386# define ZYAN_WPRINTF_ATTR(format_index, first_to_check)
400#define ZYAN_ARRAY_LENGTH(a) (sizeof(a) / sizeof((a)[0]))
414#define ZYAN_MIN(a, b) (((a) < (b)) ? (a) : (b))
424#define ZYAN_MAX(a, b) (((a) > (b)) ? (a) : (b))
433#define ZYAN_ABS(a) (((a) < 0) ? -(a) : (a))
444#define ZYAN_IS_POWER_OF_2(x) (((x) & ((x) - 1)) == 0)
451#define ZYAN_IS_ALIGNED_TO(x, align) (((x) & ((align) - 1)) == 0)
463#define ZYAN_ALIGN_UP(x, align) (((x) + (align) - 1) & ~((align) - 1))
475#define ZYAN_ALIGN_DOWN(x, align) (((x) - 1) & ~((align) - 1))
492#define ZYAN_NEEDS_BIT(n, b) (((unsigned long)(n) >> (b)) > 0)
503#define ZYAN_BITS_TO_REPRESENT(n) \
505 ZYAN_NEEDS_BIT(n, 0) + ZYAN_NEEDS_BIT(n, 1) + \
506 ZYAN_NEEDS_BIT(n, 2) + ZYAN_NEEDS_BIT(n, 3) + \
507 ZYAN_NEEDS_BIT(n, 4) + ZYAN_NEEDS_BIT(n, 5) + \
508 ZYAN_NEEDS_BIT(n, 6) + ZYAN_NEEDS_BIT(n, 7) + \
509 ZYAN_NEEDS_BIT(n, 8) + ZYAN_NEEDS_BIT(n, 9) + \
510 ZYAN_NEEDS_BIT(n, 10) + ZYAN_NEEDS_BIT(n, 11) + \
511 ZYAN_NEEDS_BIT(n, 12) + ZYAN_NEEDS_BIT(n, 13) + \
512 ZYAN_NEEDS_BIT(n, 14) + ZYAN_NEEDS_BIT(n, 15) + \
513 ZYAN_NEEDS_BIT(n, 16) + ZYAN_NEEDS_BIT(n, 17) + \
514 ZYAN_NEEDS_BIT(n, 18) + ZYAN_NEEDS_BIT(n, 19) + \
515 ZYAN_NEEDS_BIT(n, 20) + ZYAN_NEEDS_BIT(n, 21) + \
516 ZYAN_NEEDS_BIT(n, 22) + ZYAN_NEEDS_BIT(n, 23) + \
517 ZYAN_NEEDS_BIT(n, 24) + ZYAN_NEEDS_BIT(n, 25) + \
518 ZYAN_NEEDS_BIT(n, 26) + ZYAN_NEEDS_BIT(n, 27) + \
519 ZYAN_NEEDS_BIT(n, 28) + ZYAN_NEEDS_BIT(n, 29) + \
520 ZYAN_NEEDS_BIT(n, 30) + ZYAN_NEEDS_BIT(n, 31) \