15#if !defined __has_attribute
16#define __has_attribute(x) 0
18#if !defined __has_builtin
19#define __has_builtin(x) 0
21#if !defined __has_feature
22#define __has_feature(x) 0
24#if !defined __has_include
25#define __has_include(x) 0
27#if !defined __has_warning
28#define __has_warning(x) 0
30#if !defined A_HAVE_INLINE
31#define A_HAVE_INLINE 1
32#elif A_HAVE_INLINE + 0 < 1
35#if defined(__GNUC__) || \
37#pragma GCC system_header
40#if defined(__MINGW32__)
41#undef __USE_MINGW_ANSI_STDIO
42#define __USE_MINGW_ANSI_STDIO 1
47#define A_PREREQ_MSVC(maj, min) (_MSC_VER >= (maj * 100 + min))
49#define A_PREREQ_MSVC(maj, min) 0
53#if defined(__GNUC__) && defined(__GNUC_MINOR__)
54#define A_PREREQ_GNUC(maj, min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
56#define A_PREREQ_GNUC(maj, min) 0
60#if defined(__clang_major__) && defined(__clang_minor__)
61#define A_PREREQ_LLVM(maj, min) ((__clang_major__ << 16) + __clang_minor__ >= ((maj) << 16) + (min))
63#define A_PREREQ_LLVM(maj, min) 0
68#define A_FUNC __FUNCTION__
69#elif defined(__GNUC__)
70#define A_FUNC (__extension__ __PRETTY_FUNCTION__)
71#elif defined(__cplusplus) && (__cplusplus > 201100L) || \
72 defined(__STDC_VERSION__) && (__STDC_VERSION__ > 199900L)
73#define A_FUNC __func__
75#define A_FUNC __FUNCTION__
79#if defined(__STDC_VERSION__) && (__STDC_VERSION__ > 199900L) || \
80 defined(__cplusplus) && (__cplusplus > 201100L) || A_PREREQ_MSVC(18, 0)
82#if !defined A_HAVE_LONG_LONG_TYPE
83#define A_HAVE_LONG_LONG_TYPE 1
87#if defined(A_HAVE_LONG_LONG_TYPE) && (A_HAVE_LONG_LONG_TYPE + 0 < 1)
88#undef A_HAVE_LONG_LONG_TYPE
91#if defined(__cplusplus) && (__cplusplus > 201100L)
93#if !defined A_HAVE_NULLPTR
94#define A_HAVE_NULLPTR 1
98#if defined(A_HAVE_NULLPTR) && (A_HAVE_NULLPTR + 0 < 1)
102#if A_PREREQ_GNUC(2, 96) || __has_builtin(__builtin_expect)
103#define A_UNLIKELY(x) __builtin_expect(!!(x), 0)
104#define A_LIKELY(x) __builtin_expect(!!(x), 1)
106#define A_UNLIKELY(x) (!!(x))
107#define A_LIKELY(x) (!!(x))
110#if defined(_WIN32) || defined(__CYGWIN__)
111#define A_DECLSPEC(x) __declspec(x)
116#if defined(__GNUC__) || defined(__clang__)
117#define A_ATTRIBUTE(x) __attribute__(x)
119#define A_ATTRIBUTE(x)
122#if __has_builtin(__builtin_assume)
123#define A_ASSUME(x) __builtin_assume(x)
124#elif A_PREREQ_GNUC(13, 0)
125#define A_ASSUME(x) __attribute__((__assume__(x)))
126#elif A_PREREQ_GNUC(4, 5)
129 if (!(x)) { __builtin_unreachable(); } \
131#elif defined(_MSC_VER)
132#define A_ASSUME(x) __assume(x)
134#define A_ASSUME(x) (void)0
138#if A_PREREQ_GNUC(3, 3) || __has_attribute(__nonnull__)
139#define A_NONULL(x) __attribute__((__nonnull__ x))
145#if A_PREREQ_GNUC(2, 4) || __has_attribute(__format__)
146#define A_FORMAT(_, a, b) __attribute__((__format__(_, a, b)))
148#define A_FORMAT(_, a, b)
152#if A_PREREQ_GNUC(7, 0) || __has_attribute(__fallthrough__)
153#define A_FALLTHROUGH __attribute__((__fallthrough__))
155#define A_FALLTHROUGH (void)0
159#if A_PREREQ_GNUC(3, 2) || __has_attribute(__deprecated__)
160#define A_DEPRECATED __attribute__((__deprecated__))
161#elif defined(_WIN32) || defined(__CYGWIN__)
162#define A_DEPRECATED __declspec(deprecated)
168#if A_PREREQ_GNUC(3, 2) || __has_attribute(__always_inline__)
169#define A_INLINE __inline __attribute__((__always_inline__))
170#elif defined(_MSC_VER)
171#define A_INLINE __inline __forceinline
173#define A_INLINE __inline
176#define A_INTERN static A_INLINE
180#if defined(_WIN32) || defined(__CYGWIN__)
181#define A_EXPORT __declspec(dllexport)
182#define A_IMPORT __declspec(dllimport)
184#elif A_PREREQ_GNUC(4, 0) || __has_attribute(__visibility__)
185#define A_EXPORT __attribute__((__visibility__("default")))
186#define A_IMPORT __attribute__((__visibility__("default")))
187#define A_HIDDEN __attribute__((__visibility__("hidden")))
193#if defined(A_EXPORTS)
194#define A_PUBLIC A_EXPORT
195#elif defined(A_IMPORTS)
196#define A_PUBLIC A_IMPORT
202#define A_EXTERN A_PUBLIC extern
204#if !defined __cplusplus
206#define A_EXTERN_C_ENTER
207#define A_EXTERN_C_LEAVE
209#define A_EXTERN_C extern "C"
210#define A_EXTERN_C_ENTER extern "C" {
211#define A_EXTERN_C_LEAVE }
229#if defined(__ORDER_LITTLE_ENDIAN__)
230#define A_ORDER_LITTLE __ORDER_LITTLE_ENDIAN__
232#define A_ORDER_LITTLE 1234
238#if defined(__ORDER_BIG_ENDIAN__)
239#define A_ORDER_BIG __ORDER_BIG_ENDIAN__
241#define A_ORDER_BIG 4321
243#if !defined A_BYTE_ORDER
248#if defined(__BYTE_ORDER__)
249#define A_BYTE_ORDER __BYTE_ORDER__
251#define A_BYTE_ORDER 1234
255#if !defined A_SIZE_POINTER
260#if defined(__SIZEOF_POINTER__)
261#define A_SIZE_POINTER __SIZEOF_POINTER__
262#elif defined(_WIN64) || defined(__LP64__)
263#define A_SIZE_POINTER 8
265#define A_SIZE_POINTER 4
270#define A_BUILD_ASSERT(x) (void)(sizeof(char[1 - 2 * !(x)]))
272#define A_BUILD_BUG_ON(x) (void)(sizeof(char[1 - 2 * !!(x)]))
274#if defined(__cplusplus)
275#define a_cast_r(T, x) reinterpret_cast<T>(x)
276#define a_cast_d(T, x) dynamic_cast<T>(x)
277#define a_cast_s(T, x) static_cast<T>(x)
278#define a_cast_c(T, x) const_cast<T>(x)
280#define a_cast_r(T, x) ((T)(x))
281#define a_cast_d(T, x) ((T)(x))
282#define a_cast_s(T, x) ((T)(x))
283#define a_cast_c(T, x) ((T)(x))
285#define A_CAST_3(a, b, c) a##b##c
286#define A_CAST_2(a, b) a##b
287#define A_CAST_1(a) #a
289#if defined(__cplusplus) && defined(A_HAVE_NULLPTR)
290#define A_NULL nullptr
295#define a_void_c(x) a_cast_s(void, x)
296#define a_void_(_, x) a_cast_s(void _, x)
300#if defined(__cplusplus)
310#if defined(__STDC_VERSION__) || A_PREREQ_MSVC(18, 0)
313#define A_BOOL unsigned char
318#define a_bool_c(x) (!!(x))
323#define A_INT_MAX INT_MAX
324#define A_INT_MIN INT_MIN
326#define a_int_c(x) a_cast_s(a_int, x)
327#define a_int_(_, x) a_cast_s(a_int _, x)
331#define A_UINT unsigned int
332#define A_UINT_MAX UINT_MAX
334#define a_uint_c(x) a_cast_s(a_uint, x)
335#define a_uint_(_, x) a_cast_s(a_uint _, x)
340#define A_SHRT_MAX SHRT_MAX
341#define A_SHRT_MIN SHRT_MIN
343#define a_shrt_c(x) a_cast_s(a_shrt, x)
344#define a_shrt_(_, x) a_cast_s(a_shrt _, x)
348#define A_USHRT unsigned short
349#define A_USHRT_MAX USHRT_MAX
351#define a_ushrt_c(x) a_cast_s(a_ushrt, x)
352#define a_ushrt_(_, x) a_cast_s(a_ushrt _, x)
357#define A_LONG_MIN LONG_MIN
358#define A_LONG_MAX LONG_MAX
360#define a_long_c(x) a_cast_s(a_long, x)
361#define a_long_(_, x) a_cast_s(a_long _, x)
365#define A_ULONG unsigned long
366#define A_ULONG_MAX ULONG_MAX
368#define a_ulong_c(x) a_cast_s(a_ulong, x)
369#define a_ulong_(_, x) a_cast_s(a_ulong _, x)
373#if defined(A_HAVE_LONG_LONG_TYPE)
375#define A_LLONG long long
376#define A_LLONG_MAX LLONG_MAX
377#define A_LLONG_MIN LLONG_MIN
379#define a_llong_c(x) a_cast_s(a_llong, x)
380#define a_llong_(_, x) a_cast_s(a_llong _, x)
382typedef A_LLONG a_llong;
384#define A_ULLONG unsigned long long
385#define A_ULLONG_MAX ULLONG_MAX
387#define a_ullong_c(x) a_cast_s(a_ullong, x)
388#define a_ullong_(_, x) a_cast_s(a_ullong _, x)
390typedef A_ULLONG a_ullong;
394#define A_BYTE unsigned char
395#define A_BYTE_MAX UCHAR_MAX
397#define a_byte_c(x) a_cast_s(a_byte, x)
398#define a_byte_(_, x) a_cast_s(a_byte _, x)
403#define A_C8_MAX CHAR_MAX
404#define A_C8_MIN CHAR_MIN
406#define a_c8_c(x) a_cast_s(a_c8, x)
407#define a_c8_(_, x) a_cast_s(a_c8 _, x)
412#define A_I8 signed char
418#define A_I8_MAX A_I8_C(0x7F)
421#define A_I8_MIN A_I8_C(~0x7F)
424#define a_i8_c(x) a_cast_s(a_i8, x)
425#define a_i8_(_, x) a_cast_s(a_i8 _, x)
430#define A_U8 unsigned char
436#define A_U8_MAX A_U8_C(0xFF)
439#define a_u8_c(x) a_cast_s(a_u8, x)
440#define a_u8_(_, x) a_cast_s(a_u8 _, x)
451#if !defined A_I16 && (INT_MAX == 0x7FFFL)
459#if !defined A_I16_MAX
460#define A_I16_MAX A_I16_C(0x7FFF)
462#if !defined A_I16_MIN
463#define A_I16_MIN A_I16_C(~0x7FFF)
466#define a_i16_c(x) a_cast_s(a_i16, x)
467#define a_i16_(_, x) a_cast_s(a_i16 _, x)
471#if !defined A_U16 && (UINT_MAX == 0xFFFFUL)
472#define A_U16 unsigned int
474#define A_U16 unsigned short
479#if !defined A_U16_MAX
480#define A_U16_MAX A_U16_C(0xFFFF)
483#define a_u16_c(x) a_cast_s(a_u16, x)
484#define a_u16_(_, x) a_cast_s(a_u16 _, x)
488#if !defined A_PRI16 && (UINT_MAX == 0xFFFFUL)
490#elif !defined A_PRI16
493#if !defined A_SCN16 && (UINT_MAX == 0xFFFFUL)
495#elif !defined A_SCN16
499#if !defined A_I32 && (INT_MAX == 0x7FFFFFFFL)
504#if !defined A_I32_C && (INT_MAX == 0x7FFFFFFFL)
506#elif !defined A_I32_C
507#define A_I32_C(X) A_CAST_2(X, L)
509#if !defined A_I32_MAX
510#define A_I32_MAX A_I32_C(0x7FFFFFFF)
512#if !defined A_I32_MIN
513#define A_I32_MIN A_I32_C(~0x7FFFFFFF)
516#define a_i32_c(x) a_cast_s(a_i32, x)
517#define a_i32_(_, x) a_cast_s(a_i32 _, x)
521#if !defined A_U32 && (UINT_MAX == 0xFFFFFFFFUL)
522#define A_U32 unsigned int
524#define A_U32 unsigned long
526#if !defined A_U32_C && (UINT_MAX == 0xFFFFFFFFUL)
527#define A_U32_C(X) A_CAST_2(X, U)
528#elif !defined A_U32_C
529#define A_U32_C(X) A_CAST_2(X, UL)
531#if !defined A_U32_MAX
532#define A_U32_MAX A_U32_C(0xFFFFFFFF)
535#define a_u32_c(x) a_cast_s(a_u32, x)
536#define a_u32_(_, x) a_cast_s(a_u32 _, x)
540#if !defined A_PRI32 && (UINT_MAX == 0xFFFFFFFFUL)
542#elif !defined A_PRI32
545#if !defined A_SCN32 && (UINT_MAX == 0xFFFFFFFFUL)
547#elif !defined A_SCN32
551#if !defined A_I64 && (LONG_MAX == 0x7FFFFFFFL)
552#if defined(_MSC_VER) && (_MSC_VER < 1800) || \
553 defined(__WATCOMC__) && (__WATCOMC__ >= 1100) || \
554 defined(__BORLANDC__) && (__BORLANDC__ >= 0x530)
557#define A_I64 long long
562#if !defined A_I64_C && (LONG_MAX == 0x7FFFFFFFL)
563#if defined(_MSC_VER) && (_MSC_VER < 1800) || \
564 defined(__WATCOMC__) && (__WATCOMC__ >= 1100) || \
565 defined(__BORLANDC__) && (__BORLANDC__ >= 0x530)
566#define A_I64_C(X) A_CAST_2(X, i64)
567#elif defined(__GNUC__)
568#define A_I64_C(X) (A_CAST_2(__extension__ X, LL))
570#define A_I64_C(X) A_CAST_2(X, LL)
572#elif !defined A_I64_C
573#define A_I64_C(X) A_CAST_2(X, L)
575#if !defined A_I64_MAX
576#define A_I64_MAX A_I64_C(0x7FFFFFFFFFFFFFFF)
578#if !defined A_I64_MIN
579#define A_I64_MIN A_I64_C(~0x7FFFFFFFFFFFFFFF)
582#define a_i64_c(x) a_cast_s(a_i64, x)
583#define a_i64_(_, x) a_cast_s(a_i64 _, x)
592#if !defined A_U64 && (ULONG_MAX == 0xFFFFFFFFUL)
593#if defined(_MSC_VER) && (_MSC_VER < 1800) || \
594 defined(__WATCOMC__) && (__WATCOMC__ >= 1100) || \
595 defined(__BORLANDC__) && (__BORLANDC__ >= 0x530)
596#define A_U64 unsigned __int64
598#define A_U64 unsigned long long
601#define A_U64 unsigned long
603#if !defined A_U64_C && (ULONG_MAX == 0xFFFFFFFFUL)
604#if defined(_MSC_VER) && (_MSC_VER < 1800) || \
605 defined(__WATCOMC__) && (__WATCOMC__ >= 1100) || \
606 defined(__BORLANDC__) && (__BORLANDC__ >= 0x530)
607#define A_U64_C(X) A_CAST_2(X, ui64)
608#elif defined(__GNUC__)
609#define A_U64_C(X) (A_CAST_2(__extension__ X, ULL))
611#define A_U64_C(X) A_CAST_2(X, ULL)
613#elif !defined A_U64_C
614#define A_U64_C(X) A_CAST_2(X, UL)
616#if !defined A_U64_MAX
617#define A_U64_MAX A_U64_C(0xFFFFFFFFFFFFFFFF)
620#define a_u64_c(x) a_cast_s(a_u64, x)
621#define a_u64_(_, x) a_cast_s(a_u64 _, x)
630#if !defined A_PRI64 && (ULONG_MAX == 0xFFFFFFFFUL)
631#if defined(_MSC_VER) && (_MSC_VER < 1800) || \
632 defined(__WATCOMC__) && (__WATCOMC__ >= 1100) || \
633 defined(__BORLANDC__) && (__BORLANDC__ >= 0x530)
638#elif !defined A_PRI64
641#if !defined A_SCN64 && (ULONG_MAX == 0xFFFFFFFFUL)
642#if defined(_MSC_VER) && (_MSC_VER < 1800) || \
643 defined(__WATCOMC__) && (__WATCOMC__ >= 1100) || \
644 defined(__BORLANDC__) && (__BORLANDC__ >= 0x530)
649#elif !defined A_SCN64
657#define A_IMAX_C(X) A_I64_C(X)
659#if !defined A_IMAX_MAX
660#define A_IMAX_MAX A_I64_MAX
662#if !defined A_IMAX_MIN
663#define A_IMAX_MIN A_I64_MIN
666#define a_imax_c(x) a_cast_s(a_imax, x)
667#define a_imax_(_, x) a_cast_s(a_imax _, x)
675#define A_UMAX_C(X) A_U64_C(X)
677#if !defined A_UMAX_MAX
678#define A_UMAX_MAX A_U64_MAX
681#define a_umax_c(x) a_cast_s(a_umax, x)
682#define a_umax_(_, x) a_cast_s(a_umax _, x)
687#define A_PRIMAX A_PRI64
690#define A_SCNMAX A_SCN64
693#if !defined A_IPTR && (A_SIZE_POINTER == 2)
695#elif !defined A_IPTR && (A_SIZE_POINTER == 4)
700#if !defined A_IPTR_MAX && (A_SIZE_POINTER == 2)
701#define A_IPTR_MAX A_I16_MAX
702#elif !defined A_IPTR_MAX && (A_SIZE_POINTER == 4)
703#define A_IPTR_MAX A_I32_MAX
704#elif !defined A_IPTR_MAX
705#define A_IPTR_MAX A_I64_MAX
707#if !defined A_IPTR_MIN && (A_SIZE_POINTER == 2)
708#define A_IPTR_MIN A_I16_MIN
709#elif !defined A_IPTR_MIN && (A_SIZE_POINTER == 4)
710#define A_IPTR_MIN A_I32_MIN
711#elif !defined A_IPTR_MIN
712#define A_IPTR_MIN A_I64_MIN
715#define a_iptr_c(x) a_cast_s(a_iptr, x)
716#define a_iptr_(_, x) a_cast_s(a_iptr _, x)
720#if !defined A_UPTR && (A_SIZE_POINTER == 2)
722#elif !defined A_UPTR && (A_SIZE_POINTER == 4)
727#if !defined A_UPTR_MAX && (A_SIZE_POINTER == 2)
728#define A_UPTR_MAX A_U16_MAX
729#elif !defined A_UPTR_MAX && (A_SIZE_POINTER == 4)
730#define A_UPTR_MAX A_U32_MAX
731#elif !defined A_UPTR_MAX
732#define A_UPTR_MAX A_U64_MAX
735#define a_uptr_c(x) a_cast_s(a_uptr, x)
736#define a_uptr_(_, x) a_cast_s(a_uptr _, x)
740#if !defined A_PRIPTR && (A_SIZE_POINTER == 2)
741#define A_PRIPTR A_PRI16
742#elif !defined A_PRIPTR && (A_SIZE_POINTER == 4)
743#define A_PRIPTR A_PRI32
744#elif !defined A_PRIPTR
745#define A_PRIPTR A_PRI64
747#if !defined A_SCNPTR && (A_SIZE_POINTER == 2)
748#define A_SCNPTR A_SCN16
749#elif !defined A_SCNPTR && (A_SIZE_POINTER == 4)
750#define A_SCNPTR A_SCN32
751#elif !defined A_SCNPTR
752#define A_SCNPTR A_SCN64
756#define A_DIFF ptrdiff_t
758#if !defined A_DIFF_MAX && defined(__PTRDIFF_MAX__)
759#define A_DIFF_MAX __PTRDIFF_MAX__
760#elif !defined A_DIFF_MAX && (A_SIZE_POINTER == 2)
761#define A_DIFF_MAX A_I16_MAX
762#elif !defined A_DIFF_MAX && (A_SIZE_POINTER == 4)
763#define A_DIFF_MAX A_I32_MAX
764#elif !defined A_DIFF_MAX
765#define A_DIFF_MAX A_I64_MAX
767#if !defined A_DIFF_MIN && defined(__PTRDIFF_MAX__)
768#define A_DIFF_MIN (~__PTRDIFF_MAX__)
769#elif !defined A_DIFF_MIN && (A_SIZE_POINTER == 2)
770#define A_DIFF_MIN A_I16_MIN
771#elif !defined A_DIFF_MIN && (A_SIZE_POINTER == 4)
772#define A_DIFF_MIN A_I32_MIN
773#elif !defined A_DIFF_MIN
774#define A_DIFF_MIN A_I64_MIN
777#define a_diff_c(x) a_cast_s(a_diff, x)
778#define a_diff_(_, x) a_cast_s(a_diff _, x)
782#if defined(__STDC_VERSION__) && (__STDC_VERSION__ > 199900L) || \
783 defined(__cplusplus) && (__cplusplus > 201100L) || A_PREREQ_MSVC(19, 0)
791#if !defined A_PRIt && (A_SIZE_POINTER == 2)
792#define A_PRIt A_PRI16
793#elif !defined A_PRIt && (A_SIZE_POINTER == 4)
794#define A_PRIt A_PRI32
796#define A_PRIt A_PRI64
798#if !defined A_SCNt && (A_SIZE_POINTER == 2)
799#define A_SCNt A_SCN16
800#elif !defined A_SCNt && (A_SIZE_POINTER == 4)
801#define A_SCNt A_SCN32
803#define A_SCNt A_SCN64
810#if !defined A_SIZE_MAX && defined(__SIZE_MAX__)
811#define A_SIZE_MAX __SIZE_MAX__
812#elif !defined A_SIZE_MAX && (A_SIZE_POINTER == 2)
813#define A_SIZE_MAX A_U16_MAX
814#elif !defined A_SIZE_MAX && (A_SIZE_POINTER == 4)
815#define A_SIZE_MAX A_U32_MAX
816#elif !defined A_SIZE_MAX
817#define A_SIZE_MAX A_U64_MAX
820#define a_size_c(x) a_cast_s(a_size, x)
821#define a_size_(_, x) a_cast_s(a_size _, x)
825#if defined(__STDC_VERSION__) && (__STDC_VERSION__ > 199900L) || \
826 defined(__cplusplus) && (__cplusplus > 201100L) || A_PREREQ_MSVC(19, 0)
834#if !defined A_PRIz && (A_SIZE_POINTER == 2)
835#define A_PRIz A_PRI16
836#elif !defined A_PRIz && (A_SIZE_POINTER == 4)
837#define A_PRIz A_PRI32
839#define A_PRIz A_PRI64
841#if !defined A_SCNz && (A_SIZE_POINTER == 2)
842#define A_SCNz A_SCN16
843#elif !defined A_SCNz && (A_SIZE_POINTER == 4)
844#define A_SCNz A_SCN32
846#define A_SCNz A_SCN64
850#define A_F16_NNAN A_U16_C(0xFE00)
851#define A_F16_PNAN A_U16_C(0x7E00)
852#define A_F16_NINF A_U16_C(0xFC00)
853#define A_F16_PINF A_U16_C(0x7C00)
856#define A_F32_C(X) A_CAST_2(X, F)
857#define A_F32_F(F) A_CAST_2(F, f)
858#define A_F32_DIG FLT_DIG
859#define A_F32_EPSILON FLT_EPSILON
860#define A_F32_MANT_DIG FLT_MANT_DIG
861#define A_F32_MAX FLT_MAX
862#define A_F32_MAX_10_EXP FLT_MAX_10_EXP
863#define A_F32_MAX_EXP FLT_MAX_EXP
864#define A_F32_MIN FLT_MIN
865#define A_F32_MIN_10_EXP FLT_MIN_10_EXP
866#define A_F32_MIN_EXP FLT_MIN_EXP
867#define A_F32_INF a_cast_s(a_f32, A_F64_INF)
868#define A_F32_NAN (A_F32_C(0.0) * A_F32_INF)
869#define A_F32_NNAN A_U32_C(0xFFC00000)
870#define A_F32_PNAN A_U32_C(0x7FC00000)
871#define A_F32_NINF A_U32_C(0xFF800000)
872#define A_F32_PINF A_U32_C(0x7F800000)
874#define a_f32_c(x) a_cast_s(a_f32, x)
875#define a_f32_(_, x) a_cast_s(a_f32 _, x)
882#define A_F64_DIG DBL_DIG
883#define A_F64_EPSILON DBL_EPSILON
884#define A_F64_MANT_DIG DBL_MANT_DIG
885#define A_F64_MAX DBL_MAX
886#define A_F64_MAX_10_EXP DBL_MAX_10_EXP
887#define A_F64_MAX_EXP DBL_MAX_EXP
888#define A_F64_MIN DBL_MIN
889#define A_F64_MIN_10_EXP DBL_MIN_10_EXP
890#define A_F64_MIN_EXP DBL_MIN_EXP
891#define A_F64_INF (DBL_MAX * DBL_MAX)
892#define A_F64_NAN (A_F64_C(0.0) * A_F64_INF)
893#define A_F64_NNAN A_U64_C(0xFFF8000000000000)
894#define A_F64_PNAN A_U64_C(0x7FF8000000000000)
895#define A_F64_NINF A_U64_C(0xFFF0000000000000)
896#define A_F64_PINF A_U64_C(0x7FF0000000000000)
898#define a_f64_c(x) a_cast_s(a_f64, x)
899#define a_f64_(_, x) a_cast_s(a_f64 _, x)
912#if !defined A_FLOAT_TYPE
913#if !defined A_SIZE_FLOAT
914#define A_FLOAT_TYPE A_FLOAT_DOUBLE
916#define A_FLOAT_TYPE A_SIZE_FLOAT
919#define A_FLOAT_SINGLE 0x04
920#define A_FLOAT_DOUBLE 0x08
921#define A_FLOAT_EXTEND 0x10
923#elif A_FLOAT_TYPE + 0 == A_FLOAT_SINGLE
927#define A_FLOAT_DIG FLT_DIG
928#define A_FLOAT_EPSILON FLT_EPSILON
929#define A_FLOAT_MANT_DIG FLT_MANT_DIG
930#define A_FLOAT_MAX FLT_MAX
931#define A_FLOAT_MAX_10_EXP FLT_MAX_10_EXP
932#define A_FLOAT_MAX_EXP FLT_MAX_EXP
933#define A_FLOAT_MIN FLT_MIN
934#define A_FLOAT_MIN_10_EXP FLT_MIN_10_EXP
935#define A_FLOAT_MIN_EXP FLT_MIN_EXP
936#define A_FLOAT_C(X) A_CAST_2(X, F)
937#define A_FLOAT_F(F) A_CAST_2(F, f)
941#elif A_FLOAT_TYPE + 0 == A_FLOAT_DOUBLE
944#define A_FLOAT double
945#define A_FLOAT_DIG DBL_DIG
946#define A_FLOAT_EPSILON DBL_EPSILON
947#define A_FLOAT_MANT_DIG DBL_MANT_DIG
948#define A_FLOAT_MAX DBL_MAX
949#define A_FLOAT_MAX_10_EXP DBL_MAX_10_EXP
950#define A_FLOAT_MAX_EXP DBL_MAX_EXP
951#define A_FLOAT_MIN DBL_MIN
952#define A_FLOAT_MIN_10_EXP DBL_MIN_10_EXP
953#define A_FLOAT_MIN_EXP DBL_MIN_EXP
954#define A_FLOAT_C(X) X
955#define A_FLOAT_F(F) F
957#define A_FLOAT_SCN "l"
959#elif A_FLOAT_TYPE + 0 == A_FLOAT_EXTEND
962#define A_FLOAT long double
963#define A_FLOAT_DIG LDBL_DIG
964#define A_FLOAT_EPSILON LDBL_EPSILON
965#define A_FLOAT_MANT_DIG LDBL_MANT_DIG
966#define A_FLOAT_MAX LDBL_MAX
967#define A_FLOAT_MAX_10_EXP LDBL_MAX_10_EXP
968#define A_FLOAT_MAX_EXP LDBL_MAX_EXP
969#define A_FLOAT_MIN LDBL_MIN
970#define A_FLOAT_MIN_10_EXP LDBL_MIN_10_EXP
971#define A_FLOAT_MIN_EXP LDBL_MIN_EXP
972#define A_FLOAT_C(X) A_CAST_2(X, L)
973#define A_FLOAT_F(F) A_CAST_2(F, l)
974#define A_FLOAT_PRI "L"
975#define A_FLOAT_SCN "L"
978#error unsupported precision
981#define A_FLOAT_INF a_cast_s(A_FLOAT, A_F64_INF)
982#define A_FLOAT_NAN (A_FLOAT_C(0.0) * A_FLOAT_INF)
1000#define a_float_c(x) a_cast_s(a_float, x)
1001#define a_float_(_, x) a_cast_s(a_float _, x)
1016#if defined(A_HAVE_LONG_LONG_TYPE)
1040#if defined(A_FLOAT_TYPE) && (A_FLOAT_TYPE + 0 < A_FLOAT_EXTEND)
1048#define A_SQ(x) ((x) * (x))
1053#define A_ABS(x) ((x) < 0 ? -(x) : (x))
1057#define A_ABS_(f, g) ((f) < (g) ? (g) - (f) : (f) - (g))
1062#define A_MIN(x, y) (((x) < (y)) ? (x) : (y))
1067#define A_MAX(x, y) (((x) > (y)) ? (x) : (y))
1072#define A_SGN(x) ((0 < (x)) - ((x) < 0))
1076#define A_SGN_(f, g) (((f) > (g)) - ((f) < (g)))
1081#define A_SAT(x, min, max) ((min) < (x) ? (x) < (max) ? (x) : (max) : (min))
1087#define A_LEN(a) (sizeof(a) / sizeof(*(a)))
1094#if defined(offsetof)
1095#define a_offsetof(type, member) offsetof(type, member)
1097#define a_offsetof(type, member) a_cast_r(a_size, &a_cast_r(type *, 0)->member)
1106#define a_container_of(ptr, type, member) a_cast_r(type *, a_cast_r(a_uptr, ptr) - a_offsetof(type, member))
1111#define a_size_down(a, n) (a_cast_s(a_size, n) & ~a_cast_s(a_size, (a) - 1))
1116#define a_size_up(a, n) ((a_cast_s(a_size, n) + (a) - 1) & ~a_cast_s(a_size, (a) - 1))
1121#define a_align_down(a, p) a_cast_r(void *, a_cast_r(a_uptr, p) & ~a_cast_s(a_uptr, (a) - 1))
1126#define a_align_up(a, p) a_cast_r(void *, (a_cast_r(a_uptr, p) + (a) - 1) & ~a_cast_s(a_uptr, (a) - 1))
1134#define a_forenum(I, i, n) for (I i = 0; i < (n); ++i)
1135#define A_FORENUM(I, i, n) for (i = 0; i < a_cast_s(I, n); ++i)
1143#define a_forenum_reverse(I, i, n) for (I i = (n); i-- > 0;)
1144#define A_FORENUM_REVERSE(I, i, n) for (i = a_cast_s(I, n); i-- > 0;)
1154#define a_foreach(T, S, it, ptr, num) \
1155 for (T S it = a_cast_s(T S, ptr), S it##_ = it + (num); it < it##_; ++it)
1156#define A_FOREACH(T, it, at, ptr, num) \
1157 for (it = a_cast_s(T, ptr), at = it + (num); it < at; ++it)
1159#define a_forsafe(T, S, it, ptr, num) \
1160 for (T S it = a_cast_s(T S, ptr), S it##_ = (num) ? it + (num) : it; it < it##_; ++it)
1161#define A_FORSAFE(T, it, at, ptr, num) \
1162 for (it = a_cast_s(T, ptr), at = (num) ? it + (num) : it; it < at; ++it)
1172#define a_foreach_reverse(T, S, it, ptr, num) \
1173 for (T S it##_ = a_cast_s(T S, ptr) - 1, S it = it##_ + (num); it > it##_; --it)
1174#define A_FOREACH_REVERSE(T, it, at, ptr, num) \
1175 for (at = a_cast_s(T, ptr) - 1, it = at + (num); it > at; --it)
1177#define a_forsafe_reverse(T, S, it, ptr, num) \
1178 for (T S it##_ = (num) ? a_cast_s(T S, ptr) - 1 : a_cast_s(T S, ptr), \
1179 S it = (num) ? it##_ + (num) : it##_; \
1181#define A_FORSAFE_REVERSE(T, it, at, ptr, num) \
1182 for (at = (num) ? a_cast_s(T, ptr) - 1 : a_cast_s(T, ptr), \
1183 it = (num) ? at + (num) : at; \
1194#define a_iterate(T, S, it, ptr, end) \
1195 for (T S it = a_cast_s(T S, ptr), S it##_ = a_cast_s(T S, end); it < it##_; ++it)
1196#define A_ITERATE(T, it, at, ptr, end) \
1197 for (it = a_cast_s(T, ptr), at = a_cast_s(T, end); it < at; ++it)
1207#define a_iterate_reverse(T, S, it, ptr, end) \
1208 for (T S it = a_cast_s(T S, end) - 1, S it##_ = a_cast_s(T S, ptr) - 1; it > it##_; --it)
1209#define A_ITERATE_REVERSE(T, it, at, ptr, end) \
1210 for (it = a_cast_s(T, end) - 1, at = a_cast_s(T, ptr) - 1; it > at; --it)
1222#if defined(__cplusplus)
1225#if defined(LIBA_A_C)
1227#define A_INTERN A_INLINE
1235#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1238#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1241 x = a_cast_s(
a_u8, (x >> 4) | (x << 4));
1242 x = a_cast_s(
a_u8, ((x & 0xCC) >> 2) | ((x & 0x33) << 2));
1243 x = a_cast_s(
a_u8, ((x & 0xAA) >> 1) | ((x & 0x55) << 1));
1253#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1256#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1259 x = a_cast_s(
a_u16, (x >> 8) | (x << 8));
1260 x = a_cast_s(
a_u16, ((x & 0xF0F0) >> 4) | ((x & 0x0F0F) << 4));
1261 x = a_cast_s(
a_u16, ((x & 0xCCCC) >> 2) | ((x & 0x3333) << 2));
1262 x = a_cast_s(
a_u16, ((x & 0xAAAA) >> 1) | ((x & 0x5555) << 1));
1266#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1267A_EXTERN A_NONULL((1))
a_u16 a_u16_getl(
void const *b);
1269#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1270A_INTERN A_NONULL((1))
a_u16 a_u16_getl(
void const *b)
1273 return a_cast_s(
a_u16, (p[0] << 0) | (p[1] << 8));
1276#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1277A_EXTERN A_NONULL((1))
a_u16 a_u16_getb(
void const *b);
1279#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1280A_INTERN A_NONULL((1))
a_u16 a_u16_getb(
void const *b)
1283 return a_cast_s(
a_u16, (p[1] << 0) | (p[0] << 8));
1286#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1287A_EXTERN A_NONULL((1)) void a_u16_setl(
void *b,
a_u16 x);
1289#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1290A_INTERN A_NONULL((1)) void a_u16_setl(
void *b,
a_u16 x)
1293 p[0] = a_cast_s(
a_byte, x >> 0);
1294 p[1] = a_cast_s(
a_byte, x >> 8);
1297#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1298A_EXTERN A_NONULL((1)) void a_u16_setb(
void *b,
a_u16 x);
1300#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1301A_INTERN A_NONULL((1)) void a_u16_setb(
void *b,
a_u16 x)
1304 p[0] = a_cast_s(
a_byte, x >> 8);
1305 p[1] = a_cast_s(
a_byte, x >> 0);
1314#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1317#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1320 x = (x >> 16) | (x << 16);
1321 x = ((x & 0xFF00FF00) >> 8) | ((x & 0x00FF00FF) << 8);
1322 x = ((x & 0xF0F0F0F0) >> 4) | ((x & 0x0F0F0F0F) << 4);
1323 x = ((x & 0xCCCCCCCC) >> 2) | ((x & 0x33333333) << 2);
1324 x = ((x & 0xAAAAAAAA) >> 1) | ((x & 0x55555555) << 1);
1328#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1329A_EXTERN A_NONULL((1))
a_u32 a_u32_getl(
void const *b);
1331#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1332A_INTERN A_NONULL((1))
a_u32 a_u32_getl(
void const *b)
1335 return (a_cast_s(
a_u32, p[0]) << 0x00) |
1336 (a_cast_s(
a_u32, p[1]) << 0x08) |
1337 (a_cast_s(
a_u32, p[2]) << 0x10) |
1338 (a_cast_s(
a_u32, p[3]) << 0x18);
1341#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1342A_EXTERN A_NONULL((1))
a_u32 a_u32_getb(
void const *b);
1344#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1345A_INTERN A_NONULL((1))
a_u32 a_u32_getb(
void const *b)
1348 return (a_cast_s(
a_u32, p[0]) << 0x18) |
1349 (a_cast_s(
a_u32, p[1]) << 0x10) |
1350 (a_cast_s(
a_u32, p[2]) << 0x08) |
1351 (a_cast_s(
a_u32, p[3]) << 0x00);
1354#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1355A_EXTERN A_NONULL((1)) void a_u32_setl(
void *b,
a_u32 x);
1357#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1358A_INTERN A_NONULL((1)) void a_u32_setl(
void *b,
a_u32 x)
1361 p[0] = a_cast_s(
a_byte, x >> 0x00);
1362 p[1] = a_cast_s(
a_byte, x >> 0x08);
1363 p[2] = a_cast_s(
a_byte, x >> 0x10);
1364 p[3] = a_cast_s(
a_byte, x >> 0x18);
1367#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1368A_EXTERN A_NONULL((1)) void a_u32_setb(
void *b,
a_u32 x);
1370#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1371A_INTERN A_NONULL((1)) void a_u32_setb(
void *b,
a_u32 x)
1374 p[0] = a_cast_s(
a_byte, x >> 0x18);
1375 p[1] = a_cast_s(
a_byte, x >> 0x10);
1376 p[2] = a_cast_s(
a_byte, x >> 0x08);
1377 p[3] = a_cast_s(
a_byte, x >> 0x00);
1386#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1389#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1392 x = (x >> 32) | (x << 32);
1393 x = ((x & 0xFFFF0000FFFF0000) >> 0x10) | ((x & 0x0000FFFF0000FFFF) << 0x10);
1394 x = ((x & 0xFF00FF00FF00FF00) >> 0x08) | ((x & 0x00FF00FF00FF00FF) << 0x08);
1395 x = ((x & 0xF0F0F0F0F0F0F0F0) >> 0x04) | ((x & 0x0F0F0F0F0F0F0F0F) << 0x04);
1396 x = ((x & 0xCCCCCCCCCCCCCCCC) >> 0x02) | ((x & 0x3333333333333333) << 0x02);
1397 x = ((x & 0xAAAAAAAAAAAAAAAA) >> 0x01) | ((x & 0x5555555555555555) << 0x01);
1401#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1402A_EXTERN A_NONULL((1))
a_u64 a_u64_getl(
void const *b);
1404#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1405A_INTERN A_NONULL((1))
a_u64 a_u64_getl(
void const *b)
1408 return (a_cast_s(
a_u64, p[0]) << 0x00) |
1409 (a_cast_s(
a_u64, p[1]) << 0x08) |
1410 (a_cast_s(
a_u64, p[2]) << 0x10) |
1411 (a_cast_s(
a_u64, p[3]) << 0x18) |
1412 (a_cast_s(
a_u64, p[4]) << 0x20) |
1413 (a_cast_s(
a_u64, p[5]) << 0x28) |
1414 (a_cast_s(
a_u64, p[6]) << 0x30) |
1415 (a_cast_s(
a_u64, p[7]) << 0x38);
1418#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1419A_EXTERN A_NONULL((1))
a_u64 a_u64_getb(
void const *b);
1421#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1422A_INTERN A_NONULL((1))
a_u64 a_u64_getb(
void const *b)
1425 return (a_cast_s(
a_u64, p[0]) << 0x38) |
1426 (a_cast_s(
a_u64, p[1]) << 0x30) |
1427 (a_cast_s(
a_u64, p[2]) << 0x28) |
1428 (a_cast_s(
a_u64, p[3]) << 0x20) |
1429 (a_cast_s(
a_u64, p[4]) << 0x18) |
1430 (a_cast_s(
a_u64, p[5]) << 0x10) |
1431 (a_cast_s(
a_u64, p[6]) << 0x08) |
1432 (a_cast_s(
a_u64, p[7]) << 0x00);
1435#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1436A_EXTERN A_NONULL((1)) void a_u64_setl(
void *b,
a_u64 x);
1438#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1439A_INTERN A_NONULL((1)) void a_u64_setl(
void *b,
a_u64 x)
1442 p[0] = a_cast_s(
a_byte, x >> 0x00);
1443 p[1] = a_cast_s(
a_byte, x >> 0x08);
1444 p[2] = a_cast_s(
a_byte, x >> 0x10);
1445 p[3] = a_cast_s(
a_byte, x >> 0x18);
1446 p[4] = a_cast_s(
a_byte, x >> 0x20);
1447 p[5] = a_cast_s(
a_byte, x >> 0x28);
1448 p[6] = a_cast_s(
a_byte, x >> 0x30);
1449 p[7] = a_cast_s(
a_byte, x >> 0x38);
1452#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1453A_EXTERN A_NONULL((1)) void a_u64_setb(
void *b,
a_u64 x);
1455#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1456A_INTERN A_NONULL((1)) void a_u64_setb(
void *b,
a_u64 x)
1459 p[0] = a_cast_s(
a_byte, x >> 0x38);
1460 p[1] = a_cast_s(
a_byte, x >> 0x30);
1461 p[2] = a_cast_s(
a_byte, x >> 0x28);
1462 p[3] = a_cast_s(
a_byte, x >> 0x20);
1463 p[4] = a_cast_s(
a_byte, x >> 0x18);
1464 p[5] = a_cast_s(
a_byte, x >> 0x10);
1465 p[6] = a_cast_s(
a_byte, x >> 0x08);
1466 p[7] = a_cast_s(
a_byte, x >> 0x00);
1477A_EXTERN A_NONULL((1, 2)) void *
a_copy(
void *__restrict dst,
void const *__restrict src,
a_size siz);
1486A_EXTERN A_NONULL((1, 2))
void *
a_move(
void *dst,
void const *src,
a_size siz);
1529#if defined(LIBA_A_C)
1531#define A_INTERN static A_INLINE
1533#if defined(__cplusplus)
1538#define A_ALLOC(alloc, addr, size) void *alloc(void *addr, a_size size)
1539#define a_new(T, ptr, num) a_cast_s(T *, a_alloc(ptr, sizeof(T) * (num)))
1540#define a_die(ptr) a_alloc(ptr, 0)
double a_float
compiler built-in floating-point number type
Definition a.h:1003
#define A_FLOAT
floating-point number stored using double
Definition a.h:944
float a_f32
single precision floating point type. Matches IEEE-754 binary32 format if supported.
Definition a.h:877
a_u64 a_u64_rev(a_u64 x)
reverse the bits in a 64-bit unsigned integer
signed char a_i8
signed integer type with width of exactly 8 bits
Definition a.h:427
unsigned long a_u64
unsigned integer type with width of exactly 64 bits
Definition a.h:627
long a_long
signed integer type is guaranteed to be at least 32 bits
Definition a.h:363
unsigned int a_uint
unsigned integer type is guaranteed to be at least 16 bits
Definition a.h:337
short a_i16
signed integer type with width of exactly 16 bits
Definition a.h:469
void * a_fill(void *ptr, a_size siz, int val)
fill a buffer with a character
void a_swap(void *lhs, void *rhs, a_size siz)
swap two different memory blocks of the same size
unsigned char a_u8
unsigned integer type with width of exactly 8 bits
Definition a.h:442
char a_c8
type for character representation
Definition a.h:409
long a_imax
maximum-width signed integer type
Definition a.h:669
a_u8 a_u8_rev(a_u8 x)
reverse the bits in an 8-bit unsigned integer
void * a_copy(void *__restrict dst, void const *__restrict src, a_size siz)
copy one buffer to another
void * a_zero(void *ptr, a_size siz)
fill a buffer with zero
void *(* a_alloc)(void *addr, a_size size)
allocation function pointer
Definition a.h:1519
long a_i64
signed integer type with width of exactly 64 bits
Definition a.h:589
ptrdiff_t a_diff
signed integer type returned when subtracting two pointers
Definition a.h:780
unsigned long a_umax
maximum-width unsigned integer type
Definition a.h:684
unsigned short a_ushrt
unsigned integer type is guaranteed to be at least 16 bits
Definition a.h:354
short a_shrt
signed integer type is guaranteed to be at least 16 bits
Definition a.h:346
unsigned long a_uptr
unsigned integer type capable of holding a pointer to void
Definition a.h:738
void * a_alloc_(void *addr, a_size size)
default allocation function
void * a_move(void *dst, void const *src, a_size siz)
move one buffer to another
long a_iptr
signed integer type capable of holding a pointer to void
Definition a.h:718
unsigned long a_ulong
unsigned integer type is guaranteed to be at least 32 bits
Definition a.h:371
a_u16 a_u16_rev(a_u16 x)
reverse the bits in a 16-bit unsigned integer
a_u32 a_u32_rev(a_u32 x)
reverse the bits in a 32-bit unsigned integer
unsigned short a_u16
unsigned integer type with width of exactly 16 bits
Definition a.h:486
double a_f64
double precision floating point type. Matches IEEE-754 binary64 format if supported.
Definition a.h:901
bool a_bool
type, capable of holding one of the two values: 1 and 0
Definition a.h:320
long a_i32
signed integer type with width of exactly 32 bits
Definition a.h:519
unsigned char a_byte
type for unsigned character representation
Definition a.h:400
unsigned long a_u32
unsigned integer type with width of exactly 32 bits
Definition a.h:538
size_t a_size
unsigned integer type returned by the sizeof operator
Definition a.h:823
int a_int
signed integer type is guaranteed to be at least 16 bits
Definition a.h:329
@ A_SUCCESS
Definition a.h:1217
@ A_FAILURE
Definition a.h:1218
@ A_INVALID
Definition a.h:1219