27#define XRT_ALIGNAS(n) __declspec(align(n))
28#elif defined(XRT_DOXYGEN)
29#define XRT_ALIGNAS(align)
32#define XRT_ALIGNAS(align) alignas(align)
35#if (defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN) || \
36 (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) || \
37 (defined(__STDC_ENDIAN_NATIVE__) && __STDC_ENDIAN_NATIVE__ == __STDC_ENDIAN_BIG__) || defined(__BIG_ENDIAN__) || \
38 defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || defined(_MIBSEB) || defined(__MIBSEB) || \
43#elif (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN) || \
44 (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \
45 (defined(__STDC_ENDIAN_NATIVE__) && __STDC_ENDIAN_NATIVE__ == __STDC_ENDIAN_LITTLE__) || \
46 defined(__LITTLE_ENDIAN__) || defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || \
47 defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) || defined(__x86_64__) || defined(_M_X64) || \
48 defined(i386) || defined(__i386__) || defined(__i386) || defined(_M_IX86)
53#error "@todo: Unable to determine current architecture."
59#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
61#if defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__) || defined(_ARCH_PPC64) || defined(__s390x__) || \
62 (defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 8)
72#define XRT_PRINTF_FORMAT(fmt, list) __attribute__((format(printf, fmt, list)))
74#define XRT_PRINTF_FORMAT(fmt, list)
82#define XRT_MAYBE_UNUSED __attribute__((unused))
83#elif defined(_MSC_VER) && defined(__cplusplus)
84#define XRT_MAYBE_UNUSED [[maybe_unused]]
86#define XRT_MAYBE_UNUSED
97#define XRT_NONNULL_ALL __attribute__((nonnull))
99#define XRT_NONNULL_ALL
110#define XRT_NONNULL_FIRST __attribute__((nonnull(1)))
112#define XRT_NONNULL_FIRST
119#if defined(__GNUC__) && (__GNUC__ >= 4)
120#define XRT_CHECK_RESULT __attribute__((warn_unused_result))
121#elif defined(_MSC_VER) && (_MSC_VER >= 1700)
122#define XRT_CHECK_RESULT _Check_return_
124#define XRT_CHECK_RESULT
132#define XRT_NO_INLINE __attribute__((noinline))
133#elif defined(_MSC_VER)
134#define XRT_NO_INLINE __declspec(noinline)
146#define XRT_DEBUGBREAK()
147#elif defined(__clang__) || defined(__GNUC__)
148#define XRT_DEBUGBREAK() __builtin_trap()
149#elif defined(_MSC_VER)
150#define XRT_DEBUGBREAK() __debugbreak()
152#error "compiler not supported"
162#if defined(__cpp_decltype) && __cpp_decltype >= 200707L
163#define XRT_TYPEOF(x) decltype(x)
164#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
165#define XRT_TYPEOF(x) typeof(x)
166#elif defined(__GNUC__) || defined(__clang__)
167#define XRT_TYPEOF(x) __typeof__(x)
171typedef volatile int32_t xrt_atomic_s32_t;
174xrt_atomic_s32_inc_return(xrt_atomic_s32_t *p)
177 return __sync_add_and_fetch(p, 1);
178#elif defined(_MSC_VER)
179 return InterlockedIncrement((
volatile LONG *)p);
181#error "compiler not supported"
185xrt_atomic_s32_dec_return(xrt_atomic_s32_t *p)
188 return __sync_sub_and_fetch(p, 1);
189#elif defined(_MSC_VER)
190 return InterlockedDecrement((
volatile LONG *)p);
192#error "compiler not supported"
196xrt_atomic_s32_cmpxchg(xrt_atomic_s32_t *p, int32_t old_, int32_t new_)
199 return __sync_val_compare_and_swap(p, old_, new_);
200#elif defined(_MSC_VER)
201 return InterlockedCompareExchange((
volatile LONG *)p, old_, new_);
203#error "compiler not supported"
207xrt_atomic_s32_store(xrt_atomic_s32_t *p, int32_t v)
210 __atomic_store_n(p, v, __ATOMIC_SEQ_CST);
211#elif defined(_MSC_VER)
212 InterlockedExchange((
volatile LONG *)p, v);
214#error "compiler not supported"
218xrt_atomic_s32_load(xrt_atomic_s32_t *p)
221 return __atomic_load_n(p, __ATOMIC_SEQ_CST);
222#elif defined(_MSC_VER)
223 return InterlockedCompareExchange((
volatile LONG *)p, 0, 0);
225#error "compiler not supported"
229typedef volatile int64_t xrt_atomic_s64_t;
232xrt_atomic_s64_inc_return(xrt_atomic_s64_t *p)
235 return __sync_add_and_fetch(p, 1);
236#elif defined(_MSC_VER)
237 return InterlockedIncrement64((
volatile LONG64 *)p);
239#error "compiler not supported"
243xrt_atomic_s64_dec_return(xrt_atomic_s64_t *p)
246 return __sync_sub_and_fetch(p, 1);
247#elif defined(_MSC_VER)
248 return InterlockedDecrement64((
volatile LONG64 *)p);
250#error "compiler not supported"
254xrt_atomic_s64_cmpxchg(xrt_atomic_s64_t *p, int64_t old_, int64_t new_)
257 return __sync_val_compare_and_swap(p, old_, new_);
258#elif defined(_MSC_VER)
259 return InterlockedCompareExchange64((
volatile LONG64 *)p, old_, new_);
261#error "compiler not supported"
265xrt_atomic_s64_store(xrt_atomic_s64_t *p, int64_t v)
268 __atomic_store_n(p, v, __ATOMIC_SEQ_CST);
269#elif defined(_MSC_VER)
270 InterlockedExchange64((
volatile LONG64 *)p, v);
272#error "compiler not supported"
276xrt_atomic_s64_load(xrt_atomic_s64_t *p)
279 return __atomic_load_n(p, __ATOMIC_SEQ_CST);
280#elif defined(_MSC_VER)
281 return InterlockedCompareExchange64((
volatile LONG64 *)p, 0, 0);
283#error "compiler not supported"
288typedef intptr_t ssize_t;
290#define _SSIZE_T_DEFINED
298#define container_of(ptr, type, field) (type *)((char *)ptr - offsetof(type, field))
311#define XRT_STRUCT_INIT {}
314#elif defined(__cplusplus)
317#define XRT_STRUCT_INIT {}
323#define XRT_STRUCT_INIT {0}
344#define XRT_C11_COMPOUND(X)
346#define XRT_C11_COMPOUND(X) (X)
A minimal way to include Windows.h.