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(__unix) || defined(__unix__)
109#elif defined(__posix)
112# define ZYAN_UNKNOWN_PLATFORM
119#if (defined(ZYAN_WINDOWS) && defined(_KERNEL_MODE)) || \
120 (defined(ZYAN_APPLE) && defined(KERNEL)) || \
121 (defined(ZYAN_LINUX) && defined(__KERNEL__)) || \
122 (defined(__FreeBSD_kernel__))
132#if defined(_M_AMD64) || defined(__x86_64__)
134#elif defined(_M_IX86) || defined(__i386__)
136#elif defined(_M_ARM64) || defined(__aarch64__)
138#elif defined(_M_ARM) || defined(_M_ARMT) || defined(__arm__) || defined(__thumb__)
140#elif defined(__EMSCRIPTEN__) || defined(__wasm__) || defined(__WASM__)
142#elif defined(__loongarch__)
143# define ZYAN_LOONGARCH
144#elif defined(__powerpc64__)
146#elif defined(__powerpc__)
148#elif defined(__riscv) && __riscv_xlen == 64
151# error "Unsupported architecture detected"
158#if defined(ZYAN_MSVC) || defined(ZYAN_BORLAND)
164#elif defined(ZYAN_GNUC) || defined(ZYAN_ICC)
178#if defined(ZYAN_GCC) || defined(ZYAN_CLANG)
179# define ZYAN_DEPRECATED __attribute__((__deprecated__))
180#elif defined(ZYAN_MSVC)
181# define ZYAN_DEPRECATED __declspec(deprecated)
183# define ZYAN_DEPRECATED
190#if defined(ZYAN_MSVC)
191# define ZYAN_DLLEXPORT __declspec(dllexport)
192# define ZYAN_DLLIMPORT __declspec(dllimport)
194# define ZYAN_DLLEXPORT
195# define ZYAN_DLLIMPORT
214#if defined(ZYCORE_STATIC_DEFINE)
215# pragma message("ZYCORE_STATIC_DEFINE was renamed to ZYCORE_STATIC_BUILD.")
216# define ZYCORE_STATIC_BUILD
218#if defined(Zycore_EXPORTS)
219# pragma message("Zycore_EXPORTS was renamed to ZYCORE_SHOULD_EXPORT.")
220# define ZYCORE_SHOULD_EXPORT
226#if defined(ZYCORE_STATIC_BUILD)
227# define ZYCORE_EXPORT
229# if defined(ZYCORE_SHOULD_EXPORT)
230# define ZYCORE_EXPORT ZYAN_DLLEXPORT
232# define ZYCORE_EXPORT ZYAN_DLLIMPORT
239#define ZYCORE_NO_EXPORT
245#if defined(ZYAN_CLANG)
246# define ZYAN_NO_SANITIZE(what) __attribute__((no_sanitize(what)))
248# define ZYAN_NO_SANITIZE(what)
251#if defined(ZYAN_MSVC) || defined(ZYAN_BORLAND)
252# define ZYAN_INLINE __inline
254# define ZYAN_INLINE static inline
257#if defined(ZYAN_MSVC)
258# define ZYAN_NOINLINE __declspec(noinline)
259#elif defined(ZYAN_GCC) || defined(ZYAN_CLANG)
260# define ZYAN_NOINLINE __attribute__((noinline))
262# define ZYAN_NOINLINE
272#if defined(ZYAN_NO_LIBC)
273# define ZYAN_ASSERT(condition) (void)(condition)
274#elif defined(ZYAN_WINDOWS) && defined(ZYAN_KERNEL)
276# define ZYAN_ASSERT(condition) NT_ASSERT(condition)
279# define ZYAN_ASSERT(condition) assert(condition)
285#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
286# define ZYAN_STATIC_ASSERT(x) _Static_assert(x, #x)
287#elif (defined(__cplusplus) && __cplusplus >= 201103L) || \
288 (defined(__cplusplus) && defined (_MSC_VER) && (_MSC_VER >= 1600)) || \
289 (defined (_MSC_VER) && (_MSC_VER >= 1800))
290# define ZYAN_STATIC_ASSERT(x) static_assert(x, #x)
292# define ZYAN_STATIC_ASSERT(x) \
293 typedef int ZYAN_MACRO_CONCAT_EXPAND(ZYAN_SASSERT_, __COUNTER__) [(x) ? 1 : -1]
299#if defined(ZYAN_RELEASE)
300# if defined(ZYAN_CLANG)
301# if __has_builtin(__builtin_unreachable)
302# define ZYAN_UNREACHABLE __builtin_unreachable()
304# define ZYAN_UNREACHABLE for(;;)
306# elif defined(ZYAN_GCC) && ((__GNUC__ == 4 && __GNUC_MINOR__ > 4) || __GNUC__ > 4)
307# define ZYAN_UNREACHABLE __builtin_unreachable()
308# elif defined(ZYAN_ICC)
311# define ZYAN_UNREACHABLE __assume(0); (void)abort()
313# define ZYAN_UNREACHABLE __builtin_unreachable()
315# elif defined(ZYAN_MSVC)
316# define ZYAN_UNREACHABLE __assume(0)
318# define ZYAN_UNREACHABLE for(;;)
320#elif defined(ZYAN_NO_LIBC)
321# define ZYAN_UNREACHABLE for(;;)
322#elif defined(ZYAN_WINDOWS) && defined(ZYAN_KERNEL)
323# define ZYAN_UNREACHABLE { __fastfail(0); for(;;){} }
326# define ZYAN_UNREACHABLE { assert(0); abort(); }
342#define ZYAN_UNUSED(x) (void)(x)
347#if defined(ZYAN_GCC) && __GNUC__ >= 7
348# define ZYAN_FALLTHROUGH ; __attribute__((__fallthrough__))
350# define ZYAN_FALLTHROUGH
358#define ZYAN_BITFIELD(x) : x
363#define ZYAN_REQUIRES_LIBC
371#if defined(__RESHARPER__)
372# define ZYAN_PRINTF_ATTR(format_index, first_to_check) \
373 [[gnu::format(printf, format_index, first_to_check)]]
374#elif defined(ZYAN_GCC)
375# define ZYAN_PRINTF_ATTR(format_index, first_to_check) \
376 __attribute__((format(printf, format_index, first_to_check)))
378# define ZYAN_PRINTF_ATTR(format_index, first_to_check)
387#if defined(__RESHARPER__)
388# define ZYAN_WPRINTF_ATTR(format_index, first_to_check) \
389 [[rscpp::format(wprintf, format_index, first_to_check)]]
391# define ZYAN_WPRINTF_ATTR(format_index, first_to_check)
405#define ZYAN_ARRAY_LENGTH(a) (sizeof(a) / sizeof((a)[0]))
419#define ZYAN_MIN(a, b) (((a) < (b)) ? (a) : (b))
429#define ZYAN_MAX(a, b) (((a) > (b)) ? (a) : (b))
438#define ZYAN_ABS(a) (((a) < 0) ? -(a) : (a))
449#define ZYAN_IS_POWER_OF_2(x) (((x) & ((x) - 1)) == 0)
456#define ZYAN_IS_ALIGNED_TO(x, align) (((x) & ((align) - 1)) == 0)
468#define ZYAN_ALIGN_UP(x, align) (((x) + (align) - 1) & ~((align) - 1))
480#define ZYAN_ALIGN_DOWN(x, align) (((x) - 1) & ~((align) - 1))
489#if defined(ZYAN_LINUX) && defined(ZYAN_KERNEL)
490# include <asm/div64.h>
491# define ZYAN_DIV64(n, divisor) do_div(n, divisor)
493# define ZYAN_DIV64(n, divisor) (n /= divisor)
511#define ZYAN_NEEDS_BIT(n, b) (((unsigned long)(n) >> (b)) > 0)
522#define ZYAN_BITS_TO_REPRESENT(n) \
524 ZYAN_NEEDS_BIT(n, 0) + ZYAN_NEEDS_BIT(n, 1) + \
525 ZYAN_NEEDS_BIT(n, 2) + ZYAN_NEEDS_BIT(n, 3) + \
526 ZYAN_NEEDS_BIT(n, 4) + ZYAN_NEEDS_BIT(n, 5) + \
527 ZYAN_NEEDS_BIT(n, 6) + ZYAN_NEEDS_BIT(n, 7) + \
528 ZYAN_NEEDS_BIT(n, 8) + ZYAN_NEEDS_BIT(n, 9) + \
529 ZYAN_NEEDS_BIT(n, 10) + ZYAN_NEEDS_BIT(n, 11) + \
530 ZYAN_NEEDS_BIT(n, 12) + ZYAN_NEEDS_BIT(n, 13) + \
531 ZYAN_NEEDS_BIT(n, 14) + ZYAN_NEEDS_BIT(n, 15) + \
532 ZYAN_NEEDS_BIT(n, 16) + ZYAN_NEEDS_BIT(n, 17) + \
533 ZYAN_NEEDS_BIT(n, 18) + ZYAN_NEEDS_BIT(n, 19) + \
534 ZYAN_NEEDS_BIT(n, 20) + ZYAN_NEEDS_BIT(n, 21) + \
535 ZYAN_NEEDS_BIT(n, 22) + ZYAN_NEEDS_BIT(n, 23) + \
536 ZYAN_NEEDS_BIT(n, 24) + ZYAN_NEEDS_BIT(n, 25) + \
537 ZYAN_NEEDS_BIT(n, 26) + ZYAN_NEEDS_BIT(n, 27) + \
538 ZYAN_NEEDS_BIT(n, 28) + ZYAN_NEEDS_BIT(n, 29) + \
539 ZYAN_NEEDS_BIT(n, 30) + ZYAN_NEEDS_BIT(n, 31) \