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__)
140# error "Unsupported architecture detected"
147#if defined(ZYAN_MSVC) || defined(ZYAN_BORLAND)
153#elif defined(ZYAN_GNUC) || defined(ZYAN_ICC)
167#if defined(ZYAN_GCC) || defined(ZYAN_CLANG)
168# define ZYAN_DEPRECATED __attribute__((__deprecated__))
169#elif defined(ZYAN_MSVC)
170# define ZYAN_DEPRECATED __declspec(deprecated)
172# define ZYAN_DEPRECATED
179#if defined(ZYAN_MSVC)
180# define ZYAN_DLLEXPORT __declspec(dllexport)
181# define ZYAN_DLLIMPORT __declspec(dllimport)
183# define ZYAN_DLLEXPORT
184# define ZYAN_DLLIMPORT
203#if defined(ZYCORE_STATIC_DEFINE)
204# pragma message("ZYCORE_STATIC_DEFINE was renamed to ZYCORE_STATIC_BUILD.")
205# define ZYCORE_STATIC_BUILD
207#if defined(Zycore_EXPORTS)
208# pragma message("Zycore_EXPORTS was renamed to ZYCORE_SHOULD_EXPORT.")
209# define ZYCORE_SHOULD_EXPORT
215#if defined(ZYCORE_STATIC_BUILD)
216# define ZYCORE_EXPORT
218# if defined(ZYCORE_SHOULD_EXPORT)
219# define ZYCORE_EXPORT ZYAN_DLLEXPORT
221# define ZYCORE_EXPORT ZYAN_DLLIMPORT
228#define ZYCORE_NO_EXPORT
234#if defined(ZYAN_CLANG)
235# define ZYAN_NO_SANITIZE(what) __attribute__((no_sanitize(what)))
237# define ZYAN_NO_SANITIZE(what)
240#if defined(ZYAN_MSVC) || defined(ZYAN_BORLAND)
241# define ZYAN_INLINE __inline
243# define ZYAN_INLINE static inline
246#if defined(ZYAN_MSVC)
247# define ZYAN_NOINLINE __declspec(noinline)
248#elif defined(ZYAN_GCC) || defined(ZYAN_CLANG)
249# define ZYAN_NOINLINE __attribute__((noinline))
251# define ZYAN_NOINLINE
261#if defined(ZYAN_NO_LIBC)
262# define ZYAN_ASSERT(condition) (void)(condition)
263#elif defined(ZYAN_WINDOWS) && defined(ZYAN_KERNEL)
265# define ZYAN_ASSERT(condition) NT_ASSERT(condition)
268# define ZYAN_ASSERT(condition) assert(condition)
274#if __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
275# define ZYAN_STATIC_ASSERT(x) _Static_assert(x, #x)
276#elif (defined(__cplusplus) && __cplusplus >= 201103L) || \
277 (defined(__cplusplus) && defined (_MSC_VER) && (_MSC_VER >= 1600)) || \
278 (defined (_MSC_VER) && (_MSC_VER >= 1800))
279# define ZYAN_STATIC_ASSERT(x) static_assert(x, #x)
281# define ZYAN_STATIC_ASSERT(x) \
282 typedef int ZYAN_MACRO_CONCAT_EXPAND(ZYAN_SASSERT_, __COUNTER__) [(x) ? 1 : -1]
288#if defined(ZYAN_RELEASE)
289# if defined(ZYAN_CLANG)
290# if __has_builtin(__builtin_unreachable)
291# define ZYAN_UNREACHABLE __builtin_unreachable()
293# define ZYAN_UNREACHABLE for(;;)
295# elif defined(ZYAN_GCC) && ((__GNUC__ == 4 && __GNUC_MINOR__ > 4) || __GNUC__ > 4)
296# define ZYAN_UNREACHABLE __builtin_unreachable()
297# elif defined(ZYAN_ICC)
300# define ZYAN_UNREACHABLE __assume(0); (void)abort()
302# define ZYAN_UNREACHABLE __builtin_unreachable()
304# elif defined(ZYAN_MSVC)
305# define ZYAN_UNREACHABLE __assume(0)
307# define ZYAN_UNREACHABLE for(;;)
309#elif defined(ZYAN_NO_LIBC)
310# define ZYAN_UNREACHABLE for(;;)
311#elif defined(ZYAN_WINDOWS) && defined(ZYAN_KERNEL)
312# define ZYAN_UNREACHABLE { __fastfail(0); for(;;){} }
315# define ZYAN_UNREACHABLE { assert(0); abort(); }
331#define ZYAN_UNUSED(x) (void)(x)
336#if defined(ZYAN_GCC) && __GNUC__ >= 7
337# define ZYAN_FALLTHROUGH __attribute__((__fallthrough__))
339# define ZYAN_FALLTHROUGH
347#define ZYAN_BITFIELD(x) : x
352#define ZYAN_REQUIRES_LIBC
360#if defined(__RESHARPER__)
361# define ZYAN_PRINTF_ATTR(format_index, first_to_check) \
362 [[gnu::format(printf, format_index, first_to_check)]]
363#elif defined(ZYAN_GCC)
364# define ZYAN_PRINTF_ATTR(format_index, first_to_check) \
365 __attribute__((format(printf, format_index, first_to_check)))
367# define ZYAN_PRINTF_ATTR(format_index, first_to_check)
376#if defined(__RESHARPER__)
377# define ZYAN_WPRINTF_ATTR(format_index, first_to_check) \
378 [[rscpp::format(wprintf, format_index, first_to_check)]]
380# define ZYAN_WPRINTF_ATTR(format_index, first_to_check)
394#define ZYAN_ARRAY_LENGTH(a) (sizeof(a) / sizeof((a)[0]))
408#define ZYAN_MIN(a, b) (((a) < (b)) ? (a) : (b))
418#define ZYAN_MAX(a, b) (((a) > (b)) ? (a) : (b))
427#define ZYAN_ABS(a) (((a) < 0) ? -(a) : (a))
438#define ZYAN_IS_POWER_OF_2(x) (((x) & ((x) - 1)) == 0)
445#define ZYAN_IS_ALIGNED_TO(x, align) (((x) & ((align) - 1)) == 0)
457#define ZYAN_ALIGN_UP(x, align) (((x) + (align) - 1) & ~((align) - 1))
469#define ZYAN_ALIGN_DOWN(x, align) (((x) - 1) & ~((align) - 1))
486#define ZYAN_NEEDS_BIT(n, b) (((unsigned long)(n) >> (b)) > 0)
497#define ZYAN_BITS_TO_REPRESENT(n) \
499 ZYAN_NEEDS_BIT(n, 0) + ZYAN_NEEDS_BIT(n, 1) + \
500 ZYAN_NEEDS_BIT(n, 2) + ZYAN_NEEDS_BIT(n, 3) + \
501 ZYAN_NEEDS_BIT(n, 4) + ZYAN_NEEDS_BIT(n, 5) + \
502 ZYAN_NEEDS_BIT(n, 6) + ZYAN_NEEDS_BIT(n, 7) + \
503 ZYAN_NEEDS_BIT(n, 8) + ZYAN_NEEDS_BIT(n, 9) + \
504 ZYAN_NEEDS_BIT(n, 10) + ZYAN_NEEDS_BIT(n, 11) + \
505 ZYAN_NEEDS_BIT(n, 12) + ZYAN_NEEDS_BIT(n, 13) + \
506 ZYAN_NEEDS_BIT(n, 14) + ZYAN_NEEDS_BIT(n, 15) + \
507 ZYAN_NEEDS_BIT(n, 16) + ZYAN_NEEDS_BIT(n, 17) + \
508 ZYAN_NEEDS_BIT(n, 18) + ZYAN_NEEDS_BIT(n, 19) + \
509 ZYAN_NEEDS_BIT(n, 20) + ZYAN_NEEDS_BIT(n, 21) + \
510 ZYAN_NEEDS_BIT(n, 22) + ZYAN_NEEDS_BIT(n, 23) + \
511 ZYAN_NEEDS_BIT(n, 24) + ZYAN_NEEDS_BIT(n, 25) + \
512 ZYAN_NEEDS_BIT(n, 26) + ZYAN_NEEDS_BIT(n, 27) + \
513 ZYAN_NEEDS_BIT(n, 28) + ZYAN_NEEDS_BIT(n, 29) + \
514 ZYAN_NEEDS_BIT(n, 30) + ZYAN_NEEDS_BIT(n, 31) \