Go to the documentation of this file.
31#ifndef DOXYGEN_SHOULD_SKIP_THIS
37#define __deprecated __attribute__((deprecated))
38#define __packed __attribute__((packed))
39#define __weak __attribute__((weak))
40#define __noreturn __attribute__((noreturn))
41#define __pure __attribute__((pure))
42#define __aligned(x) __attribute__((aligned(x)))
43#define __printf(a, b) __attribute__((format(printf, a, b)))
44#define __noinline __attribute__((noinline))
45#define __attr_const __attribute__((__const__))
46#define __unused __attribute__((unused))
47#define __maybe_unused __attribute__((unused))
48#define __used __attribute__((__used__))
49#define __must_check __attribute__((warn_unused_result))
50#define __cold __attribute__((__cold__))
51#define __section(x) __attribute__((section(x)))
52#define __data __section(".data")
53#define __bss __section(".bss")
54#define __rodata __section(".rodata")
55#define __rodata_unpaged __section(".rodata.__unpaged")
56#define __early_ta __section(".rodata.early_ta")
57#define __noprof __attribute__((no_instrument_function))
59#define __compiler_bswap64(x) __builtin_bswap64((x))
60#define __compiler_bswap32(x) __builtin_bswap32((x))
61#define __compiler_bswap16(x) __builtin_bswap16((x))
63#define __GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + \
66#if __GCC_VERSION >= 50100 && !defined(__CHECKER__)
67#define __HAVE_BUILTIN_OVERFLOW 1
70#ifdef __HAVE_BUILTIN_OVERFLOW
71#define __compiler_add_overflow(a, b, res) \
72 __builtin_add_overflow((a), (b), (res))
74#define __compiler_sub_overflow(a, b, res) \
75 __builtin_sub_overflow((a), (b), (res))
77#define __compiler_mul_overflow(a, b, res) \
78 __builtin_mul_overflow((a), (b), (res))
84#define __INTOF_HALF_MAX_SIGNED(type) ((type)1 << (sizeof(type)*8-2))
85#define __INTOF_MAX_SIGNED(type) (__INTOF_HALF_MAX_SIGNED(type) - 1 + \
86 __INTOF_HALF_MAX_SIGNED(type))
87#define __INTOF_MIN_SIGNED(type) (-1 - __INTOF_MAX_SIGNED(type))
89#define __INTOF_MIN(type) ((type)-1 < 1?__INTOF_MIN_SIGNED(type):(type)0)
90#define __INTOF_MAX(type) ((type)~__INTOF_MIN(type))
92#define __INTOF_ASSIGN(dest, src) (__extension__({ \
93 typeof(src) __intof_x = (src); \
94 typeof(dest) __intof_y = __intof_x; \
95 (((uintmax_t)__intof_x == (uintmax_t)__intof_y) && \
96 ((__intof_x < 1) == (__intof_y < 1)) ? \
97 (void)((dest) = __intof_y) , 0 : 1); \
100#define __INTOF_ADD(c, a, b) (__extension__({ \
101 typeof(a) __intofa_a = (a); \
102 typeof(b) __intofa_b = (b); \
105 ((__INTOF_MIN(typeof(c)) - __intofa_b <= __intofa_a) ? \
106 __INTOF_ASSIGN((c), __intofa_a + __intofa_b) : 1) : \
107 ((__INTOF_MAX(typeof(c)) - __intofa_b >= __intofa_a) ? \
108 __INTOF_ASSIGN((c), __intofa_a + __intofa_b) : 1); \
111#define __INTOF_SUB(c, a, b) (__extension__({ \
112 typeof(a) __intofs_a = a; \
113 typeof(b) __intofs_b = b; \
116 ((__INTOF_MAX(typeof(c)) + __intofs_b >= __intofs_a) ? \
117 __INTOF_ASSIGN((c), __intofs_a - __intofs_b) : 1) : \
118 ((__INTOF_MIN(typeof(c)) + __intofs_b <= __intofs_a) ? \
119 __INTOF_ASSIGN((c), __intofs_a - __intofs_b) : 1); \
155#define __intof_mul_negate ((__intof_oa < 1) != (__intof_ob < 1))
156#define __intof_mul_hshift (sizeof(uintmax_t) * 8 / 2)
157#define __intof_mul_hmask (UINTMAX_MAX >> __intof_mul_hshift)
158#define __intof_mul_a0 ((uintmax_t)(__intof_a) >> __intof_mul_hshift)
159#define __intof_mul_b0 ((uintmax_t)(__intof_b) >> __intof_mul_hshift)
160#define __intof_mul_a1 ((uintmax_t)(__intof_a) & __intof_mul_hmask)
161#define __intof_mul_b1 ((uintmax_t)(__intof_b) & __intof_mul_hmask)
162#define __intof_mul_t (__intof_mul_a1 * __intof_mul_b0 + \
163 __intof_mul_a0 * __intof_mul_b1)
165#define __INTOF_MUL(c, a, b) (__extension__({ \
166 typeof(a) __intof_oa = (a); \
167 typeof(a) __intof_a = __intof_oa < 1 ? -__intof_oa : __intof_oa; \
168 typeof(b) __intof_ob = (b); \
169 typeof(b) __intof_b = __intof_ob < 1 ? -__intof_ob : __intof_ob; \
170 typeof(c) __intof_c; \
172 __intof_oa == 0 || __intof_ob == 0 || \
173 __intof_oa == 1 || __intof_ob == 1 ? \
174 __INTOF_ASSIGN((c), __intof_oa * __intof_ob) : \
175 (__intof_mul_a0 && __intof_mul_b0) || \
176 __intof_mul_t > __intof_mul_hmask ? 1 : \
177 __INTOF_ADD((__intof_c), __intof_mul_t << __intof_mul_hshift, \
178 __intof_mul_a1 * __intof_mul_b1) ? 1 : \
179 __intof_mul_negate ? __INTOF_ASSIGN((c), -__intof_c) : \
180 __INTOF_ASSIGN((c), __intof_c); \
183#define __compiler_add_overflow(a, b, res) __INTOF_ADD(*(res), (a), (b))
184#define __compiler_sub_overflow(a, b, res) __INTOF_SUB(*(res), (a), (b))
185#define __compiler_mul_overflow(a, b, res) __INTOF_MUL(*(res), (a), (b))
189#define __compiler_compare_and_swap(p, oval, nval) \
190 __atomic_compare_exchange_n((p), (oval), (nval), true, \
191 __ATOMIC_ACQUIRE, __ATOMIC_RELAXED) \
193#define __compiler_atomic_load(p) __atomic_load_n((p), __ATOMIC_RELAXED)
194#define __compiler_atomic_store(p, val) \
195 __atomic_store_n((p), (val), __ATOMIC_RELAXED)