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)
71#elif defined(__ICC) || defined(__INTEL_COMPILER)
73#elif defined(__GNUC__) || defined(__GNUG__)
76#elif defined(_MSC_VER)
78#elif defined(__BORLANDC__)
81# define ZYAN_UNKNOWN_COMPILER
90#elif defined(__EMSCRIPTEN__)
91# define ZYAN_EMSCRIPTEN
92#elif defined(__wasi__) || defined(__WASI__)
95#elif defined(__APPLE__)
101#elif defined(__FreeBSD__)
104#elif defined(__NetBSD__)
107#elif defined(sun) || defined(__sun)
110#elif defined(__HAIKU__)
113#elif defined(__unix) || defined(__unix__)
116#elif defined(__posix)
119# define ZYAN_UNKNOWN_PLATFORM
126#if (defined(ZYAN_WINDOWS) && defined(_KERNEL_MODE)) || \
127 (defined(ZYAN_APPLE) && defined(KERNEL)) || \
128 (defined(ZYAN_LINUX) && defined(__KERNEL__)) || \
129 (defined(__FreeBSD_kernel__))
139#if defined(_M_AMD64) || defined(__x86_64__)
141#elif defined(_M_IX86) || defined(__i386__)
143#elif defined(_M_ARM64) || defined(__aarch64__)
145#elif defined(_M_ARM) || defined(_M_ARMT) || defined(__arm__) || defined(__thumb__)
147#elif defined(__EMSCRIPTEN__) || defined(__wasm__) || defined(__WASM__)
149#elif defined(__loongarch__)
150# define ZYAN_LOONGARCH
151#elif defined(__powerpc64__)
153#elif defined(__powerpc__)
155#elif defined(__riscv) && __riscv_xlen == 64
158# error "Unsupported architecture detected"
165#if defined(ZYAN_MSVC) || defined(ZYAN_BORLAND)
171#elif defined(ZYAN_GNUC) || defined(ZYAN_ICC)
185#if defined(ZYAN_GCC) || defined(ZYAN_CLANG)
186# define ZYAN_DEPRECATED __attribute__((__deprecated__))
187#elif defined(ZYAN_MSVC)
188# define ZYAN_DEPRECATED __declspec(deprecated)
190# define ZYAN_DEPRECATED
197#if defined(ZYAN_MSVC) || (defined(ZYAN_WINDOWS) && defined(ZYAN_GNUC))
198# define ZYAN_DLLEXPORT __declspec(dllexport)
199# define ZYAN_DLLIMPORT __declspec(dllimport)
201# if defined(ZYAN_GNUC)
202# define ZYAN_DLLEXPORT __attribute__((__visibility__("default")))
203# define ZYAN_DLLIMPORT extern
205# define ZYAN_DLLEXPORT
206# define ZYAN_DLLIMPORT
226#if defined(ZYCORE_STATIC_DEFINE)
227# pragma message("ZYCORE_STATIC_DEFINE was renamed to ZYCORE_STATIC_BUILD.")
228# define ZYCORE_STATIC_BUILD
230#if defined(Zycore_EXPORTS)
231# pragma message("Zycore_EXPORTS was renamed to ZYCORE_SHOULD_EXPORT.")
232# define ZYCORE_SHOULD_EXPORT
238#if defined(ZYCORE_STATIC_BUILD)
239# define ZYCORE_EXPORT
241# if defined(ZYCORE_SHOULD_EXPORT)
242# define ZYCORE_EXPORT ZYAN_DLLEXPORT
244# define ZYCORE_EXPORT ZYAN_DLLIMPORT
251#if defined(ZYAN_GNUC)
252# define ZYCORE_NO_EXPORT __attribute__((__visibility__("hidden")))
254# define ZYCORE_NO_EXPORT
261#if defined(ZYAN_CLANG)
262# define ZYAN_NO_SANITIZE(what) __attribute__((no_sanitize(what)))
264# define ZYAN_NO_SANITIZE(what)
267#if defined(ZYAN_MSVC) || defined(ZYAN_BORLAND)
268# define ZYAN_INLINE __inline
270# define ZYAN_INLINE static inline
273#if defined(ZYAN_MSVC)
274# define ZYAN_NOINLINE __declspec(noinline)
275#elif defined(ZYAN_GCC) || defined(ZYAN_CLANG)
276# define ZYAN_NOINLINE __attribute__((noinline))
278# define ZYAN_NOINLINE
288#if defined(ZYAN_NO_LIBC)
289# define ZYAN_ASSERT(condition) (void)(condition)
290#elif defined(ZYAN_WINDOWS) && defined(ZYAN_KERNEL)
292# define ZYAN_ASSERT(condition) NT_ASSERT(condition)
295# define ZYAN_ASSERT(condition) assert(condition)
301#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
302# define ZYAN_STATIC_ASSERT(x) _Static_assert(x, #x)
303#elif (defined(__cplusplus) && __cplusplus >= 201103L) || \
304 (defined(__cplusplus) && defined (_MSC_VER) && (_MSC_VER >= 1600)) || \
305 (defined (_MSC_VER) && (_MSC_VER >= 1800))
306# define ZYAN_STATIC_ASSERT(x) static_assert(x, #x)
307#elif defined(ZYAN_GNUC)
308# define ZYAN_STATIC_ASSERT(x) \
309 __attribute__((unused)) typedef int ZYAN_MACRO_CONCAT_EXPAND(ZYAN_SASSERT_, __COUNTER__) [(x) ? 1 : -1]
311# define ZYAN_STATIC_ASSERT(x) \
312 typedef int ZYAN_MACRO_CONCAT_EXPAND(ZYAN_SASSERT_, __COUNTER__) [(x) ? 1 : -1]
318#if defined(ZYAN_RELEASE)
319# if defined(ZYAN_CLANG)
320# if __has_builtin(__builtin_unreachable)
321# define ZYAN_UNREACHABLE __builtin_unreachable()
323# define ZYAN_UNREACHABLE for(;;)
325# elif defined(ZYAN_GCC) && ((__GNUC__ == 4 && __GNUC_MINOR__ > 4) || __GNUC__ > 4)
326# define ZYAN_UNREACHABLE __builtin_unreachable()
327# elif defined(ZYAN_ICC)
330# define ZYAN_UNREACHABLE __assume(0); (void)abort()
332# define ZYAN_UNREACHABLE __builtin_unreachable()
334# elif defined(ZYAN_MSVC)
335# define ZYAN_UNREACHABLE __assume(0)
337# define ZYAN_UNREACHABLE for(;;)
339#elif defined(ZYAN_NO_LIBC)
340# define ZYAN_UNREACHABLE for(;;)
341#elif defined(ZYAN_WINDOWS) && defined(ZYAN_KERNEL)
342# define ZYAN_UNREACHABLE { __fastfail(0); for(;;){} }
345# define ZYAN_UNREACHABLE { assert(0); abort(); }
361#define ZYAN_UNUSED(x) (void)(x)
366#if defined(ZYAN_GCC) && __GNUC__ >= 7
367# define ZYAN_FALLTHROUGH ; __attribute__((__fallthrough__))
369# define ZYAN_FALLTHROUGH
377#define ZYAN_BITFIELD(x) : x
382#define ZYAN_REQUIRES_LIBC
390#if defined(__RESHARPER__)
391# define ZYAN_PRINTF_ATTR(format_index, first_to_check) \
392 [[gnu::format(printf, format_index, first_to_check)]]
393#elif defined(ZYAN_GCC)
394# define ZYAN_PRINTF_ATTR(format_index, first_to_check) \
395 __attribute__((format(printf, format_index, first_to_check)))
397# define ZYAN_PRINTF_ATTR(format_index, first_to_check)
406#if defined(__RESHARPER__)
407# define ZYAN_WPRINTF_ATTR(format_index, first_to_check) \
408 [[rscpp::format(wprintf, format_index, first_to_check)]]
410# define ZYAN_WPRINTF_ATTR(format_index, first_to_check)
424#define ZYAN_ARRAY_LENGTH(a) (sizeof(a) / sizeof((a)[0]))
438#define ZYAN_MIN(a, b) (((a) < (b)) ? (a) : (b))
448#define ZYAN_MAX(a, b) (((a) > (b)) ? (a) : (b))
457#define ZYAN_ABS(a) (((a) < 0) ? -(a) : (a))
468#define ZYAN_IS_POWER_OF_2(x) (((x) & ((x) - 1)) == 0)
475#define ZYAN_IS_ALIGNED_TO(x, align) (((x) & ((align) - 1)) == 0)
487#define ZYAN_ALIGN_UP(x, align) (((x) + (align) - 1) & ~((align) - 1))
499#define ZYAN_ALIGN_DOWN(x, align) (((x) - 1) & ~((align) - 1))
508#if defined(ZYAN_LINUX) && defined(ZYAN_KERNEL)
509# include <asm/div64.h>
510# define ZYAN_DIV64(n, divisor) do_div(n, divisor)
512# define ZYAN_DIV64(n, divisor) (n /= divisor)
530#define ZYAN_NEEDS_BIT(n, b) (((unsigned long)(n) >> (b)) > 0)
541#define ZYAN_BITS_TO_REPRESENT(n) \
543 ZYAN_NEEDS_BIT(n, 0) + ZYAN_NEEDS_BIT(n, 1) + \
544 ZYAN_NEEDS_BIT(n, 2) + ZYAN_NEEDS_BIT(n, 3) + \
545 ZYAN_NEEDS_BIT(n, 4) + ZYAN_NEEDS_BIT(n, 5) + \
546 ZYAN_NEEDS_BIT(n, 6) + ZYAN_NEEDS_BIT(n, 7) + \
547 ZYAN_NEEDS_BIT(n, 8) + ZYAN_NEEDS_BIT(n, 9) + \
548 ZYAN_NEEDS_BIT(n, 10) + ZYAN_NEEDS_BIT(n, 11) + \
549 ZYAN_NEEDS_BIT(n, 12) + ZYAN_NEEDS_BIT(n, 13) + \
550 ZYAN_NEEDS_BIT(n, 14) + ZYAN_NEEDS_BIT(n, 15) + \
551 ZYAN_NEEDS_BIT(n, 16) + ZYAN_NEEDS_BIT(n, 17) + \
552 ZYAN_NEEDS_BIT(n, 18) + ZYAN_NEEDS_BIT(n, 19) + \
553 ZYAN_NEEDS_BIT(n, 20) + ZYAN_NEEDS_BIT(n, 21) + \
554 ZYAN_NEEDS_BIT(n, 22) + ZYAN_NEEDS_BIT(n, 23) + \
555 ZYAN_NEEDS_BIT(n, 24) + ZYAN_NEEDS_BIT(n, 25) + \
556 ZYAN_NEEDS_BIT(n, 26) + ZYAN_NEEDS_BIT(n, 27) + \
557 ZYAN_NEEDS_BIT(n, 28) + ZYAN_NEEDS_BIT(n, 29) + \
558 ZYAN_NEEDS_BIT(n, 30) + ZYAN_NEEDS_BIT(n, 31) \