26#define XRT_ALIGNAS(n) __declspec(align(n))
29#define XRT_ALIGNAS(align) alignas(align)
32#if (defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN) || \
33 (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) || \
34 (defined(__STDC_ENDIAN_NATIVE__) && __STDC_ENDIAN_NATIVE__ == __STDC_ENDIAN_BIG__) || defined(__BIG_ENDIAN__) || \
35 defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || defined(_MIBSEB) || defined(__MIBSEB) || \
40#elif (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN) || \
41 (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \
42 (defined(__STDC_ENDIAN_NATIVE__) && __STDC_ENDIAN_NATIVE__ == __STDC_ENDIAN_LITTLE__) || \
43 defined(__LITTLE_ENDIAN__) || defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || \
44 defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) || defined(__x86_64__) || defined(_M_X64) || \
45 defined(i386) || defined(__i386__) || defined(__i386) || defined(_M_IX86)
50#error "@todo: Unable to determine current architecture."
56#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
58#if defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__) || defined(_ARCH_PPC64) || defined(__s390x__) || \
59 (defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 8)
69#define XRT_PRINTF_FORMAT(fmt, list) __attribute__((format(printf, fmt, list)))
71#define XRT_PRINTF_FORMAT(fmt, list)
79#define XRT_MAYBE_UNUSED __attribute__((unused))
80#elif defined(_MSC_VER) && defined(__cplusplus)
81#define XRT_MAYBE_UNUSED [[maybe_unused]]
83#define XRT_MAYBE_UNUSED
90#if defined(__GNUC__) && (__GNUC__ >= 4)
91#define XRT_CHECK_RESULT __attribute__((warn_unused_result))
92#elif defined(_MSC_VER) && (_MSC_VER >= 1700)
93#define XRT_CHECK_RESULT _Check_return_
95#define XRT_CHECK_RESULT
103#define XRT_NO_INLINE __attribute__((noinline))
104#elif defined(_MSC_VER)
105#define XRT_NO_INLINE __declspec(noinline)
117#define XRT_DEBUGBREAK()
118#elif defined(__clang__) || defined(__GNUC__)
119#define XRT_DEBUGBREAK() __builtin_trap()
120#elif defined(_MSC_VER)
121#define XRT_DEBUGBREAK() __debugbreak()
123#error "compiler not supported"
128typedef volatile int32_t xrt_atomic_s32_t;
131xrt_atomic_s32_inc_return(xrt_atomic_s32_t *p)
134 return __sync_add_and_fetch(p, 1);
135#elif defined(_MSC_VER)
136 return InterlockedIncrement((
volatile LONG *)p);
138#error "compiler not supported"
142xrt_atomic_s32_dec_return(xrt_atomic_s32_t *p)
145 return __sync_sub_and_fetch(p, 1);
146#elif defined(_MSC_VER)
147 return InterlockedDecrement((
volatile LONG *)p);
149#error "compiler not supported"
153xrt_atomic_s32_cmpxchg(xrt_atomic_s32_t *p, int32_t old_, int32_t new_)
156 return __sync_val_compare_and_swap(p, old_, new_);
157#elif defined(_MSC_VER)
158 return InterlockedCompareExchange((
volatile LONG *)p, old_, new_);
160#error "compiler not supported"
165typedef intptr_t ssize_t;
167#define _SSIZE_T_DEFINED
175#define container_of(ptr, type, field) (type *)((char *)ptr - offsetof(type, field))
188#define XRT_STRUCT_INIT {}
191#elif defined(__cplusplus)
194#define XRT_STRUCT_INIT {}
200#define XRT_STRUCT_INIT {0}
A minimal way to include Windows.h.