34 #ifndef _RTE_COMMON_H_
35 #define _RTE_COMMON_H_
55 #define typeof __typeof__
63 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L
64 #define RTE_STD_C11 __extension__
69 #ifdef RTE_ARCH_STRICT_ALIGN
70 typedef uint64_t unaligned_uint64_t __attribute__ ((aligned(1)));
71 typedef uint32_t unaligned_uint32_t __attribute__ ((aligned(1)));
72 typedef uint16_t unaligned_uint16_t __attribute__ ((aligned(1)));
74 typedef uint64_t unaligned_uint64_t;
75 typedef uint32_t unaligned_uint32_t;
76 typedef uint16_t unaligned_uint16_t;
82 #define __rte_aligned(a) __attribute__((__aligned__(a)))
87 #define __rte_packed __attribute__((__packed__))
90 #define __rte_deprecated __attribute__((__deprecated__))
97 #define __rte_unused __attribute__((__unused__))
103 #define RTE_SET_USED(x) (void)(x)
110 #define RTE_PTR_ADD(ptr, x) ((void*)((uintptr_t)(ptr) + (x)))
115 #define RTE_PTR_SUB(ptr, x) ((void*)((uintptr_t)ptr - (x)))
122 #define RTE_PTR_DIFF(ptr1, ptr2) ((uintptr_t)(ptr1) - (uintptr_t)(ptr2))
133 #define RTE_PTR_ALIGN_FLOOR(ptr, align) \
134 ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)ptr, align))
142 #define RTE_ALIGN_FLOOR(val, align) \
143 (typeof(val))((val) & (~((typeof(val))((align) - 1))))
151 #define RTE_PTR_ALIGN_CEIL(ptr, align) \
152 RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, (align) - 1), align)
160 #define RTE_ALIGN_CEIL(val, align) \
161 RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align)
170 #define RTE_PTR_ALIGN(ptr, align) RTE_PTR_ALIGN_CEIL(ptr, align)
179 #define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align)
203 #define RTE_BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
216 return n && !(n & (n - 1));
228 static inline uint32_t
250 static inline uint64_t
269 #define RTE_MIN(a, b) \
271 typeof (a) _a = (a); \
272 typeof (b) _b = (b); \
279 #define RTE_MAX(a, b) \
281 typeof (a) _a = (a); \
282 typeof (b) _b = (b); \
289 #include <emmintrin.h>
314 static inline uint32_t
317 return (uint32_t)__builtin_ctz(v);
334 return (x == 0) ? 0 : 32 - __builtin_clz(x);
339 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
342 #define _RTE_STR(x) #x
344 #define RTE_STR(x) _RTE_STR(x)
351 #define RTE_FMT(fmt, ...) fmt "%.0s", __VA_ARGS__ ""
352 #define RTE_FMT_HEAD(fmt, ...) fmt
353 #define RTE_FMT_TAIL(fmt, ...) __VA_ARGS__
356 #define RTE_LEN2MASK(ln, tp) \
357 ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln))))
360 #define RTE_DIM(a) (sizeof (a) / sizeof ((a)[0]))
376 static inline uint64_t
380 unsigned long long size;
382 while (isspace((
int)*str))
388 size = strtoull(str, &endptr, 0);
396 case 'G':
case 'g': size *= 1024;
397 case 'M':
case 'm': size *= 1024;
398 case 'K':
case 'k': size *= 1024;
419 rte_exit(
int exit_code,
const char *format, ...)
420 __attribute__((noreturn))
421 __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_align64pow2(uint64_t v)
static uint32_t rte_bsf32(uint32_t v)
static uint32_t rte_align32pow2(uint32_t x)
#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 uint64_t rte_str_to_size(const char *str)