| 1 | /* @title: Compiler Functions */ |
| 2 | #pragma once |
| 3 | |
| 4 | #define __noinline __attribute__((noinline)) |
| 5 | |
| 6 | #define __always_inline __attribute__((always_inline)) |
| 7 | |
| 8 | #define __noreturn __attribute__((noreturn)) |
| 9 | |
| 10 | #define __unused __attribute__((unused)) |
| 11 | |
| 12 | #define __warn_unused_result __attribute__((warn_unused_result)) |
| 13 | |
| 14 | #define __packed __attribute__((__packed__)) |
| 15 | |
| 16 | #define __aligned(x) __attribute__((aligned(x))) |
| 17 | |
| 18 | #define __cache_aligned __attribute__((aligned(64))) |
| 19 | |
| 20 | #define __used __attribute__((used)) |
| 21 | |
| 22 | #define __section(x) __attribute__((section(x))) |
| 23 | |
| 24 | #define __hidden __attribute__((visibility("hidden"))) |
| 25 | #define __export __attribute__((visibility("default"))) |
| 26 | |
| 27 | #define likely(x) __builtin_expect(!!(x), 1) |
| 28 | #define unlikely(x) __builtin_expect(!!(x), 0) |
| 29 | |
| 30 | #define __no_sanitize_address __attribute__((no_sanitize("address"))) |
| 31 | |
| 32 | #define __deprecated __attribute__((deprecated)) |
| 33 | #define __deprecated_msg(msg) __attribute__((deprecated(msg))) |
| 34 | |
| 35 | #define __pure __attribute__((pure)) |
| 36 | |
| 37 | #define __constfn __attribute__((const)) |
| 38 | |
| 39 | #define __noclone __attribute__((noclone)) |
| 40 | |
| 41 | #define __malloc_like __attribute__((malloc)) |
| 42 | |
| 43 | #define __nullable __attribute__((nullable)) |
| 44 | |
| 45 | #define __naked __attribute__((naked)) |
| 46 | |
| 47 | #define __returns_nonnull __attribute__((returns_nonnull)) |
| 48 | |
| 49 | #define __returns_twice __attribute__((returns_twice)) |
| 50 | |
| 51 | #define __may_alias __attribute__((__may_alias__)) |
| 52 | |
| 53 | #define __weak __attribute__((weak)) |
| 54 | |
| 55 | #define __weakref(sym) __attribute__((weakref(#sym))) |
| 56 | |
| 57 | #define __alias(sym) __attribute__((alias(#sym))) |
| 58 | |
| 59 | #define __no_sanitize_undefined __attribute__((no_sanitize("undefined"))) |
| 60 | |
| 61 | #define __no_sanitize_thread __attribute__((no_sanitize("thread"))) |
| 62 | |
| 63 | #define __no_sanitize_memory __attribute__((no_sanitize("memory"))) |
| 64 | |
| 65 | #define __no_sanitize_coverage __attribute__((no_sanitize("coverage"))) |
| 66 | |
| 67 | #define __printf_like(fmt_idx, arg_idx) \ |
| 68 | __attribute__((format(printf, fmt_idx, arg_idx))) |
| 69 | |
| 70 | #define __constructor(prio) __attribute__((constructor(prio))) |
| 71 | #define __destructor(prio) __attribute__((destructor(prio))) |
| 72 | |
| 73 | #define __fallthrough __attribute__((fallthrough)) |
| 74 | |
| 75 | #if defined(__GNUC__) |
| 76 | #define __restrict __restrict__ |
| 77 | #else |
| 78 | #define __restrict |
| 79 | #endif |
| 80 | |
| 81 | #define static_assert_struct_size_eq(__struct, __want) \ |
| 82 | _Static_assert(sizeof(struct __struct) == __want, \ |
| 83 | "size of struct" #__struct \ |
| 84 | " does not match expected size " #__want) |
| 85 | |
| 86 | #define static_assert_1(cond) _Static_assert(cond, #cond) |
| 87 | #define static_assert_2(cond, msg) _Static_assert(cond, msg) |
| 88 | #define static_assert(...) \ |
| 89 | _DISPATCH(static_assert, PP_NARG(__VA_ARGS__))(__VA_ARGS__) |
| 90 | |
| 91 | #define smp_mb() atomic_thread_fence(memory_order_seq_cst) |
| 92 | #define smp_rmb() atomic_thread_fence(memory_order_acquire) |
| 93 | #define smp_wmb() atomic_thread_fence(memory_order_release) |
| 94 | |
| 95 | #define _DISPATCH_(name, n) name##_##n |
| 96 | #define _DISPATCH(name, n) _DISPATCH_(name, n) |
| 97 | |
| 98 | #define PP_ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, \ |
| 99 | _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, \ |
| 100 | _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, \ |
| 101 | _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \ |
| 102 | _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, \ |
| 103 | _63, _64, N, ...) \ |
| 104 | N |
| 105 | |
| 106 | #define PP_RSEQ_N() \ |
| 107 | 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, \ |
| 108 | 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, \ |
| 109 | 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, \ |
| 110 | 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 |
| 111 | |
| 112 | #define PP_NARG_HELPER(...) PP_ARG_N(__VA_ARGS__) |
| 113 | #define PP_NARG(...) PP_NARG_HELPER(_, ##__VA_ARGS__, PP_RSEQ_N()) |
| 114 | |
| 115 | #define CONCAT_(a, b) a##b |
| 116 | #define CONCAT(a, b) CONCAT_(a, b) |
| 117 | |