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__))
76 #define __rte_unused __attribute__((__unused__))
82 #define RTE_SET_USED(x) (void)(x)
84 #define RTE_PRIORITY_LOG 101
85 #define RTE_PRIORITY_BUS 110
86 #define RTE_PRIORITY_CLASS 120
87 #define RTE_PRIORITY_LAST 65535
89 #define RTE_PRIO(prio) \
101 #define RTE_INIT_PRIO(func, prio) \
102 static void __attribute__((constructor(RTE_PRIO(prio)), used)) func(void)
112 #define RTE_INIT(func) \
113 RTE_INIT_PRIO(func, LAST)
124 #define RTE_FINI_PRIO(func, prio) \
125 static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
135 #define RTE_FINI(func) \
136 RTE_FINI_PRIO(func, LAST)
141 #define __rte_always_inline inline __attribute__((always_inline))
146 #define __rte_noinline __attribute__((noinline))
153 #define RTE_PTR_ADD(ptr, x) ((void*)((uintptr_t)(ptr) + (x)))
158 #define RTE_PTR_SUB(ptr, x) ((void*)((uintptr_t)ptr - (x)))
165 #define RTE_PTR_DIFF(ptr1, ptr2) ((uintptr_t)(ptr1) - (uintptr_t)(ptr2))
176 #define RTE_PTR_ALIGN_FLOOR(ptr, align) \
177 ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)ptr, align))
185 #define RTE_ALIGN_FLOOR(val, align) \
186 (typeof(val))((val) & (~((typeof(val))((align) - 1))))
194 #define RTE_PTR_ALIGN_CEIL(ptr, align) \
195 RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, (align) - 1), align)
203 #define RTE_ALIGN_CEIL(val, align) \
204 RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align)
213 #define RTE_PTR_ALIGN(ptr, align) RTE_PTR_ALIGN_CEIL(ptr, align)
222 #define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align)
229 #define RTE_ALIGN_MUL_CEIL(v, mul) \
230 (((v + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
237 #define RTE_ALIGN_MUL_FLOOR(v, mul) \
238 ((v / ((typeof(v))(mul))) * (typeof(v))(mul))
262 #define RTE_BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
274 static inline uint32_t
296 static inline uint64_t
314 #define RTE_IS_POWER_OF_2(n) ((n) && !(((n) - 1) & (n)))
325 return n && !(n & (n - 1));
337 static inline uint32_t
355 static inline uint32_t
372 static inline uint64_t
390 static inline uint64_t
403 #define RTE_MIN(a, b) \
405 typeof (a) _a = (a); \
406 typeof (b) _b = (b); \
413 #define RTE_MAX(a, b) \
415 typeof (a) _a = (a); \
416 typeof (b) _b = (b); \
433 static inline uint32_t
436 return (uint32_t)__builtin_ctz(v);
447 static inline uint32_t
458 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
476 #define container_of(ptr, type, member) __extension__ ({ \
477 const typeof(((type *)0)->member) *_ptr = (ptr); \
478 __attribute__((unused)) type *_target_ptr = \
480 (type *)(((uintptr_t)_ptr) - offsetof(type, member)); \
484 #define _RTE_STR(x) #x
486 #define RTE_STR(x) _RTE_STR(x)
493 #define RTE_FMT(fmt, ...) fmt "%.0s", __VA_ARGS__ ""
494 #define RTE_FMT_HEAD(fmt, ...) fmt
495 #define RTE_FMT_TAIL(fmt, ...) __VA_ARGS__
498 #define RTE_LEN2MASK(ln, tp) \
499 ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln))))
502 #define RTE_DIM(a) (sizeof (a) / sizeof ((a)[0]))
518 static inline uint64_t
522 unsigned long long size;
524 while (isspace((
int)*str))
530 size = strtoull(str, &endptr, 0);
538 case 'G':
case 'g': size *= 1024;
539 case 'M':
case 'm': size *= 1024;
540 case 'K':
case 'k': size *= 1024;
561 rte_exit(
int exit_code,
const char *format, ...)
562 __attribute__((noreturn))
563 __attribute__((format(printf, 2, 3)));