22#include <rte_config.h>
28#define typeof __typeof__
38#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L
39#define RTE_STD_C11 __extension__
50#define RTE_CC_IS_GNU 0
53#elif defined __INTEL_COMPILER
58#define RTE_CC_IS_GNU 1
61#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + \
68#define __rte_aligned(a) __attribute__((__aligned__(a)))
70#ifdef RTE_ARCH_STRICT_ALIGN
75typedef uint64_t unaligned_uint64_t;
76typedef uint32_t unaligned_uint32_t;
77typedef uint16_t unaligned_uint16_t;
83#define __rte_packed __attribute__((__packed__))
88#define __rte_may_alias __attribute__((__may_alias__))
91#define __rte_deprecated __attribute__((__deprecated__))
92#define __rte_deprecated_msg(msg) __attribute__((__deprecated__(msg)))
97#if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG)
98#define RTE_PRAGMA(x) _Pragma(#x)
99#define RTE_PRAGMA_WARNING(w) RTE_PRAGMA(GCC warning #w)
100#define RTE_DEPRECATED(x) RTE_PRAGMA_WARNING(#x is deprecated)
102#define RTE_DEPRECATED(x)
108#define __rte_weak __attribute__((__weak__))
113#define __rte_used __attribute__((used))
120#define __rte_unused __attribute__((__unused__))
125#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
126#define __rte_restrict __restrict
128#define __rte_restrict restrict
135#define RTE_SET_USED(x) (void)(x)
145#define __rte_format_printf(format_index, first_arg) \
146 __attribute__((format(gnu_printf, format_index, first_arg)))
148#define __rte_format_printf(format_index, first_arg) \
149 __attribute__((format(printf, format_index, first_arg)))
157#if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG)
158#define __rte_alloc_size(...) \
159 __attribute__((alloc_size(__VA_ARGS__)))
161#define __rte_alloc_size(...)
164#define RTE_PRIORITY_LOG 101
165#define RTE_PRIORITY_BUS 110
166#define RTE_PRIORITY_CLASS 120
167#define RTE_PRIORITY_LAST 65535
169#define RTE_PRIO(prio) \
170 RTE_PRIORITY_ ## prio
182#if defined(__x86_64__) || defined(__i386__)
183#define RTE_INIT_PRIO(func, prio) \
185 __attribute__((constructor(RTE_PRIO(prio)), used)) \
186 __attribute__((target ("sse2"))) \
187 __attribute__((target ("no-sse3"))) \
188 __attribute__((target ("no-sse4"))) \
191#define RTE_INIT_PRIO(func, prio) \
193 __attribute__((constructor(RTE_PRIO(prio)), used)) \
206#define RTE_INIT(func) \
207 RTE_INIT_PRIO(func, LAST)
219#define RTE_FINI_PRIO(func, prio) \
220static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
231#define RTE_FINI(func) \
232 RTE_FINI_PRIO(func, LAST)
237#define __rte_noreturn __attribute__((noreturn))
262#define __rte_warn_unused_result __attribute__((warn_unused_result))
267#define __rte_always_inline inline __attribute__((always_inline))
272#define __rte_noinline __attribute__((noinline))
277#define __rte_hot __attribute__((hot))
282#define __rte_cold __attribute__((cold))
287#ifdef RTE_MALLOC_ASAN
289#define __rte_no_asan __attribute__((no_sanitize("address", "hwaddress")))
291#define __rte_no_asan __attribute__((no_sanitize_address))
302#define RTE_PTR_ADD(ptr, x) ((void*)((uintptr_t)(ptr) + (x)))
307#define RTE_PTR_SUB(ptr, x) ((void *)((uintptr_t)(ptr) - (x)))
314#define RTE_PTR_DIFF(ptr1, ptr2) ((uintptr_t)(ptr1) - (uintptr_t)(ptr2))
319#define RTE_CAST_FIELD(var, field, type) \
320 (*(type *)((uintptr_t)(var) + offsetof(typeof(*(var)), field)))
331#define RTE_PTR_ALIGN_FLOOR(ptr, align) \
332 ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)(ptr), align))
340#define RTE_ALIGN_FLOOR(val, align) \
341 (typeof(val))((val) & (~((typeof(val))((align) - 1))))
349#define RTE_PTR_ALIGN_CEIL(ptr, align) \
350 RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, (align) - 1), align)
358#define RTE_ALIGN_CEIL(val, align) \
359 RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align)
368#define RTE_PTR_ALIGN(ptr, align) RTE_PTR_ALIGN_CEIL(ptr, align)
377#define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align)
384#define RTE_ALIGN_MUL_CEIL(v, mul) \
385 ((((v) + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
392#define RTE_ALIGN_MUL_FLOOR(v, mul) \
393 (((v) / ((typeof(v))(mul))) * (typeof(v))(mul))
400#define RTE_ALIGN_MUL_NEAR(v, mul) \
402 typeof(v) ceil = RTE_ALIGN_MUL_CEIL(v, mul); \
403 typeof(v) floor = RTE_ALIGN_MUL_FLOOR(v, mul); \
404 (ceil - (v)) > ((v) - floor) ? floor : ceil; \
421 return ((uintptr_t)ptr & (align - 1)) == 0;
429#define RTE_BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
434#define RTE_CACHE_LINE_MASK (RTE_CACHE_LINE_SIZE-1)
437#define RTE_CACHE_LINE_ROUNDUP(size) RTE_ALIGN_CEIL(size, RTE_CACHE_LINE_SIZE)
440#if RTE_CACHE_LINE_SIZE == 64
441#define RTE_CACHE_LINE_SIZE_LOG2 6
442#elif RTE_CACHE_LINE_SIZE == 128
443#define RTE_CACHE_LINE_SIZE_LOG2 7
445#error "Unsupported cache line size"
449#define RTE_CACHE_LINE_MIN_SIZE 64
452#define __rte_cache_aligned __rte_aligned(RTE_CACHE_LINE_SIZE)
455#define __rte_cache_min_aligned __rte_aligned(RTE_CACHE_LINE_MIN_SIZE)
461#define RTE_BAD_PHYS_ADDR ((phys_addr_t)-1)
471#define RTE_BAD_IOVA ((rte_iova_t)-1)
496static inline uint32_t
518static inline uint64_t
536#define RTE_IS_POWER_OF_2(n) ((n) && !(((n) - 1) & (n)))
547 return n && !(n & (n - 1));
559static inline uint32_t
577static inline uint32_t
594static inline uint64_t
612static inline uint64_t
625#define RTE_MIN(a, b) \
627 typeof (a) _a = (a); \
628 typeof (b) _b = (b); \
635#define RTE_MAX(a, b) \
637 typeof (a) _a = (a); \
638 typeof (b) _b = (b); \
655static inline uint32_t
658 return (uint32_t)__builtin_ctz(v);
696static inline uint32_t
717static inline uint32_t
720 return (x == 0) ? 0 : 32 - __builtin_clz(x);
734static inline uint32_t
737 return (uint32_t)__builtin_ctzll(v);
776static inline uint32_t
779 return (x == 0) ? 0 : 64 - __builtin_clzll(x);
793static inline uint32_t
805#define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
823#define container_of(ptr, type, member) __extension__ ({ \
824 const typeof(((type *)0)->member) *_ptr = (ptr); \
825 __rte_unused type *_target_ptr = \
827 (type *)(((uintptr_t)_ptr) - offsetof(type, member)); \
832#define RTE_SWAP(a, b) \
849#define RTE_SIZEOF_FIELD(type, field) (sizeof(((type *)0)->field))
851#define _RTE_STR(x) #x
853#define RTE_STR(x) _RTE_STR(x)
860#define RTE_FMT(fmt, ...) fmt "%.0s", __VA_ARGS__ ""
861#define RTE_FMT_HEAD(fmt, ...) fmt
862#define RTE_FMT_TAIL(fmt, ...) __VA_ARGS__
865#define RTE_LEN2MASK(ln, tp) \
866 ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln))))
869#define RTE_DIM(a) (sizeof (a) / sizeof ((a)[0]))
uint64_t rte_str_to_size(const char *str)
__extension__ typedef uint64_t RTE_MARKER64[0]
static uint32_t rte_log2_u32(uint32_t v)
static uint32_t rte_fls_u32(uint32_t x)
static int rte_bsf32_safe(uint32_t v, uint32_t *pos)
__extension__ typedef uint8_t RTE_MARKER8[0]
__extension__ typedef uint32_t RTE_MARKER32[0]
__extension__ typedef uint16_t RTE_MARKER16[0]
static uint32_t rte_bsf64(uint64_t v)
#define __rte_format_printf(format_index, first_arg)
static uint32_t rte_align32pow2(uint32_t x)
static uint32_t rte_align32prevpow2(uint32_t x)
static uint64_t rte_align64pow2(uint64_t v)
static uint32_t rte_bsf32(uint32_t v)
static int rte_bsf64_safe(uint64_t v, uint32_t *pos)
static uint64_t rte_align64prevpow2(uint64_t v)
static int rte_is_aligned(const void *const __rte_restrict ptr, const unsigned int align)
__rte_noreturn void rte_exit(int exit_code, const char *format,...) __rte_format_printf(2
static int rte_is_power_of_2(uint32_t n)
static uint64_t rte_combine64ms1b(uint64_t v)
static uint32_t rte_combine32ms1b(uint32_t x)
static uint32_t rte_log2_u64(uint64_t v)
static uint32_t rte_fls_u64(uint64_t x)
__extension__ typedef void * RTE_MARKER[0]