20#include <rte_config.h>
29#ifndef RTE_TOOLCHAIN_MSVC
31#define typeof __typeof__
41#ifdef RTE_TOOLCHAIN_MSVC
47#ifdef RTE_TOOLCHAIN_MSVC
48#define __rte_constant(e) 0
50#define __rte_constant(e) __extension__(__builtin_constant_p(e))
59#define RTE_CC_IS_GNU 0
65#define RTE_CC_IS_GNU 1
68#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + \
84#ifdef RTE_TOOLCHAIN_MSVC
85#define __rte_aligned(a) __declspec(align(a))
87#define __rte_aligned(a) __attribute__((__aligned__(a)))
90#ifdef RTE_ARCH_STRICT_ALIGN
95typedef uint64_t unaligned_uint64_t;
96typedef uint32_t unaligned_uint32_t;
97typedef uint16_t unaligned_uint16_t;
107#ifdef RTE_TOOLCHAIN_MSVC
108#define __rte_packed RTE_DEPRECATED(__rte_packed)
110#define __rte_packed (RTE_DEPRECATED(__rte_packed) __attribute__((__packed__)))
120#ifdef RTE_TOOLCHAIN_MSVC
121#define __rte_packed_begin __pragma(pack(push, 1))
122#define __rte_packed_end __pragma(pack(pop))
124#define __rte_packed_begin
125#define __rte_packed_end __attribute__((__packed__))
131#ifdef RTE_TOOLCHAIN_MSVC
132#define __rte_may_alias
134#define __rte_may_alias __attribute__((__may_alias__))
138#ifdef RTE_TOOLCHAIN_MSVC
139#define __rte_deprecated
140#define __rte_deprecated_msg(msg)
142#define __rte_deprecated __attribute__((__deprecated__))
143#define __rte_deprecated_msg(msg) __attribute__((__deprecated__(msg)))
149#if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG)
150#define RTE_PRAGMA(x) _Pragma(#x)
151#define RTE_PRAGMA_WARNING(w) RTE_PRAGMA(GCC warning #w)
152#define RTE_DEPRECATED(x) RTE_PRAGMA_WARNING(#x is deprecated)
154#define RTE_DEPRECATED(x)
161#if !defined(RTE_TOOLCHAIN_MSVC)
162#define __rte_diagnostic_push _Pragma("GCC diagnostic push")
163#define __rte_diagnostic_pop _Pragma("GCC diagnostic pop")
165#define __rte_diagnostic_push
166#define __rte_diagnostic_pop
173#if !defined(RTE_TOOLCHAIN_MSVC)
174#define __rte_diagnostic_ignored_wcast_qual _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
176#define __rte_diagnostic_ignored_wcast_qual
182#ifdef RTE_TOOLCHAIN_MSVC
183#define __rte_weak RTE_DEPRECATED(__rte_weak)
185#define __rte_weak RTE_DEPRECATED(__rte_weak) __attribute__((__weak__))
191#ifdef RTE_TOOLCHAIN_MSVC
194#define __rte_pure __attribute__((pure))
200#ifdef RTE_TOOLCHAIN_MSVC
203#define __rte_used __attribute__((used))
211#ifdef RTE_TOOLCHAIN_MSVC
214#define __rte_unused __attribute__((__unused__))
220#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
221#define __rte_restrict __restrict
223#define __rte_restrict restrict
230#define RTE_SET_USED(x) (void)(x)
239#ifdef RTE_TOOLCHAIN_MSVC
240#define __rte_format_printf(format_index, first_arg)
243#define __rte_format_printf(format_index, first_arg) \
244 __attribute__((format(gnu_printf, format_index, first_arg)))
246#define __rte_format_printf(format_index, first_arg) \
247 __attribute__((format(printf, format_index, first_arg)))
254#ifdef RTE_TOOLCHAIN_MSVC
255#define __rte_section(name) \
256 __pragma(data_seg(name)) __declspec(allocate(name))
258#define __rte_section(name) \
259 __attribute__((section(name)))
267#if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG)
268#define __rte_alloc_size(...) \
269 __attribute__((alloc_size(__VA_ARGS__)))
271#define __rte_alloc_size(...)
280#if defined(RTE_CC_GCC)
281#define __rte_alloc_align(argno) \
282 __attribute__((alloc_align(argno)))
284#define __rte_alloc_align(argno)
291#if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG)
292#define __rte_malloc __attribute__((__malloc__))
301#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >= 110000)
302#define __rte_dealloc(dealloc, argno) \
303 __attribute__((malloc(dealloc, argno)))
305#define __rte_dealloc(dealloc, argno)
308#define RTE_PRIORITY_LOG 101
309#define RTE_PRIORITY_BUS 110
310#define RTE_PRIORITY_CLASS 120
311#define RTE_PRIORITY_LAST 65535
313#define RTE_PRIO(prio) \
314 RTE_PRIORITY_ ## prio
326#ifndef RTE_TOOLCHAIN_MSVC
327#define RTE_INIT_PRIO(func, prio) \
328static void __attribute__((constructor(RTE_PRIO(prio)), used)) func(void)
331typedef int(__cdecl *_PIFV)(void);
333#define CTOR_SECTION_LOG ".CRT$XIB"
334#define CTOR_SECTION_BUS ".CRT$XIC"
335#define CTOR_SECTION_CLASS ".CRT$XID"
336#define CTOR_SECTION_LAST ".CRT$XIY"
338#define CTOR_PRIORITY_TO_SECTION(priority) CTOR_SECTION_ ## priority
340#define RTE_INIT_PRIO(name, priority) \
341 static void name(void); \
342 static int __cdecl name ## _thunk(void) { name(); return 0; } \
343 __pragma(const_seg(CTOR_PRIORITY_TO_SECTION(priority))) \
344 __declspec(allocate(CTOR_PRIORITY_TO_SECTION(priority))) \
345 _PIFV name ## _pointer = &name ## _thunk; \
346 __pragma(const_seg()) \
347 static void name(void)
359#define RTE_INIT(func) \
360 RTE_INIT_PRIO(func, LAST)
372#ifndef RTE_TOOLCHAIN_MSVC
373#define RTE_FINI_PRIO(func, prio) \
374static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
376#define DTOR_SECTION_LOG "mydtor$B"
377#define DTOR_SECTION_BUS "mydtor$C"
378#define DTOR_SECTION_CLASS "mydtor$D"
379#define DTOR_SECTION_LAST "mydtor$Y"
381#define DTOR_PRIORITY_TO_SECTION(priority) DTOR_SECTION_ ## priority
383#define RTE_FINI_PRIO(name, priority) \
384 static void name(void); \
385 __pragma(const_seg(DTOR_PRIORITY_TO_SECTION(priority))) \
386 __declspec(allocate(DTOR_PRIORITY_TO_SECTION(priority))) void *name ## _pointer = &name; \
387 __pragma(const_seg()) \
388 static void name(void)
400#define RTE_FINI(func) \
401 RTE_FINI_PRIO(func, LAST)
406#ifdef RTE_TOOLCHAIN_MSVC
407#define __rte_noreturn
409#define __rte_noreturn __attribute__((noreturn))
415#if defined(RTE_TOOLCHAIN_GCC) || defined(RTE_TOOLCHAIN_CLANG)
416#define __rte_unreachable() __extension__(__builtin_unreachable())
418#define __rte_unreachable() __assume(0)
444#ifdef RTE_TOOLCHAIN_MSVC
445#define __rte_warn_unused_result
447#define __rte_warn_unused_result __attribute__((warn_unused_result))
453#ifdef RTE_TOOLCHAIN_MSVC
454#define __rte_always_inline __forceinline
456#define __rte_always_inline inline __attribute__((always_inline))
462#ifdef RTE_TOOLCHAIN_MSVC
463#define __rte_noinline __declspec(noinline)
465#define __rte_noinline __attribute__((noinline))
471#ifdef RTE_TOOLCHAIN_MSVC
474#define __rte_hot __attribute__((hot))
480#ifdef RTE_TOOLCHAIN_MSVC
483#define __rte_cold __attribute__((cold))
492#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >= 130000)
493#define __rte_assume(condition) __attribute__((assume(condition)))
494#elif defined(RTE_TOOLCHAIN_GCC)
495#define __rte_assume(condition) do { if (!(condition)) __rte_unreachable(); } while (0)
496#elif defined(RTE_TOOLCHAIN_CLANG)
497#define __rte_assume(condition) __extension__(__builtin_assume(condition))
499#define __rte_assume(condition) __assume(condition)
505#ifdef RTE_MALLOC_ASAN
507#define __rte_no_asan __attribute__((no_sanitize("address", "hwaddress")))
509#define __rte_no_asan __attribute__((no_sanitize_address))
520#define RTE_PTR_ADD(ptr, x) ((void*)((uintptr_t)(ptr) + (x)))
525#define RTE_PTR_SUB(ptr, x) ((void *)((uintptr_t)(ptr) - (x)))
532#define RTE_PTR_DIFF(ptr1, ptr2) ((uintptr_t)(ptr1) - (uintptr_t)(ptr2))
540#define RTE_PTR_UNQUAL(X) ((void *)(uintptr_t)(X))
559#define RTE_CAST_PTR(type, ptr) ((type)(uintptr_t)(ptr))
564#define RTE_CAST_FIELD(var, field, type) \
565 (*(type *)((uintptr_t)(var) + offsetof(typeof(*(var)), field)))
576#define RTE_PTR_ALIGN_FLOOR(ptr, align) \
577 ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)(ptr), align))
585#define RTE_ALIGN_FLOOR(val, align) \
586 (typeof(val))((val) & (~((typeof(val))((align) - 1))))
594#define RTE_PTR_ALIGN_CEIL(ptr, align) \
595 RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, (align) - 1), align)
603#define RTE_ALIGN_CEIL(val, align) \
604 RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align)
613#define RTE_PTR_ALIGN(ptr, align) RTE_PTR_ALIGN_CEIL(ptr, align)
622#define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align)
629#define RTE_ALIGN_MUL_CEIL(v, mul) \
630 ((((v) + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
637#define RTE_ALIGN_MUL_FLOOR(v, mul) \
638 (((v) / ((typeof(v))(mul))) * (typeof(v))(mul))
645#define RTE_ALIGN_MUL_NEAR(v, mul) \
647 typeof(v) ceil = RTE_ALIGN_MUL_CEIL(v, mul); \
648 typeof(v) floor = RTE_ALIGN_MUL_FLOOR(v, mul); \
649 (ceil - (v)) > ((v) - floor) ? floor : ceil; \
666 return ((uintptr_t)ptr & (align - 1)) == 0;
672#if !defined(static_assert) && !defined(__cplusplus)
673#define static_assert _Static_assert
682#define RTE_BUILD_BUG_ON(condition) do { static_assert(!(condition), #condition); } while (0)
687#define RTE_CACHE_LINE_MASK (RTE_CACHE_LINE_SIZE-1)
690#define RTE_CACHE_LINE_ROUNDUP(size) RTE_ALIGN_CEIL(size, RTE_CACHE_LINE_SIZE)
693#if RTE_CACHE_LINE_SIZE == 64
694#define RTE_CACHE_LINE_SIZE_LOG2 6
695#elif RTE_CACHE_LINE_SIZE == 128
696#define RTE_CACHE_LINE_SIZE_LOG2 7
698#error "Unsupported cache line size"
702#define RTE_CACHE_LINE_MIN_SIZE 64
705#define __rte_cache_aligned __rte_aligned(RTE_CACHE_LINE_SIZE)
708#define __rte_cache_min_aligned __rte_aligned(RTE_CACHE_LINE_MIN_SIZE)
710#define _RTE_CACHE_GUARD_HELPER2(unique) \
711 alignas(RTE_CACHE_LINE_SIZE) \
712 char cache_guard_ ## unique[RTE_CACHE_LINE_SIZE * RTE_CACHE_GUARD_LINES]
713#define _RTE_CACHE_GUARD_HELPER1(unique) _RTE_CACHE_GUARD_HELPER2(unique)
721#define RTE_CACHE_GUARD _RTE_CACHE_GUARD_HELPER1(__COUNTER__)
727#define RTE_BAD_PHYS_ADDR ((phys_addr_t)-1)
737#define RTE_BAD_IOVA ((rte_iova_t)-1)
741#ifndef RTE_TOOLCHAIN_MSVC
761#define RTE_MIN(a, b) \
763 typeof (a) _a = (a); \
764 typeof (b) _b = (b); \
775#define RTE_MIN_T(a, b, t) \
776 ((t)(a) < (t)(b) ? (t)(a) : (t)(b))
781#define RTE_MAX(a, b) \
783 typeof (a) _a = (a); \
784 typeof (b) _b = (b); \
795#define RTE_MAX_T(a, b, t) \
796 ((t)(a) > (t)(b) ? (t)(a) : (t)(b))
802#define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
820#ifdef RTE_TOOLCHAIN_MSVC
821#define container_of(ptr, type, member) \
822 ((type *)((uintptr_t)(ptr) - offsetof(type, member)))
824#define container_of(ptr, type, member) __extension__ ({ \
825 const typeof(((type *)0)->member) *_ptr = (ptr); \
826 __rte_unused type *_target_ptr = \
828 (type *)(((uintptr_t)_ptr) - offsetof(type, member)); \
834#define RTE_SWAP(a, b) \
851#define RTE_SIZEOF_FIELD(type, field) (sizeof(((type *)0)->field))
853#define _RTE_STR(x) #x
855#define RTE_STR(x) _RTE_STR(x)
862#define RTE_FMT(fmt, ...) fmt "%.0s", __VA_ARGS__ ""
863#define RTE_FMT_HEAD(fmt, ...) fmt
864#define RTE_FMT_TAIL(fmt, ...) __VA_ARGS__
867#define RTE_LEN2MASK(ln, tp) \
868 ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln))))
871#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]
__extension__ typedef uint8_t RTE_MARKER8[0]
__extension__ typedef uint32_t RTE_MARKER32[0]
__extension__ typedef uint16_t RTE_MARKER16[0]
#define __rte_format_printf(format_index, first_arg)
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
__extension__ typedef void * RTE_MARKER[0]