2
3
4
5
6
7
8
9
10
11
20# include <type_traits>
33# define SHZ_BACKEND SHZ_SH4
40
41
42
44#define SHZ_STRINGIFY_LITERAL(a) #a
48#define SHZ_COUNT_OF(array) (sizeof(array) / sizeof((array)[0
]))
50#define SHZ_CONTAINER_OF(ptr, type, member) ((type*)((char*)(ptr) - offsetof(type, member)))
52#define SHZ_SWAP(a, b) do { typeof(a) tmp = a; a = b; b = tmp; } while(false)
54#define SHZ_DECLARE_STRUCT(n, t) struct n; typedef struct n t
56#define SHZ_DECLARE_STRUCT_ALIGNED(n, t, a) struct SHZ_ALIGNAS
(a) n; typedef struct n t
61
62
63
65#define SHZ_ALIGNAS(N) __attribute__((aligned((N))))
67#define SHZ_SIMD(N) __attribute__((vector_size((N))))
69#define SHZ_HOT __attribute__((hot))
71#define SHZ_COLD __attribute__((cold))
73#define SHZ_FAST_MATH __attribute__((optimize("fast-math")))
75#define SHZ_NO_FAST_MATH __attribute__((optimize("no-fast-math")))
77#define SHZ_NO_OPTIMIZATION __attribute__((optimize("O0")))
79#define SHZ_ICACHE_ALIGNED __attribute__((aligned(32
)))
81#define SHZ_FORCE_INLINE __attribute__((always_inline)) SHZ_INLINE
83#define SHZ_NO_INLINE __attribute__((noinline))
85#define SHZ_FLATTEN __attribute__((flatten))
87#define SHZ_PACKED __attribute__((packed))
89#define SHZ_PURE __attribute__((pure))
91#define SHZ_ALIASING __attribute__((__may_alias__))
93#define SHZ_LIKELY(e) __builtin_expect(!!(e), 1
)
95#define SHZ_UNLIKELY(e) __builtin_expect(!!(e), 0
)
97#define SHZ_PREFETCH(a) __builtin_prefetch(a)
99#define SHZ_PREFETCH_VOLATILE(a) asm volatile("pref @%0" : : "r" (a))
103# define SHZ_DECLS_BEGIN
105# define SHZ_DECLS_END
107# define SHZ_INLINE inline static
109# define SHZ_CONST __attribute__((const))
111# define SHZ_RESTRICT restrict
115# define SHZ_CONVERT(type, value)
121 static_assert(sizeof(type) == sizeof(value), "SHZ_CONVERT: Cannot convert between types of differing sizes.");
125# define SHZ_DECLS_BEGIN extern "C" {
127# define SHZ_DECLS_END }
129# define SHZ_INLINE inline
131# define SHZ_CONST __attribute__((const)) constexpr
133# define SHZ_RESTRICT __restrict__
135# define SHZ_NOEXCEPT noexcept
137# define SHZ_CONVERT(type, from)
138 [&]<typename To, typename V>(V&& value) -> To {
139 using TNR = std::remove_reference_t<To>;
140 using VNR = std::remove_reference_t<V>;
141 if constexpr (std::is_pointer_v<To>) {
142 if constexpr (std::is_pointer_v<VNR>) {
143 return reinterpret_cast<To>(value);
145 return reinterpret_cast<To>(&value);
147 } else if constexpr (std::is_reference_v<To>) {
148 static_assert(sizeof(VNR) == sizeof(TNR), "SHZ_CONVERT: Cannot convert between types of differing sizes when converting to a reference type.");
149 return reinterpret_cast<To>(value);
151 static_assert(sizeof(VNR) == sizeof(TNR), "SHZ_CONVERT: Cannot convert between types of differing sizes.");
152 return reinterpret_cast<To&>(value);
154 }.template operator
()<type>(from)
160
161
162
SHZ_ALIASING int16_t shz_alias_int16_t
int16_t type whose value may be aliased as another type.
SHZ_ALIASING double shz_alias_double_t
double type whose value may be aliased as another type.
SHZ_ALIASING uint32_t shz_alias_uint32_t
uint32_t type whose value may be aliased as another type.
#define SHZ_STRINGIFY_LITERAL(a)
Stringifies a literal expression.
SHZ_ALIASING int64_t shz_alias_int64_t
int64_t type whose value may be aliased as another type.
SHZ_ALIASING uint16_t shz_alias_uint16_t
uint16_t type whose value may be aliased as another type.
SHZ_ALIASING int32_t shz_alias_int32_t
int32_t type whose value may be aliased as another type.
SHZ_ALIASING uint64_t shz_alias_uint64_t
uint64_t type whose value may be aliased as another type.
SHZ_ALIASING float shz_alias_float_t
float type whose value may be aliased as another type.