18#define RT_BITS_PER_LONG 64
20#define RT_BITS_PER_LONG 32
22#define RT_BITS_PER_LONG_LONG 64
24#define RT_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
26#define RT_DIV_ROUND_CLOSEST(x, divisor) \
29 typeof(divisor) __d = divisor; \
30 (((typeof(x))-1) > 0 || \
31 ((typeof(divisor))-1) > 0 || \
32 (((__x) > 0) == ((__d) > 0))) ? \
33 (((__x) + ((__d) / 2)) / (__d)) : \
34 (((__x) - ((__d) / 2)) / (__d)); \
37#define __KEY_PLACEHOLDER_1 0,
38#define ____KEY_ENABLED(__ignored, val, ...) val
39#define ___KEY_ENABLED(arg1_or_junk) ____KEY_ENABLED(arg1_or_junk 1, 0)
40#define __KEY_ENABLED(value) ___KEY_ENABLED(__KEY_PLACEHOLDER_##value)
41#define RT_KEY_ENABLED(key) __KEY_ENABLED(key)
43#define RT_FIELD_PREP(mask, val) (((rt_uint64_t)(val) << (__rt_ffsl((mask)) - 1)) & (mask))
44#define RT_FIELD_GET(mask, val) (((val) & (mask)) >> (__rt_ffsl((mask)) - 1))
46#define RT_BIT(n) (1UL << (n))
47#define RT_BIT_ULL(n) (1ULL << (n))
48#define RT_BIT_MASK(nr) (1UL << ((nr) % RT_BITS_PER_LONG))
49#define RT_BIT_WORD(nr) ((nr) / RT_BITS_PER_LONG)
51#define RT_BITS_PER_BYTE 8
52#define RT_BITS_PER_TYPE(type) (sizeof(type) * RT_BITS_PER_BYTE)
53#define RT_BITS_TO_BYTES(nr) RT_DIV_ROUND_UP(nr, RT_BITS_PER_TYPE(char))
54#define RT_BITS_TO_LONGS(nr) RT_DIV_ROUND_UP(nr, RT_BITS_PER_TYPE(long))
56#define RT_GENMASK(h, l) (((~0UL) << (l)) & (~0UL >> (RT_BITS_PER_LONG - 1 - (h))))
57#define RT_GENMASK_ULL(h, l) (((~0ULL) << (l)) & (~0ULL >> (RT_BITS_PER_LONG_LONG - 1 - (h))))
59#define RT_ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
61#define rt_offsetof(s, field) ((rt_size_t)&((s *)0)->field)
63#define rt_err_ptr(err) ((void *)(rt_base_t)(err))
64#define rt_ptr_err(ptr) ((rt_err_t)(rt_base_t)(ptr))
65#define rt_is_err_value(ptr) ((rt_ubase_t)(void *)(ptr) >= (rt_ubase_t)-4095)
66#define rt_is_err(ptr) rt_is_err_value(ptr)
67#define rt_is_err_or_null(ptr) (!(ptr) || rt_is_err_value((rt_ubase_t)(ptr)))
69#define rt_upper_32_bits(n) ((rt_uint32_t)(((n) >> 16) >> 16))
70#define rt_lower_32_bits(n) ((rt_uint32_t)((n) & 0xffffffff))
71#define rt_upper_16_bits(n) ((rt_uint16_t)((n) >> 16))
72#define rt_lower_16_bits(n) ((rt_uint16_t)((n) & 0xffff))
78 (void) (&_x == &_y); \
86 (void) (&_x == &_y); \
90#define rt_min_t(type, x, y) \
97#define rt_max_t(type, x, y) \
104#define rt_clamp(val, lo, hi) rt_min((typeof(val))rt_max(val, lo), hi)
106#define rt_do_div(n, base) \
108 rt_uint32_t _base = (base), _rem; \
109 _rem = ((rt_uint64_t)(n)) % _base; \
110 (n) = ((rt_uint64_t)(n)) / _base; \
111 if (_rem > _base / 2) \
119 if (sizeof(x) == sizeof(long)) \
122 ret = (__x < 0) ? -__x : __x; \
127 ret = (__x < 0) ? -__x : __x; \
137 while ((1UL << l) < v)
rt_inline int rt_ilog2(rt_ubase_t v)