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(__NetBSD__)
103#elif defined(sun) || defined(__sun)
106#elif defined(__HAIKU__)
109#elif defined(__unix) || defined(__unix__)
112#elif defined(__posix)
115# define ZYAN_UNKNOWN_PLATFORM
122#if (defined(ZYAN_WINDOWS) && defined(_KERNEL_MODE)) || \
123 (defined(ZYAN_APPLE) && defined(KERNEL)) || \
124 (defined(ZYAN_LINUX) && defined(__KERNEL__)) || \
125 (defined(__FreeBSD_kernel__))
135#if defined(_M_AMD64) || defined(__x86_64__)
137#elif defined(_M_IX86) || defined(__i386__)
139#elif defined(_M_ARM64) || defined(__aarch64__)
141#elif defined(_M_ARM) || defined(_M_ARMT) || defined(__arm__) || defined(__thumb__)
143#elif defined(__EMSCRIPTEN__) || defined(__wasm__) || defined(__WASM__)
145#elif defined(__loongarch__)
146# define ZYAN_LOONGARCH
147#elif defined(__powerpc64__)
149#elif defined(__powerpc__)
151#elif defined(__riscv) && __riscv_xlen == 64
154# error "Unsupported architecture detected"
161#if defined(ZYAN_MSVC) || defined(ZYAN_BORLAND)
167#elif defined(ZYAN_GNUC) || defined(ZYAN_ICC)
181#if defined(ZYAN_GCC) || defined(ZYAN_CLANG)
182# define ZYAN_DEPRECATED __attribute__((__deprecated__))
183#elif defined(ZYAN_MSVC)
184# define ZYAN_DEPRECATED __declspec(deprecated)
186# define ZYAN_DEPRECATED
193#if defined(ZYAN_MSVC)
194# define ZYAN_DLLEXPORT __declspec(dllexport)
195# define ZYAN_DLLIMPORT __declspec(dllimport)
197# define ZYAN_DLLEXPORT
198# define ZYAN_DLLIMPORT
217#if defined(ZYCORE_STATIC_DEFINE)
218# pragma message("ZYCORE_STATIC_DEFINE was renamed to ZYCORE_STATIC_BUILD.")
219# define ZYCORE_STATIC_BUILD
221#if defined(Zycore_EXPORTS)
222# pragma message("Zycore_EXPORTS was renamed to ZYCORE_SHOULD_EXPORT.")
223# define ZYCORE_SHOULD_EXPORT
229#if defined(ZYCORE_STATIC_BUILD)
230# define ZYCORE_EXPORT
232# if defined(ZYCORE_SHOULD_EXPORT)
233# define ZYCORE_EXPORT ZYAN_DLLEXPORT
235# define ZYCORE_EXPORT ZYAN_DLLIMPORT
242#define ZYCORE_NO_EXPORT
248#if defined(ZYAN_CLANG)
249# define ZYAN_NO_SANITIZE(what) __attribute__((no_sanitize(what)))
251# define ZYAN_NO_SANITIZE(what)
254#if defined(ZYAN_MSVC) || defined(ZYAN_BORLAND)
255# define ZYAN_INLINE __inline
257# define ZYAN_INLINE static inline
260#if defined(ZYAN_MSVC)
261# define ZYAN_NOINLINE __declspec(noinline)
262#elif defined(ZYAN_GCC) || defined(ZYAN_CLANG)
263# define ZYAN_NOINLINE __attribute__((noinline))
265# define ZYAN_NOINLINE
275#if defined(ZYAN_NO_LIBC)
276# define ZYAN_ASSERT(condition) (void)(condition)
277#elif defined(ZYAN_WINDOWS) && defined(ZYAN_KERNEL)
279# define ZYAN_ASSERT(condition) NT_ASSERT(condition)
282# define ZYAN_ASSERT(condition) assert(condition)
288#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
289# define ZYAN_STATIC_ASSERT(x) _Static_assert(x, #x)
290#elif (defined(__cplusplus) && __cplusplus >= 201103L) || \
291 (defined(__cplusplus) && defined (_MSC_VER) && (_MSC_VER >= 1600)) || \
292 (defined (_MSC_VER) && (_MSC_VER >= 1800))
293# define ZYAN_STATIC_ASSERT(x) static_assert(x, #x)
295# define ZYAN_STATIC_ASSERT(x) \
296 typedef int ZYAN_MACRO_CONCAT_EXPAND(ZYAN_SASSERT_, __COUNTER__) [(x) ? 1 : -1]
302#if defined(ZYAN_RELEASE)
303# if defined(ZYAN_CLANG)
304# if __has_builtin(__builtin_unreachable)
305# define ZYAN_UNREACHABLE __builtin_unreachable()
307# define ZYAN_UNREACHABLE for(;;)
309# elif defined(ZYAN_GCC) && ((__GNUC__ == 4 && __GNUC_MINOR__ > 4) || __GNUC__ > 4)
310# define ZYAN_UNREACHABLE __builtin_unreachable()
311# elif defined(ZYAN_ICC)
314# define ZYAN_UNREACHABLE __assume(0); (void)abort()
316# define ZYAN_UNREACHABLE __builtin_unreachable()
318# elif defined(ZYAN_MSVC)
319# define ZYAN_UNREACHABLE __assume(0)
321# define ZYAN_UNREACHABLE for(;;)
323#elif defined(ZYAN_NO_LIBC)
324# define ZYAN_UNREACHABLE for(;;)
325#elif defined(ZYAN_WINDOWS) && defined(ZYAN_KERNEL)
326# define ZYAN_UNREACHABLE { __fastfail(0); for(;;){} }
329# define ZYAN_UNREACHABLE { assert(0); abort(); }
345#define ZYAN_UNUSED(x) (void)(x)
350#if defined(ZYAN_GCC) && __GNUC__ >= 7
351# define ZYAN_FALLTHROUGH ; __attribute__((__fallthrough__))
353# define ZYAN_FALLTHROUGH
361#define ZYAN_BITFIELD(x) : x
366#define ZYAN_REQUIRES_LIBC
374#if defined(__RESHARPER__)
375# define ZYAN_PRINTF_ATTR(format_index, first_to_check) \
376 [[gnu::format(printf, format_index, first_to_check)]]
377#elif defined(ZYAN_GCC)
378# define ZYAN_PRINTF_ATTR(format_index, first_to_check) \
379 __attribute__((format(printf, format_index, first_to_check)))
381# define ZYAN_PRINTF_ATTR(format_index, first_to_check)
390#if defined(__RESHARPER__)
391# define ZYAN_WPRINTF_ATTR(format_index, first_to_check) \
392 [[rscpp::format(wprintf, format_index, first_to_check)]]
394# define ZYAN_WPRINTF_ATTR(format_index, first_to_check)
408#define ZYAN_ARRAY_LENGTH(a) (sizeof(a) / sizeof((a)[0]))
422#define ZYAN_MIN(a, b) (((a) < (b)) ? (a) : (b))
432#define ZYAN_MAX(a, b) (((a) > (b)) ? (a) : (b))
441#define ZYAN_ABS(a) (((a) < 0) ? -(a) : (a))
452#define ZYAN_IS_POWER_OF_2(x) (((x) & ((x) - 1)) == 0)
459#define ZYAN_IS_ALIGNED_TO(x, align) (((x) & ((align) - 1)) == 0)
471#define ZYAN_ALIGN_UP(x, align) (((x) + (align) - 1) & ~((align) - 1))
483#define ZYAN_ALIGN_DOWN(x, align) (((x) - 1) & ~((align) - 1))
492#if defined(ZYAN_LINUX) && defined(ZYAN_KERNEL)
493# include <asm/div64.h>
494# define ZYAN_DIV64(n, divisor) do_div(n, divisor)
496# define ZYAN_DIV64(n, divisor) (n /= divisor)
514#define ZYAN_NEEDS_BIT(n, b) (((unsigned long)(n) >> (b)) > 0)
525#define ZYAN_BITS_TO_REPRESENT(n) \
527 ZYAN_NEEDS_BIT(n, 0) + ZYAN_NEEDS_BIT(n, 1) + \
528 ZYAN_NEEDS_BIT(n, 2) + ZYAN_NEEDS_BIT(n, 3) + \
529 ZYAN_NEEDS_BIT(n, 4) + ZYAN_NEEDS_BIT(n, 5) + \
530 ZYAN_NEEDS_BIT(n, 6) + ZYAN_NEEDS_BIT(n, 7) + \
531 ZYAN_NEEDS_BIT(n, 8) + ZYAN_NEEDS_BIT(n, 9) + \
532 ZYAN_NEEDS_BIT(n, 10) + ZYAN_NEEDS_BIT(n, 11) + \
533 ZYAN_NEEDS_BIT(n, 12) + ZYAN_NEEDS_BIT(n, 13) + \
534 ZYAN_NEEDS_BIT(n, 14) + ZYAN_NEEDS_BIT(n, 15) + \
535 ZYAN_NEEDS_BIT(n, 16) + ZYAN_NEEDS_BIT(n, 17) + \
536 ZYAN_NEEDS_BIT(n, 18) + ZYAN_NEEDS_BIT(n, 19) + \
537 ZYAN_NEEDS_BIT(n, 20) + ZYAN_NEEDS_BIT(n, 21) + \
538 ZYAN_NEEDS_BIT(n, 22) + ZYAN_NEEDS_BIT(n, 23) + \
539 ZYAN_NEEDS_BIT(n, 24) + ZYAN_NEEDS_BIT(n, 25) + \
540 ZYAN_NEEDS_BIT(n, 26) + ZYAN_NEEDS_BIT(n, 27) + \
541 ZYAN_NEEDS_BIT(n, 28) + ZYAN_NEEDS_BIT(n, 29) + \
542 ZYAN_NEEDS_BIT(n, 30) + ZYAN_NEEDS_BIT(n, 31) \