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;
77 #define __rte_unused __attribute__((__unused__))
83 #define RTE_SET_USED(x) (void)(x)
90 #define RTE_PTR_ADD(ptr, x) ((void*)((uintptr_t)(ptr) + (x)))
95 #define RTE_PTR_SUB(ptr, x) ((void*)((uintptr_t)ptr - (x)))
102 #define RTE_PTR_DIFF(ptr1, ptr2) ((uintptr_t)(ptr1) - (uintptr_t)(ptr2))
113 #define RTE_PTR_ALIGN_FLOOR(ptr, align) \
114 ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)ptr, align))
122 #define RTE_ALIGN_FLOOR(val, align) \
123 (typeof(val))((val) & (~((typeof(val))((align) - 1))))
131 #define RTE_PTR_ALIGN_CEIL(ptr, align) \
132 RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, (align) - 1), align)
140 #define RTE_ALIGN_CEIL(val, align) \
141 RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align)
150 #define RTE_PTR_ALIGN(ptr, align) RTE_PTR_ALIGN_CEIL(ptr, align)
159 #define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align)
184 #define RTE_BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
186 extern int RTE_BUILD_BUG_ON_detected_error;
187 #define RTE_BUILD_BUG_ON(condition) do { \
188 ((void)sizeof(char[1 - 2*!!(condition)])); \
190 RTE_BUILD_BUG_ON_detected_error = 1; \
205 return n && !(n & (n - 1));
217 static inline uint32_t
239 static inline uint64_t
258 #define RTE_MIN(a, b) ({ \
259 typeof (a) _a = (a); \
260 typeof (b) _b = (b); \
267 #define RTE_MAX(a, b) ({ \
268 typeof (a) _a = (a); \
269 typeof (b) _b = (b); \
276 #include <emmintrin.h>
301 static inline uint32_t
304 return __builtin_ctz(v);
309 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
312 #define _RTE_STR(x) #x
314 #define RTE_STR(x) _RTE_STR(x)
317 #define RTE_LEN2MASK(ln, tp) \
318 ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln))))
321 #define RTE_DIM(a) (sizeof (a) / sizeof ((a)[0]))
337 static inline uint64_t
341 unsigned long long size;
343 while (isspace((
int)*str))
349 size = strtoull(str, &endptr, 0);
357 case 'G':
case 'g': size *= 1024;
358 case 'M':
case 'm': size *= 1024;
359 case 'K':
case 'k': size *= 1024;
380 rte_exit(
int exit_code,
const char *format, ...)
381 __attribute__((noreturn))
382 __attribute__((format(printf, 2, 3)));