liba 0.1.15
An algorithm library based on C/C++
 
Loading...
Searching...
No Matches
a.h
Go to the documentation of this file.
1
5
6#ifndef LIBA_A_H
7#define LIBA_A_H
8
9#if defined(A_HAVE_H)
10#include A_HAVE_H
11#endif /* A_HAVE_H */
12
14
15#if !defined __has_attribute
16#define __has_attribute(x) 0
17#endif /* __has_attribute */
18#if !defined __has_builtin
19#define __has_builtin(x) 0
20#endif /* __has_builtin */
21#if !defined __has_feature
22#define __has_feature(x) 0
23#endif /* __has_feature */
24#if !defined __has_include
25#define __has_include(x) 0
26#endif /* __has_include */
27#if !defined __has_warning
28#define __has_warning(x) 0
29#endif /* __has_warning */
30#if !defined A_HAVE_INLINE
31#define A_HAVE_INLINE 1
32#elif A_HAVE_INLINE + 0 < 1
33#undef A_HAVE_INLINE
34#endif /* A_HAVE_INLINE */
35#if defined(__GNUC__) || \
36 defined(__clang__)
37#pragma GCC system_header
38#endif /* __GNUC__ */
39
40#if defined(__MINGW32__)
41#undef __USE_MINGW_ANSI_STDIO
42#define __USE_MINGW_ANSI_STDIO 1
43#endif /* __MINGW32__ */
44
45/* https://en.wikipedia.org/wiki/Microsoft_Visual_C++ */
46#if defined(_MSC_VER)
47#define A_PREREQ_MSVC(maj, min) (_MSC_VER >= (maj * 100 + min))
48#else /* !_MSC_VER */
49#define A_PREREQ_MSVC(maj, min) 0
50#endif /* _MSC_VER */
51
52/* https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html */
53#if defined(__GNUC__) && defined(__GNUC_MINOR__)
54#define A_PREREQ_GNUC(maj, min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
55#else /* !__GNUC__ */
56#define A_PREREQ_GNUC(maj, min) 0
57#endif /* __GNUC__ */
58
59/* https://clang.llvm.org/docs/LanguageExtensions.html */
60#if defined(__clang_major__) && defined(__clang_minor__)
61#define A_PREREQ_LLVM(maj, min) ((__clang_major__ << 16) + __clang_minor__ >= ((maj) << 16) + (min))
62#else /* !__clang__ */
63#define A_PREREQ_LLVM(maj, min) 0
64#endif /* __clang__ */
65
66#if !defined A_FUNC
67#if defined(_MSC_VER)
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__
74#else /* !__func__ */
75#define A_FUNC __FUNCTION__
76#endif /* __func__ */
77#endif /* A_FUNC */
78
79#if defined(__STDC_VERSION__) && (__STDC_VERSION__ > 199900L) || \
80 defined(__cplusplus) && (__cplusplus > 201100L) || A_PREREQ_MSVC(18, 0)
81
82#if !defined A_HAVE_LONG_LONG_TYPE
83#define A_HAVE_LONG_LONG_TYPE 1
84#endif /* A_HAVE_LONG_LONG_TYPE */
85
86#endif /* C > 199900 or C++ > 201100 */
87#if defined(A_HAVE_LONG_LONG_TYPE) && (A_HAVE_LONG_LONG_TYPE + 0 < 1)
88#undef A_HAVE_LONG_LONG_TYPE
89#endif /* A_HAVE_LONG_LONG_TYPE */
90
91#if defined(__cplusplus) && (__cplusplus > 201100L)
92
93#if !defined A_HAVE_NULLPTR
94#define A_HAVE_NULLPTR 1
95#endif /* A_HAVE_NULLPTR */
96
97#endif /* C++ > 201100 */
98#if defined(A_HAVE_NULLPTR) && (A_HAVE_NULLPTR + 0 < 1)
99#undef A_HAVE_NULLPTR
100#endif /* A_HAVE_NULLPTR */
101
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)
105#else /* !likely */
106#define A_UNLIKELY(x) (!!(x))
107#define A_LIKELY(x) (!!(x))
108#endif /* likely */
109
110#if defined(_WIN32) || defined(__CYGWIN__)
111#define A_DECLSPEC(x) __declspec(x)
112#else /* !__declspec */
113#define A_DECLSPEC(x)
114#endif /* __declspec */
115
116#if defined(__GNUC__) || defined(__clang__)
117#define A_ATTRIBUTE(x) __attribute__(x)
118#else /* !__attribute__ */
119#define A_ATTRIBUTE(x)
120#endif /* __attribute__ */
121
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)
127#define A_ASSUME(x) \
128 do { \
129 if (!(x)) { __builtin_unreachable(); } \
130 } while (0)
131#elif defined(_MSC_VER)
132#define A_ASSUME(x) __assume(x)
133#else /* !assume */
134#define A_ASSUME(x) (void)0
135#endif /* assume */
136
137/* attribute nonnull */
138#if A_PREREQ_GNUC(3, 3) || __has_attribute(__nonnull__)
139#define A_NONULL(x) __attribute__((__nonnull__ x))
140#else /* !nonnull */
141#define A_NONULL(x)
142#endif /* nonnull */
143
144/* attribute format */
145#if A_PREREQ_GNUC(2, 4) || __has_attribute(__format__)
146#define A_FORMAT(_, a, b) __attribute__((__format__(_, a, b)))
147#else /* !format */
148#define A_FORMAT(_, a, b)
149#endif /* format */
150
151/* attribute fallthrough */
152#if A_PREREQ_GNUC(7, 0) || __has_attribute(__fallthrough__)
153#define A_FALLTHROUGH __attribute__((__fallthrough__))
154#else /* !fallthrough */
155#define A_FALLTHROUGH (void)0
156#endif /* fallthrough */
157
158/* attribute deprecated */
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)
163#else /* !deprecated */
164#define A_DEPRECATED
165#endif /* deprecated */
166
167/* attribute always inline */
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
172#else /* !_MSC_VER */
173#define A_INLINE __inline
174#endif /* _MSC_VER */
175#if !defined A_INTERN
176#define A_INTERN static A_INLINE
177#endif /* A_INTERN */
178
179/* attribute visibility */
180#if defined(_WIN32) || defined(__CYGWIN__)
181#define A_EXPORT __declspec(dllexport)
182#define A_IMPORT __declspec(dllimport)
183#define A_HIDDEN
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")))
188#else /* !visibility */
189#define A_EXPORT
190#define A_IMPORT
191#define A_HIDDEN
192#endif /* visibility */
193#if defined(A_EXPORTS)
194#define A_PUBLIC A_EXPORT
195#elif defined(A_IMPORTS)
196#define A_PUBLIC A_IMPORT
197#else /* !A_PUBLIC */
198#define A_PUBLIC
199#endif /* A_PUBLIC */
200
201#if !defined A_EXTERN
202#define A_EXTERN A_PUBLIC extern
203#endif /* A_EXTERN */
204#if !defined __cplusplus
205#define A_EXTERN_C
206#define A_EXTERN_C_ENTER
207#define A_EXTERN_C_LEAVE
208#else /* !__cplusplus */
209#define A_EXTERN_C extern "C"
210#define A_EXTERN_C_ENTER extern "C" {
211#define A_EXTERN_C_LEAVE }
212#endif /* __cplusplus */
213
215
216#include <stddef.h>
217#include <limits.h>
218#include <float.h>
219
224
229#if defined(__ORDER_LITTLE_ENDIAN__)
230#define A_ORDER_LITTLE __ORDER_LITTLE_ENDIAN__
231#else /* !__ORDER_LITTLE_ENDIAN__ */
232#define A_ORDER_LITTLE 1234
233#endif /* __ORDER_LITTLE_ENDIAN__ */
238#if defined(__ORDER_BIG_ENDIAN__)
239#define A_ORDER_BIG __ORDER_BIG_ENDIAN__
240#else /* !__ORDER_BIG_ENDIAN__ */
241#define A_ORDER_BIG 4321
242#endif /* __ORDER_BIG_ENDIAN__ */
243#if !defined A_BYTE_ORDER
248#if defined(__BYTE_ORDER__)
249#define A_BYTE_ORDER __BYTE_ORDER__
250#else /* !__BYTE_ORDER__ */
251#define A_BYTE_ORDER 1234
252#endif /* __BYTE_ORDER__ */
253#endif /* A_BYTE_ORDER */
254
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
264#else /* !__SIZEOF_POINTER__ */
265#define A_SIZE_POINTER 4
266#endif /* __SIZEOF_POINTER__ */
267#endif /* A_SIZE_POINTER */
268
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)]))
273
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)
279#else /* !__cplusplus */
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))
284#endif /* __cplusplus */
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
288
289#if defined(__cplusplus) && defined(A_HAVE_NULLPTR)
290#define A_NULL nullptr
291#else /* !__cplusplus */
292#define A_NULL NULL
293#endif /* __cplusplus */
295#define a_void_c(x) a_cast_s(void, x)
296#define a_void_(_, x) a_cast_s(void _, x)
298#define a_void void
299
300#if defined(__cplusplus)
301#define A_TRUE true
302#define A_FALSE false
303#if !defined A_BOOL
304#define A_BOOL bool
305#endif /* A_BOOL */
306#else /* !__cplusplus */
307#define A_TRUE 1
308#define A_FALSE 0
309#if !defined A_BOOL
310#if defined(__STDC_VERSION__) || A_PREREQ_MSVC(18, 0)
311#define A_BOOL _Bool
312#else /* !__STDC_VERSION__ */
313#define A_BOOL unsigned char
314#endif /* __STDC_VERSION__ */
315#endif /* A_BOOL */
316#endif /* __cplusplus */
318#define a_bool_c(x) (!!(x))
320typedef A_BOOL a_bool;
321
322#define A_INT int
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)
329typedef A_INT a_int;
330
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)
337typedef A_UINT a_uint;
338
339#define A_SHRT short
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)
346typedef A_SHRT a_shrt;
347
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)
354typedef A_USHRT a_ushrt;
355
356#define A_LONG long
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)
363typedef A_LONG a_long;
364
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)
371typedef A_ULONG a_ulong;
372
373#if defined(A_HAVE_LONG_LONG_TYPE)
374
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;
383
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;
391
392#endif /* A_HAVE_LONG_LONG_TYPE */
393
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)
400typedef A_BYTE a_byte;
401
402#define A_C8 char
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)
409typedef A_C8 a_c8;
410
411#if !defined A_I8
412#define A_I8 signed char
413#endif /* A_I8 */
414#if !defined A_I8_C
415#define A_I8_C(X) X
416#endif /* A_I8_C */
417#if !defined A_I8_MAX
418#define A_I8_MAX A_I8_C(0x7F)
419#endif /* A_I8_MAX */
420#if !defined A_I8_MIN
421#define A_I8_MIN A_I8_C(~0x7F)
422#endif /* A_I8_MIN */
424#define a_i8_c(x) a_cast_s(a_i8, x)
425#define a_i8_(_, x) a_cast_s(a_i8 _, x)
427typedef A_I8 a_i8;
428
429#if !defined A_U8
430#define A_U8 unsigned char
431#endif /* A_U8 */
432#if !defined A_U8_C
433#define A_U8_C(X) X
434#endif /* A_U8_C */
435#if !defined A_U8_MAX
436#define A_U8_MAX A_U8_C(0xFF)
437#endif /* A_U8_MAX */
439#define a_u8_c(x) a_cast_s(a_u8, x)
440#define a_u8_(_, x) a_cast_s(a_u8 _, x)
442typedef A_U8 a_u8;
443
444#if !defined A_PRI8
445#define A_PRI8
446#endif /* A_PRI8 */
447#if !defined A_SCN8
448#define A_SCN8 "hh"
449#endif /* A_SCN8 */
450
451#if !defined A_I16 && (INT_MAX == 0x7FFFL)
452#define A_I16 int
453#elif !defined A_I16
454#define A_I16 short
455#endif /* A_I16 */
456#if !defined A_I16_C
457#define A_I16_C(X) X
458#endif /* A_I16_C */
459#if !defined A_I16_MAX
460#define A_I16_MAX A_I16_C(0x7FFF)
461#endif /* A_I16_MAX */
462#if !defined A_I16_MIN
463#define A_I16_MIN A_I16_C(~0x7FFF)
464#endif /* A_I16_MIN */
466#define a_i16_c(x) a_cast_s(a_i16, x)
467#define a_i16_(_, x) a_cast_s(a_i16 _, x)
469typedef A_I16 a_i16;
470
471#if !defined A_U16 && (UINT_MAX == 0xFFFFUL)
472#define A_U16 unsigned int
473#elif !defined A_U16
474#define A_U16 unsigned short
475#endif /* A_U16 */
476#if !defined A_U16_C
477#define A_U16_C(X) X
478#endif /* A_U16_C */
479#if !defined A_U16_MAX
480#define A_U16_MAX A_U16_C(0xFFFF)
481#endif /* A_U16_MAX */
483#define a_u16_c(x) a_cast_s(a_u16, x)
484#define a_u16_(_, x) a_cast_s(a_u16 _, x)
486typedef A_U16 a_u16;
487
488#if !defined A_PRI16 && (UINT_MAX == 0xFFFFUL)
489#define A_PRI16
490#elif !defined A_PRI16
491#define A_PRI16
492#endif /* A_PRI16 */
493#if !defined A_SCN16 && (UINT_MAX == 0xFFFFUL)
494#define A_SCN16
495#elif !defined A_SCN16
496#define A_SCN16 "h"
497#endif /* A_SCN16 */
498
499#if !defined A_I32 && (INT_MAX == 0x7FFFFFFFL)
500#define A_I32 int
501#elif !defined A_I32
502#define A_I32 long
503#endif /* A_I32 */
504#if !defined A_I32_C && (INT_MAX == 0x7FFFFFFFL)
505#define A_I32_C(X) X
506#elif !defined A_I32_C
507#define A_I32_C(X) A_CAST_2(X, L)
508#endif /* A_I32_C */
509#if !defined A_I32_MAX
510#define A_I32_MAX A_I32_C(0x7FFFFFFF)
511#endif /* A_I32_MAX */
512#if !defined A_I32_MIN
513#define A_I32_MIN A_I32_C(~0x7FFFFFFF)
514#endif /* A_I32_MIN */
516#define a_i32_c(x) a_cast_s(a_i32, x)
517#define a_i32_(_, x) a_cast_s(a_i32 _, x)
519typedef A_I32 a_i32;
520
521#if !defined A_U32 && (UINT_MAX == 0xFFFFFFFFUL)
522#define A_U32 unsigned int
523#elif !defined A_U32
524#define A_U32 unsigned long
525#endif /* A_U32 */
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)
530#endif /* A_U32_C */
531#if !defined A_U32_MAX
532#define A_U32_MAX A_U32_C(0xFFFFFFFF)
533#endif /* A_U32_MAX */
535#define a_u32_c(x) a_cast_s(a_u32, x)
536#define a_u32_(_, x) a_cast_s(a_u32 _, x)
538typedef A_U32 a_u32;
539
540#if !defined A_PRI32 && (UINT_MAX == 0xFFFFFFFFUL)
541#define A_PRI32
542#elif !defined A_PRI32
543#define A_PRI32 "l"
544#endif /* A_PRI32 */
545#if !defined A_SCN32 && (UINT_MAX == 0xFFFFFFFFUL)
546#define A_SCN32
547#elif !defined A_SCN32
548#define A_SCN32 "l"
549#endif /* A_SCN32 */
550
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)
555#define A_I64 __int64
556#else /* !extension */
557#define A_I64 long long
558#endif /* extension */
559#elif !defined A_I64
560#define A_I64 long
561#endif /* A_I64 */
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))
569#else /* !extension */
570#define A_I64_C(X) A_CAST_2(X, LL)
571#endif /* extension */
572#elif !defined A_I64_C
573#define A_I64_C(X) A_CAST_2(X, L)
574#endif /* A_I64_C */
575#if !defined A_I64_MAX
576#define A_I64_MAX A_I64_C(0x7FFFFFFFFFFFFFFF)
577#endif /* A_I64_MAX */
578#if !defined A_I64_MIN
579#define A_I64_MIN A_I64_C(~0x7FFFFFFFFFFFFFFF)
580#endif /* A_I64_MIN */
582#define a_i64_c(x) a_cast_s(a_i64, x)
583#define a_i64_(_, x) a_cast_s(a_i64 _, x)
584/* clang-format off */
585#if defined(__GNUC__)
586__extension__
587#endif /* __GNUC__ */
589typedef A_I64 a_i64;
590/* clang-format on */
591
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
597#else /* !extension */
598#define A_U64 unsigned long long
599#endif /* extension */
600#elif !defined A_U64
601#define A_U64 unsigned long
602#endif /* A_U64 */
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))
610#else /* !extension */
611#define A_U64_C(X) A_CAST_2(X, ULL)
612#endif /* extension */
613#elif !defined A_U64_C
614#define A_U64_C(X) A_CAST_2(X, UL)
615#endif /* A_U64_C */
616#if !defined A_U64_MAX
617#define A_U64_MAX A_U64_C(0xFFFFFFFFFFFFFFFF)
618#endif /* A_U64_MAX */
620#define a_u64_c(x) a_cast_s(a_u64, x)
621#define a_u64_(_, x) a_cast_s(a_u64 _, x)
622/* clang-format off */
623#if defined(__GNUC__)
624__extension__
625#endif /* __GNUC__ */
627typedef A_U64 a_u64;
628/* clang-format on */
629
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)
634#define A_PRI64 "I64"
635#else /* !extension */
636#define A_PRI64 "ll"
637#endif /* extension */
638#elif !defined A_PRI64
639#define A_PRI64 "l"
640#endif /* 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)
645#define A_SCN64 "I64"
646#else /* !extension */
647#define A_SCN64 "ll"
648#endif /* extension */
649#elif !defined A_SCN64
650#define A_SCN64 "l"
651#endif /* A_SCN64 */
652
653#if !defined A_IMAX
654#define A_IMAX A_I64
655#endif /* A_IMAX */
656#if !defined A_IMAX_C
657#define A_IMAX_C(X) A_I64_C(X)
658#endif /* A_IMAX_C */
659#if !defined A_IMAX_MAX
660#define A_IMAX_MAX A_I64_MAX
661#endif /* A_IMAX_MAX */
662#if !defined A_IMAX_MIN
663#define A_IMAX_MIN A_I64_MIN
664#endif /* A_IMAX_MIN */
666#define a_imax_c(x) a_cast_s(a_imax, x)
667#define a_imax_(_, x) a_cast_s(a_imax _, x)
669typedef A_IMAX a_imax;
670
671#if !defined A_UMAX
672#define A_UMAX A_U64
673#endif /* A_UMAX */
674#if !defined A_UMAX_C
675#define A_UMAX_C(X) A_U64_C(X)
676#endif /* A_UMAX_C */
677#if !defined A_UMAX_MAX
678#define A_UMAX_MAX A_U64_MAX
679#endif /* A_UMAX_MAX */
681#define a_umax_c(x) a_cast_s(a_umax, x)
682#define a_umax_(_, x) a_cast_s(a_umax _, x)
684typedef A_UMAX a_umax;
685
686#if !defined A_PRIMAX
687#define A_PRIMAX A_PRI64
688#endif /* A_PRIMAX */
689#if !defined A_SCNMAX
690#define A_SCNMAX A_SCN64
691#endif /* A_SCNMAX */
692
693#if !defined A_IPTR && (A_SIZE_POINTER == 2)
694#define A_IPTR A_I16
695#elif !defined A_IPTR && (A_SIZE_POINTER == 4)
696#define A_IPTR A_I32
697#elif !defined A_IPTR
698#define A_IPTR A_I64
699#endif /* A_IPTR */
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
706#endif /* A_IPTR_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
713#endif /* A_IPTR_MIN */
715#define a_iptr_c(x) a_cast_s(a_iptr, x)
716#define a_iptr_(_, x) a_cast_s(a_iptr _, x)
718typedef A_IPTR a_iptr;
719
720#if !defined A_UPTR && (A_SIZE_POINTER == 2)
721#define A_UPTR A_U16
722#elif !defined A_UPTR && (A_SIZE_POINTER == 4)
723#define A_UPTR A_U32
724#elif !defined A_UPTR
725#define A_UPTR A_U64
726#endif /* A_UPTR */
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
733#endif /* A_UPTR_MAX */
735#define a_uptr_c(x) a_cast_s(a_uptr, x)
736#define a_uptr_(_, x) a_cast_s(a_uptr _, x)
738typedef A_UPTR a_uptr;
739
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
746#endif /* A_PRIPTR */
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
753#endif /* A_SCNPTR */
754
755#if !defined A_DIFF
756#define A_DIFF ptrdiff_t
757#endif /* A_DIFF */
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
766#endif /* A_DIFF_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
775#endif /* A_DIFF_MIN */
777#define a_diff_c(x) a_cast_s(a_diff, x)
778#define a_diff_(_, x) a_cast_s(a_diff _, x)
780typedef A_DIFF a_diff;
781
782#if defined(__STDC_VERSION__) && (__STDC_VERSION__ > 199900L) || \
783 defined(__cplusplus) && (__cplusplus > 201100L) || A_PREREQ_MSVC(19, 0)
784#if !defined A_PRIt
785#define A_PRIt "t"
786#endif /* A_PRIt */
787#if !defined A_SCNt
788#define A_SCNt "t"
789#endif /* A_SCNt */
790#else /* C < 199900 and C++ < 201100 */
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
795#elif !defined A_PRIt
796#define A_PRIt A_PRI64
797#endif /* A_PRIt */
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
802#elif !defined A_SCNt
803#define A_SCNt A_SCN64
804#endif /* A_SCNt */
805#endif /* C > 199900 or C++ > 201100 */
806
807#if !defined A_SIZE
808#define A_SIZE size_t
809#endif /* A_SIZE */
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
818#endif /* A_SIZE_MAX */
820#define a_size_c(x) a_cast_s(a_size, x)
821#define a_size_(_, x) a_cast_s(a_size _, x)
823typedef A_SIZE a_size;
824
825#if defined(__STDC_VERSION__) && (__STDC_VERSION__ > 199900L) || \
826 defined(__cplusplus) && (__cplusplus > 201100L) || A_PREREQ_MSVC(19, 0)
827#if !defined A_PRIz
828#define A_PRIz "z"
829#endif /* A_PRIz */
830#if !defined A_SCNz
831#define A_SCNz "z"
832#endif /* A_SCNz */
833#else /* C < 199900 and C++ < 201100 */
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
838#elif !defined A_PRIz
839#define A_PRIz A_PRI64
840#endif /* A_PRIz */
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
845#elif !defined A_SCNz
846#define A_SCNz A_SCN64
847#endif /* A_SCNz */
848#endif /* C > 199900 or C++ > 201100 */
849
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)
854
855#define A_F32 float
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)
877typedef A_F32 a_f32;
878
879#define A_F64 double
880#define A_F64_C(X) X
881#define A_F64_F(F) F
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)
901typedef A_F64 a_f64;
902
907
912#if !defined A_FLOAT_TYPE
913#if !defined A_SIZE_FLOAT
914#define A_FLOAT_TYPE A_FLOAT_DOUBLE
915#else /* !A_SIZE_FLOAT */
916#define A_FLOAT_TYPE A_SIZE_FLOAT
917#endif /* A_SIZE_FLOAT */
918#endif /* A_FLOAT_TYPE */
919#define A_FLOAT_SINGLE 0x04
920#define A_FLOAT_DOUBLE 0x08
921#define A_FLOAT_EXTEND 0x10
922#if defined(A_FLOAT)
923#elif A_FLOAT_TYPE + 0 == A_FLOAT_SINGLE
924
926#define A_FLOAT float
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)
938#define A_FLOAT_PRI
939#define A_FLOAT_SCN
940
941#elif A_FLOAT_TYPE + 0 == A_FLOAT_DOUBLE
942
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
956#define A_FLOAT_PRI
957#define A_FLOAT_SCN "l"
958
959#elif A_FLOAT_TYPE + 0 == A_FLOAT_EXTEND
960
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"
976
977#else /* !A_FLOAT_TYPE */
978#error unsupported precision
979#endif /* A_FLOAT_TYPE */
980
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)
1004
1006
1007typedef union a_cast
1008{
1009 a_c8 c;
1010 a_int i;
1011 a_uint u;
1012 a_shrt ih;
1013 a_ushrt uh;
1014 a_long il;
1015 a_ulong ul;
1016#if defined(A_HAVE_LONG_LONG_TYPE)
1017 a_llong ill;
1018 a_ullong ull;
1019#endif /* A_HAVE_LONG_LONG_TYPE */
1020 a_i8 i8;
1021 a_u8 u8;
1022 a_i16 i16;
1023 a_u16 u16;
1024 a_i32 i32;
1025 a_u32 u32;
1026 a_i64 i64;
1027 a_u64 u64;
1028 a_f32 f32;
1029 a_f64 f64;
1030 a_imax imax;
1031 a_umax umax;
1032 a_iptr iptr;
1033 a_uptr uptr;
1034 a_diff diff;
1035 a_size size;
1036 void const *PTR;
1037 void *ptr;
1038 char const *STR;
1039 char *str;
1040#if defined(A_FLOAT_TYPE) && (A_FLOAT_TYPE + 0 < A_FLOAT_EXTEND)
1041 a_float f;
1042#endif /* A_FLOAT_TYPE */
1043} a_cast;
1044
1048#define A_SQ(x) ((x) * (x))
1049
1053#define A_ABS(x) ((x) < 0 ? -(x) : (x))
1057#define A_ABS_(f, g) ((f) < (g) ? (g) - (f) : (f) - (g))
1058
1062#define A_MIN(x, y) (((x) < (y)) ? (x) : (y))
1063
1067#define A_MAX(x, y) (((x) > (y)) ? (x) : (y))
1068
1072#define A_SGN(x) ((0 < (x)) - ((x) < 0))
1076#define A_SGN_(f, g) (((f) > (g)) - ((f) < (g)))
1077
1081#define A_SAT(x, min, max) ((min) < (x) ? (x) < (max) ? (x) : (max) : (min))
1082
1087#define A_LEN(a) (sizeof(a) / sizeof(*(a)))
1088
1094#if defined(offsetof)
1095#define a_offsetof(type, member) offsetof(type, member)
1096#else /* !offsetof */
1097#define a_offsetof(type, member) a_cast_r(a_size, &a_cast_r(type *, 0)->member)
1098#endif /* offsetof */
1099
1106#define a_container_of(ptr, type, member) a_cast_r(type *, a_cast_r(a_uptr, ptr) - a_offsetof(type, member))
1107
1111#define a_size_down(a, n) (a_cast_s(a_size, n) & ~a_cast_s(a_size, (a) - 1))
1112
1116#define a_size_up(a, n) ((a_cast_s(a_size, n) + (a) - 1) & ~a_cast_s(a_size, (a) - 1))
1117
1121#define a_align_down(a, p) a_cast_r(void *, a_cast_r(a_uptr, p) & ~a_cast_s(a_uptr, (a) - 1))
1122
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))
1127
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)
1136
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;)
1145
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)
1163
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##_; \
1180 it > it##_; --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; \
1184 it > at; --it)
1185
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)
1198
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)
1211
1215enum
1216{
1220};
1221
1222#if defined(__cplusplus)
1223extern "C" {
1224#endif /* __cplusplus */
1225#if defined(LIBA_A_C)
1226#undef A_INTERN
1227#define A_INTERN A_INLINE
1228#endif /* LIBA_A_C */
1229
1235#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1236A_EXTERN a_u8 a_u8_rev(a_u8 x);
1237#endif /* A_HAVE_INLINE */
1238#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1239A_INTERN a_u8 a_u8_rev(a_u8 x)
1240{
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));
1244 return x;
1245}
1246#endif /* A_HAVE_INLINE */
1247
1253#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1255#endif /* A_HAVE_INLINE */
1256#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1257A_INTERN a_u16 a_u16_rev(a_u16 x)
1258{
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));
1263 return x;
1264}
1265#endif /* A_HAVE_INLINE */
1266#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1267A_EXTERN A_NONULL((1)) a_u16 a_u16_getl(void const *b);
1268#endif /* A_HAVE_INLINE */
1269#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1270A_INTERN A_NONULL((1)) a_u16 a_u16_getl(void const *b)
1271{
1272 a_byte const *p = a_cast_s(a_byte const *, b);
1273 return a_cast_s(a_u16, (p[0] << 0) | (p[1] << 8));
1274}
1275#endif /* A_HAVE_INLINE */
1276#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1277A_EXTERN A_NONULL((1)) a_u16 a_u16_getb(void const *b);
1278#endif /* A_HAVE_INLINE */
1279#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1280A_INTERN A_NONULL((1)) a_u16 a_u16_getb(void const *b)
1281{
1282 a_byte const *p = a_cast_s(a_byte const *, b);
1283 return a_cast_s(a_u16, (p[1] << 0) | (p[0] << 8));
1284}
1285#endif /* A_HAVE_INLINE */
1286#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1287A_EXTERN A_NONULL((1)) void a_u16_setl(void *b, a_u16 x);
1288#endif /* A_HAVE_INLINE */
1289#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1290A_INTERN A_NONULL((1)) void a_u16_setl(void *b, a_u16 x)
1291{
1292 a_byte *p = a_cast_s(a_byte *, b);
1293 p[0] = a_cast_s(a_byte, x >> 0);
1294 p[1] = a_cast_s(a_byte, x >> 8);
1295}
1296#endif /* A_HAVE_INLINE */
1297#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1298A_EXTERN A_NONULL((1)) void a_u16_setb(void *b, a_u16 x);
1299#endif /* A_HAVE_INLINE */
1300#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1301A_INTERN A_NONULL((1)) void a_u16_setb(void *b, a_u16 x)
1302{
1303 a_byte *p = a_cast_s(a_byte *, b);
1304 p[0] = a_cast_s(a_byte, x >> 8);
1305 p[1] = a_cast_s(a_byte, x >> 0);
1306}
1307#endif /* A_HAVE_INLINE */
1308
1314#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1316#endif /* A_HAVE_INLINE */
1317#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1318A_INTERN a_u32 a_u32_rev(a_u32 x)
1319{
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);
1325 return x;
1326}
1327#endif /* A_HAVE_INLINE */
1328#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1329A_EXTERN A_NONULL((1)) a_u32 a_u32_getl(void const *b);
1330#endif /* A_HAVE_INLINE */
1331#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1332A_INTERN A_NONULL((1)) a_u32 a_u32_getl(void const *b)
1333{
1334 a_byte const *p = a_cast_s(a_byte 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);
1339}
1340#endif /* A_HAVE_INLINE */
1341#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1342A_EXTERN A_NONULL((1)) a_u32 a_u32_getb(void const *b);
1343#endif /* A_HAVE_INLINE */
1344#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1345A_INTERN A_NONULL((1)) a_u32 a_u32_getb(void const *b)
1346{
1347 a_byte const *p = a_cast_s(a_byte 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);
1352}
1353#endif /* A_HAVE_INLINE */
1354#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1355A_EXTERN A_NONULL((1)) void a_u32_setl(void *b, a_u32 x);
1356#endif /* A_HAVE_INLINE */
1357#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1358A_INTERN A_NONULL((1)) void a_u32_setl(void *b, a_u32 x)
1359{
1360 a_byte *p = a_cast_s(a_byte *, b);
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);
1365}
1366#endif /* A_HAVE_INLINE */
1367#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1368A_EXTERN A_NONULL((1)) void a_u32_setb(void *b, a_u32 x);
1369#endif /* A_HAVE_INLINE */
1370#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1371A_INTERN A_NONULL((1)) void a_u32_setb(void *b, a_u32 x)
1372{
1373 a_byte *p = a_cast_s(a_byte *, b);
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);
1378}
1379#endif /* A_HAVE_INLINE */
1380
1386#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1388#endif /* A_HAVE_INLINE */
1389#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1390A_INTERN a_u64 a_u64_rev(a_u64 x)
1391{
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);
1398 return x;
1399}
1400#endif /* A_HAVE_INLINE */
1401#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1402A_EXTERN A_NONULL((1)) a_u64 a_u64_getl(void const *b);
1403#endif /* A_HAVE_INLINE */
1404#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1405A_INTERN A_NONULL((1)) a_u64 a_u64_getl(void const *b)
1406{
1407 a_byte const *p = a_cast_s(a_byte 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);
1416}
1417#endif /* A_HAVE_INLINE */
1418#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1419A_EXTERN A_NONULL((1)) a_u64 a_u64_getb(void const *b);
1420#endif /* A_HAVE_INLINE */
1421#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1422A_INTERN A_NONULL((1)) a_u64 a_u64_getb(void const *b)
1423{
1424 a_byte const *p = a_cast_s(a_byte 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);
1433}
1434#endif /* A_HAVE_INLINE */
1435#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1436A_EXTERN A_NONULL((1)) void a_u64_setl(void *b, a_u64 x);
1437#endif /* A_HAVE_INLINE */
1438#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1439A_INTERN A_NONULL((1)) void a_u64_setl(void *b, a_u64 x)
1440{
1441 a_byte *p = a_cast_s(a_byte *, b);
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);
1450}
1451#endif /* A_HAVE_INLINE */
1452#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1453A_EXTERN A_NONULL((1)) void a_u64_setb(void *b, a_u64 x);
1454#endif /* A_HAVE_INLINE */
1455#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1456A_INTERN A_NONULL((1)) void a_u64_setb(void *b, a_u64 x)
1457{
1458 a_byte *p = a_cast_s(a_byte *, b);
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);
1467}
1468#endif /* A_HAVE_INLINE */
1469
1477A_EXTERN A_NONULL((1, 2)) void *a_copy(void *__restrict dst, void const *__restrict src, a_size siz);
1478
1486A_EXTERN A_NONULL((1, 2)) void *a_move(void *dst, void const *src, a_size siz);
1487
1495A_EXTERN A_NONULL((1)) void *a_fill(void *ptr, a_size siz, int val);
1496
1503A_EXTERN A_NONULL((1)) void *a_zero(void *ptr, a_size siz);
1504
1511A_EXTERN A_NONULL((1, 2)) void a_swap(void *lhs, void *rhs, a_size siz);
1512
1519A_EXTERN void *(*a_alloc)(void *addr, a_size size);
1520
1527A_EXTERN void *a_alloc_(void *addr, a_size size);
1528
1529#if defined(LIBA_A_C)
1530#undef A_INTERN
1531#define A_INTERN static A_INLINE
1532#endif /* LIBA_A_C */
1533#if defined(__cplusplus)
1534} /* extern "C" */
1535#endif /* __cplusplus */
1536
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)
1541
1543
1544#endif /* a/a.h */
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
Definition a.h:1008