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(__loongarch__)
140# define ZYAN_LOONGARCH
141#elif defined(__powerpc64__)
143#elif defined(__powerpc__)
145#elif defined(__riscv) && __riscv_xlen == 64
148# error "Unsupported architecture detected"
155#if defined(ZYAN_MSVC) || defined(ZYAN_BORLAND)
161#elif defined(ZYAN_GNUC) || defined(ZYAN_ICC)
175#if defined(ZYAN_GCC) || defined(ZYAN_CLANG)
176# define ZYAN_DEPRECATED __attribute__((__deprecated__))
177#elif defined(ZYAN_MSVC)
178# define ZYAN_DEPRECATED __declspec(deprecated)
180# define ZYAN_DEPRECATED
187#if defined(ZYAN_MSVC)
188# define ZYAN_DLLEXPORT __declspec(dllexport)
189# define ZYAN_DLLIMPORT __declspec(dllimport)
191# define ZYAN_DLLEXPORT
192# define ZYAN_DLLIMPORT
211#if defined(ZYCORE_STATIC_DEFINE)
212# pragma message("ZYCORE_STATIC_DEFINE was renamed to ZYCORE_STATIC_BUILD.")
213# define ZYCORE_STATIC_BUILD
215#if defined(Zycore_EXPORTS)
216# pragma message("Zycore_EXPORTS was renamed to ZYCORE_SHOULD_EXPORT.")
217# define ZYCORE_SHOULD_EXPORT
223#if defined(ZYCORE_STATIC_BUILD)
224# define ZYCORE_EXPORT
226# if defined(ZYCORE_SHOULD_EXPORT)
227# define ZYCORE_EXPORT ZYAN_DLLEXPORT
229# define ZYCORE_EXPORT ZYAN_DLLIMPORT
236#define ZYCORE_NO_EXPORT
242#if defined(ZYAN_CLANG)
243# define ZYAN_NO_SANITIZE(what) __attribute__((no_sanitize(what)))
245# define ZYAN_NO_SANITIZE(what)
248#if defined(ZYAN_MSVC) || defined(ZYAN_BORLAND)
249# define ZYAN_INLINE __inline
251# define ZYAN_INLINE static inline
254#if defined(ZYAN_MSVC)
255# define ZYAN_NOINLINE __declspec(noinline)
256#elif defined(ZYAN_GCC) || defined(ZYAN_CLANG)
257# define ZYAN_NOINLINE __attribute__((noinline))
259# define ZYAN_NOINLINE
269#if defined(ZYAN_NO_LIBC)
270# define ZYAN_ASSERT(condition) (void)(condition)
271#elif defined(ZYAN_WINDOWS) && defined(ZYAN_KERNEL)
273# define ZYAN_ASSERT(condition) NT_ASSERT(condition)
276# define ZYAN_ASSERT(condition) assert(condition)
282#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
283# define ZYAN_STATIC_ASSERT(x) _Static_assert(x, #x)
284#elif (defined(__cplusplus) && __cplusplus >= 201103L) || \
285 (defined(__cplusplus) && defined (_MSC_VER) && (_MSC_VER >= 1600)) || \
286 (defined (_MSC_VER) && (_MSC_VER >= 1800))
287# define ZYAN_STATIC_ASSERT(x) static_assert(x, #x)
289# define ZYAN_STATIC_ASSERT(x) \
290 typedef int ZYAN_MACRO_CONCAT_EXPAND(ZYAN_SASSERT_, __COUNTER__) [(x) ? 1 : -1]
296#if defined(ZYAN_RELEASE)
297# if defined(ZYAN_CLANG)
298# if __has_builtin(__builtin_unreachable)
299# define ZYAN_UNREACHABLE __builtin_unreachable()
301# define ZYAN_UNREACHABLE for(;;)
303# elif defined(ZYAN_GCC) && ((__GNUC__ == 4 && __GNUC_MINOR__ > 4) || __GNUC__ > 4)
304# define ZYAN_UNREACHABLE __builtin_unreachable()
305# elif defined(ZYAN_ICC)
308# define ZYAN_UNREACHABLE __assume(0); (void)abort()
310# define ZYAN_UNREACHABLE __builtin_unreachable()
312# elif defined(ZYAN_MSVC)
313# define ZYAN_UNREACHABLE __assume(0)
315# define ZYAN_UNREACHABLE for(;;)
317#elif defined(ZYAN_NO_LIBC)
318# define ZYAN_UNREACHABLE for(;;)
319#elif defined(ZYAN_WINDOWS) && defined(ZYAN_KERNEL)
320# define ZYAN_UNREACHABLE { __fastfail(0); for(;;){} }
323# define ZYAN_UNREACHABLE { assert(0); abort(); }
339#define ZYAN_UNUSED(x) (void)(x)
344#if defined(ZYAN_GCC) && __GNUC__ >= 7
345# define ZYAN_FALLTHROUGH ; __attribute__((__fallthrough__))
347# define ZYAN_FALLTHROUGH
355#define ZYAN_BITFIELD(x) : x
360#define ZYAN_REQUIRES_LIBC
368#if defined(__RESHARPER__)
369# define ZYAN_PRINTF_ATTR(format_index, first_to_check) \
370 [[gnu::format(printf, format_index, first_to_check)]]
371#elif defined(ZYAN_GCC)
372# define ZYAN_PRINTF_ATTR(format_index, first_to_check) \
373 __attribute__((format(printf, format_index, first_to_check)))
375# define ZYAN_PRINTF_ATTR(format_index, first_to_check)
384#if defined(__RESHARPER__)
385# define ZYAN_WPRINTF_ATTR(format_index, first_to_check) \
386 [[rscpp::format(wprintf, format_index, first_to_check)]]
388# define ZYAN_WPRINTF_ATTR(format_index, first_to_check)
402#define ZYAN_ARRAY_LENGTH(a) (sizeof(a) / sizeof((a)[0]))
416#define ZYAN_MIN(a, b) (((a) < (b)) ? (a) : (b))
426#define ZYAN_MAX(a, b) (((a) > (b)) ? (a) : (b))
435#define ZYAN_ABS(a) (((a) < 0) ? -(a) : (a))
446#define ZYAN_IS_POWER_OF_2(x) (((x) & ((x) - 1)) == 0)
453#define ZYAN_IS_ALIGNED_TO(x, align) (((x) & ((align) - 1)) == 0)
465#define ZYAN_ALIGN_UP(x, align) (((x) + (align) - 1) & ~((align) - 1))
477#define ZYAN_ALIGN_DOWN(x, align) (((x) - 1) & ~((align) - 1))
494#define ZYAN_NEEDS_BIT(n, b) (((unsigned long)(n) >> (b)) > 0)
505#define ZYAN_BITS_TO_REPRESENT(n) \
507 ZYAN_NEEDS_BIT(n, 0) + ZYAN_NEEDS_BIT(n, 1) + \
508 ZYAN_NEEDS_BIT(n, 2) + ZYAN_NEEDS_BIT(n, 3) + \
509 ZYAN_NEEDS_BIT(n, 4) + ZYAN_NEEDS_BIT(n, 5) + \
510 ZYAN_NEEDS_BIT(n, 6) + ZYAN_NEEDS_BIT(n, 7) + \
511 ZYAN_NEEDS_BIT(n, 8) + ZYAN_NEEDS_BIT(n, 9) + \
512 ZYAN_NEEDS_BIT(n, 10) + ZYAN_NEEDS_BIT(n, 11) + \
513 ZYAN_NEEDS_BIT(n, 12) + ZYAN_NEEDS_BIT(n, 13) + \
514 ZYAN_NEEDS_BIT(n, 14) + ZYAN_NEEDS_BIT(n, 15) + \
515 ZYAN_NEEDS_BIT(n, 16) + ZYAN_NEEDS_BIT(n, 17) + \
516 ZYAN_NEEDS_BIT(n, 18) + ZYAN_NEEDS_BIT(n, 19) + \
517 ZYAN_NEEDS_BIT(n, 20) + ZYAN_NEEDS_BIT(n, 21) + \
518 ZYAN_NEEDS_BIT(n, 22) + ZYAN_NEEDS_BIT(n, 23) + \
519 ZYAN_NEEDS_BIT(n, 24) + ZYAN_NEEDS_BIT(n, 25) + \
520 ZYAN_NEEDS_BIT(n, 26) + ZYAN_NEEDS_BIT(n, 27) + \
521 ZYAN_NEEDS_BIT(n, 28) + ZYAN_NEEDS_BIT(n, 29) + \
522 ZYAN_NEEDS_BIT(n, 30) + ZYAN_NEEDS_BIT(n, 31) \