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__
70 #ifdef RTE_TOOLCHAIN_GCC
71 #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + \
75 #ifdef RTE_ARCH_STRICT_ALIGN
77 typedef uint32_t unaligned_uint32_t __attribute__ ((aligned(1)));
78 typedef uint16_t unaligned_uint16_t __attribute__ ((aligned(1)));
81 typedef uint32_t unaligned_uint32_t;
82 typedef uint16_t unaligned_uint16_t;
88 #define __rte_aligned(a) __attribute__((__aligned__(a)))
93 #define __rte_packed __attribute__((__packed__))
96 #define __rte_deprecated __attribute__((__deprecated__))
103 #define __rte_unused __attribute__((__unused__))
109 #define RTE_SET_USED(x) (void)(x)
114 #define __rte_always_inline inline __attribute__((always_inline))
119 #define __rte_noinline __attribute__((noinline))
126 #define RTE_PTR_ADD(ptr, x) ((void*)((uintptr_t)(ptr) + (x)))
131 #define RTE_PTR_SUB(ptr, x) ((void*)((uintptr_t)ptr - (x)))
138 #define RTE_PTR_DIFF(ptr1, ptr2) ((uintptr_t)(ptr1) - (uintptr_t)(ptr2))
149 #define RTE_PTR_ALIGN_FLOOR(ptr, align) \
150 ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)ptr, align))
158 #define RTE_ALIGN_FLOOR(val, align) \
159 (typeof(val))((val) & (~((typeof(val))((align) - 1))))
167 #define RTE_PTR_ALIGN_CEIL(ptr, align) \
168 RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, (align) - 1), align)
176 #define RTE_ALIGN_CEIL(val, align) \
177 RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align)
186 #define RTE_PTR_ALIGN(ptr, align) RTE_PTR_ALIGN_CEIL(ptr, align)
195 #define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align)
220 #define RTE_BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
222 extern int RTE_BUILD_BUG_ON_detected_error;
223 #define RTE_BUILD_BUG_ON(condition) do { \
224 ((void)sizeof(char[1 - 2*!!(condition)])); \
226 RTE_BUILD_BUG_ON_detected_error = 1; \
241 return n && !(n & (n - 1));
253 static inline uint32_t
275 static inline uint64_t
294 #define RTE_MIN(a, b) \
296 typeof (a) _a = (a); \
297 typeof (b) _b = (b); \
304 #define RTE_MAX(a, b) \
306 typeof (a) _a = (a); \
307 typeof (b) _b = (b); \
324 static inline uint32_t
327 return __builtin_ctz(v);
338 static inline uint32_t
349 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
367 #define container_of(ptr, type, member) __extension__ ({ \
368 const typeof(((type *)0)->member) *_ptr = (ptr); \
369 __attribute__((unused)) type *_target_ptr = \
371 (type *)(((uintptr_t)_ptr) - offsetof(type, member)); \
375 #define _RTE_STR(x) #x
377 #define RTE_STR(x) _RTE_STR(x)
384 #define RTE_FMT(fmt, ...) fmt "%.0s", __VA_ARGS__ ""
385 #define RTE_FMT_HEAD(fmt, ...) fmt
386 #define RTE_FMT_TAIL(fmt, ...) __VA_ARGS__
389 #define RTE_LEN2MASK(ln, tp) \
390 ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln))))
393 #define RTE_DIM(a) (sizeof (a) / sizeof ((a)[0]))
409 static inline uint64_t
413 unsigned long long size;
415 while (isspace((
int)*str))
421 size = strtoull(str, &endptr, 0);
429 case 'G':
case 'g': size *= 1024;
430 case 'M':
case 'm': size *= 1024;
431 case 'K':
case 'k': size *= 1024;
452 rte_exit(
int exit_code,
const char *format, ...)
453 __attribute__((noreturn))
454 __attribute__((format(printf, 2, 3)));