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_LAST 65535
88 #define RTE_PRIO(prio) \
100 #define RTE_INIT_PRIO(func, prio) \
101 static void __attribute__((constructor(RTE_PRIO(prio)), used)) func(void)
111 #define RTE_INIT(func) \
112 RTE_INIT_PRIO(func, LAST)
117 #define __rte_always_inline inline __attribute__((always_inline))
122 #define __rte_noinline __attribute__((noinline))
129 #define RTE_PTR_ADD(ptr, x) ((void*)((uintptr_t)(ptr) + (x)))
134 #define RTE_PTR_SUB(ptr, x) ((void*)((uintptr_t)ptr - (x)))
141 #define RTE_PTR_DIFF(ptr1, ptr2) ((uintptr_t)(ptr1) - (uintptr_t)(ptr2))
152 #define RTE_PTR_ALIGN_FLOOR(ptr, align) \
153 ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)ptr, align))
161 #define RTE_ALIGN_FLOOR(val, align) \
162 (typeof(val))((val) & (~((typeof(val))((align) - 1))))
170 #define RTE_PTR_ALIGN_CEIL(ptr, align) \
171 RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, (align) - 1), align)
179 #define RTE_ALIGN_CEIL(val, align) \
180 RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align)
189 #define RTE_PTR_ALIGN(ptr, align) RTE_PTR_ALIGN_CEIL(ptr, align)
198 #define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align)
205 #define RTE_ALIGN_MUL_CEIL(v, mul) \
206 (((v + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
213 #define RTE_ALIGN_MUL_FLOOR(v, mul) \
214 ((v / ((typeof(v))(mul))) * (typeof(v))(mul))
239 #define RTE_BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
241 extern int RTE_BUILD_BUG_ON_detected_error;
242 #define RTE_BUILD_BUG_ON(condition) do { \
243 ((void)sizeof(char[1 - 2*!!(condition)])); \
245 RTE_BUILD_BUG_ON_detected_error = 1; \
259 static inline uint32_t
281 static inline uint64_t
305 return n && !(n & (n - 1));
317 static inline uint32_t
335 static inline uint32_t
352 static inline uint64_t
370 static inline uint64_t
383 #define RTE_MIN(a, b) \
385 typeof (a) _a = (a); \
386 typeof (b) _b = (b); \
393 #define RTE_MAX(a, b) \
395 typeof (a) _a = (a); \
396 typeof (b) _b = (b); \
413 static inline uint32_t
416 return (uint32_t)__builtin_ctz(v);
427 static inline uint32_t
438 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
456 #define container_of(ptr, type, member) __extension__ ({ \
457 const typeof(((type *)0)->member) *_ptr = (ptr); \
458 __attribute__((unused)) type *_target_ptr = \
460 (type *)(((uintptr_t)_ptr) - offsetof(type, member)); \
464 #define _RTE_STR(x) #x
466 #define RTE_STR(x) _RTE_STR(x)
473 #define RTE_FMT(fmt, ...) fmt "%.0s", __VA_ARGS__ ""
474 #define RTE_FMT_HEAD(fmt, ...) fmt
475 #define RTE_FMT_TAIL(fmt, ...) __VA_ARGS__
478 #define RTE_LEN2MASK(ln, tp) \
479 ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln))))
482 #define RTE_DIM(a) (sizeof (a) / sizeof ((a)[0]))
498 static inline uint64_t
502 unsigned long long size;
504 while (isspace((
int)*str))
510 size = strtoull(str, &endptr, 0);
518 case 'G':
case 'g': size *= 1024;
519 case 'M':
case 'm': size *= 1024;
520 case 'K':
case 'k': size *= 1024;
541 rte_exit(
int exit_code,
const char *format, ...)
542 __attribute__((noreturn))
543 __attribute__((format(printf, 2, 3)));