25 #include <rte_config.h>
31 #define typeof __typeof__
39 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L
40 #define RTE_STD_C11 __extension__
46 #ifdef RTE_TOOLCHAIN_GCC
47 #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + \
51 #ifdef RTE_ARCH_STRICT_ALIGN
53 typedef uint32_t unaligned_uint32_t __attribute__ ((aligned(1)));
54 typedef uint16_t unaligned_uint16_t __attribute__ ((aligned(1)));
57 typedef uint32_t unaligned_uint32_t;
58 typedef uint16_t unaligned_uint16_t;
64 #define __rte_aligned(a) __attribute__((__aligned__(a)))
69 #define __rte_packed __attribute__((__packed__))
72 #define __rte_deprecated __attribute__((__deprecated__))
77 #define __rte_weak __attribute__((__weak__))
84 #define __rte_unused __attribute__((__unused__))
90 #define RTE_SET_USED(x) (void)(x)
92 #define RTE_PRIORITY_LOG 101
93 #define RTE_PRIORITY_BUS 110
94 #define RTE_PRIORITY_CLASS 120
95 #define RTE_PRIORITY_LAST 65535
97 #define RTE_PRIO(prio) \
109 #ifndef RTE_INIT_PRIO
110 #define RTE_INIT_PRIO(func, prio) \
111 static void __attribute__((constructor(RTE_PRIO(prio)), used)) func(void)
122 #define RTE_INIT(func) \
123 RTE_INIT_PRIO(func, LAST)
134 #ifndef RTE_FINI_PRIO
135 #define RTE_FINI_PRIO(func, prio) \
136 static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
147 #define RTE_FINI(func) \
148 RTE_FINI_PRIO(func, LAST)
153 #define __rte_always_inline inline __attribute__((always_inline))
158 #define __rte_noinline __attribute__((noinline))
165 #define RTE_PTR_ADD(ptr, x) ((void*)((uintptr_t)(ptr) + (x)))
170 #define RTE_PTR_SUB(ptr, x) ((void*)((uintptr_t)ptr - (x)))
177 #define RTE_PTR_DIFF(ptr1, ptr2) ((uintptr_t)(ptr1) - (uintptr_t)(ptr2))
182 #define RTE_CAST_FIELD(var, field, type) \
183 (*(type *)((uintptr_t)(var) + offsetof(typeof(*(var)), field)))
194 #define RTE_PTR_ALIGN_FLOOR(ptr, align) \
195 ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)ptr, align))
203 #define RTE_ALIGN_FLOOR(val, align) \
204 (typeof(val))((val) & (~((typeof(val))((align) - 1))))
212 #define RTE_PTR_ALIGN_CEIL(ptr, align) \
213 RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, (align) - 1), align)
221 #define RTE_ALIGN_CEIL(val, align) \
222 RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align)
231 #define RTE_PTR_ALIGN(ptr, align) RTE_PTR_ALIGN_CEIL(ptr, align)
240 #define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align)
247 #define RTE_ALIGN_MUL_CEIL(v, mul) \
248 (((v + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
255 #define RTE_ALIGN_MUL_FLOOR(v, mul) \
256 ((v / ((typeof(v))(mul))) * (typeof(v))(mul))
263 #define RTE_ALIGN_MUL_NEAR(v, mul) \
265 typeof(v) ceil = RTE_ALIGN_MUL_CEIL(v, mul); \
266 typeof(v) floor = RTE_ALIGN_MUL_FLOOR(v, mul); \
267 (ceil - v) > (v - floor) ? floor : ceil; \
292 #define RTE_BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
304 static inline uint32_t
326 static inline uint64_t
344 #define RTE_IS_POWER_OF_2(n) ((n) && !(((n) - 1) & (n)))
355 return n && !(n & (n - 1));
367 static inline uint32_t
385 static inline uint32_t
402 static inline uint64_t
420 static inline uint64_t
433 #define RTE_MIN(a, b) \
435 typeof (a) _a = (a); \
436 typeof (b) _b = (b); \
443 #define RTE_MAX(a, b) \
445 typeof (a) _a = (a); \
446 typeof (b) _b = (b); \
463 static inline uint32_t
466 return (uint32_t)__builtin_ctz(v);
501 static inline uint32_t
525 return (x == 0) ? 0 : 32 - __builtin_clz(x);
542 return (uint32_t)__builtin_ctzll(v);
584 return (x == 0) ? 0 : 64 - __builtin_clzll(x);
595 static inline uint32_t
607 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
625 #define container_of(ptr, type, member) __extension__ ({ \
626 const typeof(((type *)0)->member) *_ptr = (ptr); \
627 __attribute__((unused)) type *_target_ptr = \
629 (type *)(((uintptr_t)_ptr) - offsetof(type, member)); \
633 #define _RTE_STR(x) #x
635 #define RTE_STR(x) _RTE_STR(x)
642 #define RTE_FMT(fmt, ...) fmt "%.0s", __VA_ARGS__ ""
643 #define RTE_FMT_HEAD(fmt, ...) fmt
644 #define RTE_FMT_TAIL(fmt, ...) __VA_ARGS__
647 #define RTE_LEN2MASK(ln, tp) \
648 ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln))))
651 #define RTE_DIM(a) (sizeof (a) / sizeof ((a)[0]))
667 static inline uint64_t
671 unsigned long long size;
673 while (isspace((
int)*str))
679 size = strtoull(str, &endptr, 0);
687 case 'G':
case 'g': size *= 1024;
688 case 'M':
case 'm': size *= 1024;
689 case 'K':
case 'k': size *= 1024;
710 rte_exit(
int exit_code,
const char *format, ...)
711 __attribute__((noreturn))
712 __attribute__((format(printf, 2, 3)));