 |
mTower
|
41 #define __deprecated __attribute__((deprecated)) 43 #define __packed __attribute__((packed)) 45 #define __weak __attribute__((weak)) 47 #define __noreturn __attribute__((noreturn)) 49 #define __pure __attribute__((pure)) 50 #define __aligned(x) __attribute__((aligned(x))) 51 #define __printf(a, b) __attribute__((format(printf, a, b))) 52 #define __noinline __attribute__((noinline)) 53 #define __attr_const __attribute__((__const__)) 55 #define __unused __attribute__((unused)) 57 #define __maybe_unused __attribute__((unused)) 59 #define __used __attribute__((__used__)) 61 #define __must_check __attribute__((warn_unused_result)) 62 #define __cold __attribute__((__cold__)) 63 #define __section(x) __attribute__((section(x))) 64 #define __data __section(".data") 65 #define __bss __section(".bss") 66 #define __rodata __section(".rodata") 67 #define __rodata_unpaged __section(".rodata.__unpaged") 68 #define __early_ta __section(".rodata.early_ta") 69 #define __noprof __attribute__((no_instrument_function)) 71 #define __compiler_bswap64(x) __builtin_bswap64((x)) 72 #define __compiler_bswap32(x) __builtin_bswap32((x)) 73 #define __compiler_bswap16(x) __builtin_bswap16((x)) 75 #define __GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + \ 78 #if __GCC_VERSION >= 50100 && !defined(__CHECKER__) 79 #define __HAVE_BUILTIN_OVERFLOW 1 82 #ifdef __HAVE_BUILTIN_OVERFLOW 83 #define __compiler_add_overflow(a, b, res) \ 84 __builtin_add_overflow((a), (b), (res)) 86 #define __compiler_sub_overflow(a, b, res) \ 87 __builtin_sub_overflow((a), (b), (res)) 89 #define __compiler_mul_overflow(a, b, res) \ 90 __builtin_mul_overflow((a), (b), (res)) 96 #define __INTOF_HALF_MAX_SIGNED(type) ((type)1 << (sizeof(type)*8-2)) 97 #define __INTOF_MAX_SIGNED(type) (__INTOF_HALF_MAX_SIGNED(type) - 1 + \ 98 __INTOF_HALF_MAX_SIGNED(type)) 99 #define __INTOF_MIN_SIGNED(type) (-1 - __INTOF_MAX_SIGNED(type)) 101 #define __INTOF_MIN(type) ((type)-1 < 1?__INTOF_MIN_SIGNED(type):(type)0) 102 #define __INTOF_MAX(type) ((type)~__INTOF_MIN(type)) 104 #define __INTOF_ASSIGN(dest, src) (__extension__({ \ 105 typeof(src) __intof_x = (src); \ 106 typeof(dest) __intof_y = __intof_x; \ 107 (((uintmax_t)__intof_x == (uintmax_t)__intof_y) && \ 108 ((__intof_x < 1) == (__intof_y < 1)) ? \ 109 (void)((dest) = __intof_y) , 0 : 1); \ 112 #define __INTOF_ADD(c, a, b) (__extension__({ \ 113 typeof(a) __intofa_a = (a); \ 114 typeof(b) __intofa_b = (b); \ 117 ((__INTOF_MIN(typeof(c)) - __intofa_b <= __intofa_a) ? \ 118 __INTOF_ASSIGN((c), __intofa_a + __intofa_b) : 1) : \ 119 ((__INTOF_MAX(typeof(c)) - __intofa_b >= __intofa_a) ? \ 120 __INTOF_ASSIGN((c), __intofa_a + __intofa_b) : 1); \ 123 #define __INTOF_SUB(c, a, b) (__extension__({ \ 124 typeof(a) __intofs_a = a; \ 125 typeof(b) __intofs_b = b; \ 128 ((__INTOF_MAX(typeof(c)) + __intofs_b >= __intofs_a) ? \ 129 __INTOF_ASSIGN((c), __intofs_a - __intofs_b) : 1) : \ 130 ((__INTOF_MIN(typeof(c)) + __intofs_b <= __intofs_a) ? \ 131 __INTOF_ASSIGN((c), __intofs_a - __intofs_b) : 1); \ 167 #define __intof_mul_negate ((__intof_oa < 1) != (__intof_ob < 1)) 168 #define __intof_mul_hshift (sizeof(uintmax_t) * 8 / 2) 169 #define __intof_mul_hmask (UINTMAX_MAX >> __intof_mul_hshift) 170 #define __intof_mul_a0 ((uintmax_t)(__intof_a) >> __intof_mul_hshift) 171 #define __intof_mul_b0 ((uintmax_t)(__intof_b) >> __intof_mul_hshift) 172 #define __intof_mul_a1 ((uintmax_t)(__intof_a) & __intof_mul_hmask) 173 #define __intof_mul_b1 ((uintmax_t)(__intof_b) & __intof_mul_hmask) 174 #define __intof_mul_t (__intof_mul_a1 * __intof_mul_b0 + \ 175 __intof_mul_a0 * __intof_mul_b1) 177 #define __INTOF_MUL(c, a, b) (__extension__({ \ 178 typeof(a) __intof_oa = (a); \ 179 typeof(a) __intof_a = __intof_oa < 1 ? -__intof_oa : __intof_oa; \ 180 typeof(b) __intof_ob = (b); \ 181 typeof(b) __intof_b = __intof_ob < 1 ? -__intof_ob : __intof_ob; \ 182 typeof(c) __intof_c; \ 184 __intof_oa == 0 || __intof_ob == 0 || \ 185 __intof_oa == 1 || __intof_ob == 1 ? \ 186 __INTOF_ASSIGN((c), __intof_oa * __intof_ob) : \ 187 (__intof_mul_a0 && __intof_mul_b0) || \ 188 __intof_mul_t > __intof_mul_hmask ? 1 : \ 189 __INTOF_ADD((__intof_c), __intof_mul_t << __intof_mul_hshift, \ 190 __intof_mul_a1 * __intof_mul_b1) ? 1 : \ 191 __intof_mul_negate ? __INTOF_ASSIGN((c), -__intof_c) : \ 192 __INTOF_ASSIGN((c), __intof_c); \ 195 #define __compiler_add_overflow(a, b, res) __INTOF_ADD(*(res), (a), (b)) 196 #define __compiler_sub_overflow(a, b, res) __INTOF_SUB(*(res), (a), (b)) 197 #define __compiler_mul_overflow(a, b, res) __INTOF_MUL(*(res), (a), (b)) 201 #define __compiler_compare_and_swap(p, oval, nval) \ 202 __atomic_compare_exchange_n((p), (oval), (nval), true, \ 203 __ATOMIC_ACQUIRE, __ATOMIC_RELAXED) \ 205 #define __compiler_atomic_load(p) __atomic_load_n((p), __ATOMIC_RELAXED) 206 #define __compiler_atomic_store(p, val) \ 207 __atomic_store_n((p), (val), __ATOMIC_RELAXED)