25 #include <rte_config.h> 28 #define typeof __typeof__ 36 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L 37 #define RTE_STD_C11 __extension__ 43 #ifdef RTE_TOOLCHAIN_GCC 44 #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + \ 48 #ifdef RTE_ARCH_STRICT_ALIGN 50 typedef uint32_t unaligned_uint32_t __attribute__ ((aligned(1)));
51 typedef uint16_t unaligned_uint16_t __attribute__ ((aligned(1)));
54 typedef uint32_t unaligned_uint32_t;
55 typedef uint16_t unaligned_uint16_t;
61 #define __rte_aligned(a) __attribute__((__aligned__(a))) 66 #define __rte_packed __attribute__((__packed__)) 69 #define __rte_deprecated __attribute__((__deprecated__)) 74 #define __rte_weak __attribute__((__weak__)) 81 #define __rte_unused __attribute__((__unused__)) 87 #define RTE_SET_USED(x) (void)(x) 89 #define RTE_PRIORITY_LOG 101 90 #define RTE_PRIORITY_BUS 110 91 #define RTE_PRIORITY_CLASS 120 92 #define RTE_PRIORITY_LAST 65535 94 #define RTE_PRIO(prio) \ 106 #if defined(__x86_64__) || defined(__i386__) 107 #define RTE_INIT_PRIO(func, prio) \ 109 __attribute__((constructor(RTE_PRIO(prio)), used)) \ 110 __attribute__((target ("sse2"))) \ 111 __attribute__((target ("no-sse3"))) \ 112 __attribute__((target ("no-sse4"))) \ 115 #define RTE_INIT_PRIO(func, prio) \ 117 __attribute__((constructor(RTE_PRIO(prio)), used)) \ 130 #define RTE_INIT(func) \ 131 RTE_INIT_PRIO(func, LAST) 142 #define RTE_FINI_PRIO(func, prio) \ 143 static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) 153 #define RTE_FINI(func) \ 154 RTE_FINI_PRIO(func, LAST) 159 #define __rte_always_inline inline __attribute__((always_inline)) 164 #define __rte_noinline __attribute__((noinline)) 171 #define RTE_PTR_ADD(ptr, x) ((void*)((uintptr_t)(ptr) + (x))) 176 #define RTE_PTR_SUB(ptr, x) ((void*)((uintptr_t)ptr - (x))) 183 #define RTE_PTR_DIFF(ptr1, ptr2) ((uintptr_t)(ptr1) - (uintptr_t)(ptr2)) 188 #define RTE_CAST_FIELD(var, field, type) \ 189 (*(type *)((uintptr_t)(var) + offsetof(typeof(*(var)), field))) 200 #define RTE_PTR_ALIGN_FLOOR(ptr, align) \ 201 ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)ptr, align)) 209 #define RTE_ALIGN_FLOOR(val, align) \ 210 (typeof(val))((val) & (~((typeof(val))((align) - 1)))) 218 #define RTE_PTR_ALIGN_CEIL(ptr, align) \ 219 RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, (align) - 1), align) 227 #define RTE_ALIGN_CEIL(val, align) \ 228 RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align) 237 #define RTE_PTR_ALIGN(ptr, align) RTE_PTR_ALIGN_CEIL(ptr, align) 246 #define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align) 253 #define RTE_ALIGN_MUL_CEIL(v, mul) \ 254 (((v + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul)) 261 #define RTE_ALIGN_MUL_FLOOR(v, mul) \ 262 ((v / ((typeof(v))(mul))) * (typeof(v))(mul)) 286 #define RTE_BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) 298 static inline uint32_t
320 static inline uint64_t
338 #define RTE_IS_POWER_OF_2(n) ((n) && !(((n) - 1) & (n))) 349 return n && !(n & (n - 1));
361 static inline uint32_t
379 static inline uint32_t
396 static inline uint64_t
414 static inline uint64_t
427 #define RTE_MIN(a, b) \ 429 typeof (a) _a = (a); \ 430 typeof (b) _b = (b); \ 437 #define RTE_MAX(a, b) \ 439 typeof (a) _a = (a); \ 440 typeof (b) _b = (b); \ 457 static inline uint32_t
460 return (uint32_t)__builtin_ctz(v);
471 static inline uint32_t
495 return (x == 0) ? 0 : 32 - __builtin_clz(x);
518 *pos = __builtin_ctzll(v);
524 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER) 542 #define container_of(ptr, type, member) __extension__ ({ \ 543 const typeof(((type *)0)->member) *_ptr = (ptr); \ 544 __attribute__((unused)) type *_target_ptr = \ 546 (type *)(((uintptr_t)_ptr) - offsetof(type, member)); \ 550 #define _RTE_STR(x) #x 552 #define RTE_STR(x) _RTE_STR(x) 559 #define RTE_FMT(fmt, ...) fmt "%.0s", __VA_ARGS__ "" 560 #define RTE_FMT_HEAD(fmt, ...) fmt 561 #define RTE_FMT_TAIL(fmt, ...) __VA_ARGS__ 564 #define RTE_LEN2MASK(ln, tp) \ 565 ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln)))) 568 #define RTE_DIM(a) (sizeof (a) / sizeof ((a)[0])) 584 static inline uint64_t
588 unsigned long long size;
590 while (isspace((
int)*str))
596 size = strtoull(str, &endptr, 0);
604 case 'G':
case 'g': size *= 1024;
605 case 'M':
case 'm': size *= 1024;
606 case 'K':
case 'k': size *= 1024;
627 rte_exit(
int exit_code,
const char *format, ...)
628 __attribute__((noreturn))
629 __attribute__((format(printf, 2, 3)));
static int rte_is_aligned(void *ptr, unsigned align)
static int rte_fls_u32(uint32_t x)
static uint64_t rte_combine64ms1b(register uint64_t v)
static uint64_t rte_align64pow2(uint64_t v)
static uint32_t rte_log2_u32(uint32_t v)
static uint32_t rte_bsf32(uint32_t v)
static uint64_t rte_align64prevpow2(uint64_t v)
static uint32_t rte_align32pow2(uint32_t x)
static int rte_bsf64_safe(uint64_t v, uint32_t *pos)
uint64_t unaligned_uint64_t
#define RTE_PTR_ALIGN(ptr, align)
static int rte_is_power_of_2(uint32_t n)
void rte_exit(int exit_code, const char *format,...)
static uint32_t rte_align32prevpow2(uint32_t x)
static uint64_t rte_str_to_size(const char *str)
static uint32_t rte_combine32ms1b(register uint32_t x)