|
20 | 20 | extern "C" {
|
21 | 21 | #endif
|
22 | 22 |
|
| 23 | +#if defined(__GNUC__) || defined(__GNUG__) |
| 24 | + |
| 25 | +#include <assert.h> |
| 26 | + |
| 27 | +#define CC_PACKED_BEGIN |
| 28 | +#define CC_PACKED_END |
| 29 | +#define CC_PACKED __attribute__ ((packed)) |
| 30 | + |
| 31 | +#define CC_FORMAT(str, arg) __attribute__ ((format (printf, str, arg))) |
| 32 | + |
| 33 | +#if BYTE_ORDER == LITTLE_ENDIAN |
| 34 | +#define CC_TO_LE16(x) ((uint16_t)(x)) |
| 35 | +#define CC_TO_LE32(x) ((uint32_t)(x)) |
| 36 | +#define CC_TO_LE64(x) ((uint64_t)(x)) |
| 37 | +#define CC_FROM_LE16(x) ((uint16_t)(x)) |
| 38 | +#define CC_FROM_LE32(x) ((uint32_t)(x)) |
| 39 | +#define CC_FROM_LE64(x) ((uint64_t)(x)) |
| 40 | +#define CC_TO_BE16(x) ((uint16_t)__builtin_bswap16 (x)) |
| 41 | +#define CC_TO_BE32(x) ((uint32_t)__builtin_bswap32 (x)) |
| 42 | +#define CC_TO_BE64(x) ((uint64_t)__builtin_bswap64 (x)) |
| 43 | +#define CC_FROM_BE16(x) ((uint16_t)__builtin_bswap16 (x)) |
| 44 | +#define CC_FROM_BE32(x) ((uint32_t)__builtin_bswap32 (x)) |
| 45 | +#define CC_FROM_BE64(x) ((uint64_t)__builtin_bswap64 (x)) |
| 46 | +#else |
| 47 | +#define CC_TO_LE16(x) ((uint16_t)__builtin_bswap16 (x)) |
| 48 | +#define CC_TO_LE32(x) ((uint32_t)__builtin_bswap32 (x)) |
| 49 | +#define CC_TO_LE64(x) ((uint64_t)__builtin_bswap64 (x)) |
| 50 | +#define CC_FROM_LE16(x) ((uint16_t)__builtin_bswap16 (x)) |
| 51 | +#define CC_FROM_LE32(x) ((uint32_t)__builtin_bswap32 (x)) |
| 52 | +#define CC_FROM_LE64(x) ((uint64_t)__builtin_bswap64 (x)) |
| 53 | +#define CC_TO_BE16(x) ((uint16_t)(x)) |
| 54 | +#define CC_TO_BE32(x) ((uint32_t)(x)) |
| 55 | +#define CC_TO_BE64(x) ((uint64_t)(x)) |
| 56 | +#define CC_FROM_BE16(x) ((uint16_t)(x)) |
| 57 | +#define CC_FROM_BE32(x) ((uint32_t)(x)) |
| 58 | +#define CC_FROM_BE64(x) ((uint64_t)(x)) |
| 59 | +#endif |
| 60 | + |
| 61 | +#define CC_ATOMIC_GET8(p) __atomic_load_n ((p), __ATOMIC_SEQ_CST) |
| 62 | +#define CC_ATOMIC_GET16(p) __atomic_load_n ((p), __ATOMIC_SEQ_CST) |
| 63 | +#define CC_ATOMIC_GET32(p) __atomic_load_n ((p), __ATOMIC_SEQ_CST) |
| 64 | +#define CC_ATOMIC_GET64(p) __atomic_load_n ((p), __ATOMIC_SEQ_CST) |
| 65 | + |
| 66 | +#define CC_ATOMIC_SET8(p, v) __atomic_store_n ((p), (v), __ATOMIC_SEQ_CST) |
| 67 | +#define CC_ATOMIC_SET16(p, v) __atomic_store_n ((p), (v), __ATOMIC_SEQ_CST) |
| 68 | +#define CC_ATOMIC_SET32(p, v) __atomic_store_n ((p), (v), __ATOMIC_SEQ_CST) |
| 69 | +#define CC_ATOMIC_SET64(p, v) __atomic_store_n ((p), (v), __ATOMIC_SEQ_CST) |
| 70 | + |
| 71 | +#define CC_ASSERT(exp) cc_assert (exp) |
| 72 | + |
| 73 | +#ifdef __cplusplus |
| 74 | +#define CC_STATIC_ASSERT(exp) static_assert (exp, "") |
| 75 | +#else |
| 76 | +#define CC_STATIC_ASSERT(exp) _Static_assert(exp, "") |
| 77 | +#endif |
| 78 | + |
| 79 | +#define CC_UNUSED(var) (void)(var) |
| 80 | + |
| 81 | +static inline void cc_assert (int exp) |
| 82 | +{ |
| 83 | + assert (exp); // LCOV_EXCL_LINE |
| 84 | +} |
| 85 | + |
| 86 | +#elif defined(_MSC_VER) |
| 87 | + |
23 | 88 | #include <assert.h>
|
24 | 89 |
|
25 | 90 | #define CC_PACKED_BEGIN __pragma (pack (push, 1))
|
@@ -65,6 +130,8 @@ static uint8_t __inline cc_ctz (uint32_t x)
|
65 | 130 | #define CC_ASSERT(exp) assert (exp)
|
66 | 131 | #define CC_STATIC_ASSERT(exp) static_assert ((exp), "")
|
67 | 132 |
|
| 133 | +#endif |
| 134 | + |
68 | 135 | #ifdef __cplusplus
|
69 | 136 | }
|
70 | 137 | #endif
|
|
0 commit comments