34 #ifndef _RTE_COMMON_H_ 35 #define _RTE_COMMON_H_ 55 #define typeof __typeof__ 62 #ifdef RTE_ARCH_STRICT_ALIGN 63 typedef uint64_t unaligned_uint64_t __attribute__ ((aligned(1)));
64 typedef uint32_t unaligned_uint32_t __attribute__ ((aligned(1)));
65 typedef uint16_t unaligned_uint16_t __attribute__ ((aligned(1)));
67 typedef uint64_t unaligned_uint64_t;
68 typedef uint32_t unaligned_uint32_t;
69 typedef uint16_t unaligned_uint16_t;
75 #define __rte_aligned(a) __attribute__((__aligned__(a))) 80 #define __rte_packed __attribute__((__packed__)) 83 #define __rte_deprecated __attribute__((__deprecated__)) 90 #define __rte_unused __attribute__((__unused__)) 96 #define RTE_SET_USED(x) (void)(x) 103 #define RTE_PTR_ADD(ptr, x) ((void*)((uintptr_t)(ptr) + (x))) 108 #define RTE_PTR_SUB(ptr, x) ((void*)((uintptr_t)ptr - (x))) 115 #define RTE_PTR_DIFF(ptr1, ptr2) ((uintptr_t)(ptr1) - (uintptr_t)(ptr2)) 126 #define RTE_PTR_ALIGN_FLOOR(ptr, align) \ 127 ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)ptr, align)) 135 #define RTE_ALIGN_FLOOR(val, align) \ 136 (typeof(val))((val) & (~((typeof(val))((align) - 1)))) 144 #define RTE_PTR_ALIGN_CEIL(ptr, align) \ 145 RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, (align) - 1), align) 153 #define RTE_ALIGN_CEIL(val, align) \ 154 RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align) 163 #define RTE_PTR_ALIGN(ptr, align) RTE_PTR_ALIGN_CEIL(ptr, align) 172 #define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align) 197 #define RTE_BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) 199 extern int RTE_BUILD_BUG_ON_detected_error;
200 #define RTE_BUILD_BUG_ON(condition) do { \ 201 ((void)sizeof(char[1 - 2*!!(condition)])); \ 203 RTE_BUILD_BUG_ON_detected_error = 1; \ 218 return n && !(n & (n - 1));
230 static inline uint32_t
252 static inline uint64_t
271 #define RTE_MIN(a, b) ({ \ 272 typeof (a) _a = (a); \ 273 typeof (b) _b = (b); \ 280 #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 __builtin_ctz(v);
322 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER) 325 #define _RTE_STR(x) #x 327 #define RTE_STR(x) _RTE_STR(x) 330 #define RTE_LEN2MASK(ln, tp) \ 331 ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln)))) 334 #define RTE_DIM(a) (sizeof (a) / sizeof ((a)[0])) 350 static inline uint64_t
354 unsigned long long size;
356 while (isspace((
int)*str))
362 size = strtoull(str, &endptr, 0);
370 case 'G':
case 'g': size *= 1024;
371 case 'M':
case 'm': size *= 1024;
372 case 'K':
case 'k': size *= 1024;
393 rte_exit(
int exit_code,
const char *format, ...)
394 __attribute__((noreturn))
395 __attribute__((format(printf, 2, 3)));
static int rte_is_aligned(void *ptr, unsigned align)
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)