4 * code protected with a GNU affero GPLv3 license
5 * copyright (C) 2020 Sylvain BERTRAND
10 #include <stdatomic.h>
16 #define U16_MAX 0xffff
20 #define U64_MAX 0xffffffffffffffff
22 #define S64_MIN 0x8000000000000000
23 #define S64_MAX 0x7fffffffffffffff
31 #define atomic_u8 atomic_uchar
36 #error "unable to find the right atomic for a 8 bits byte, be sure to have __STDC_WANT_IEC_60559_BFP_EXT__ defined"
40 #define atomic_u16 atomic_ushort
42 #define atomic_u16 u16
45 #error "unable to find the right atomic for an unsigned 16 bits word, be sure to have __STDC_WANT_IEC_60559_BFP_EXT__ defined"
49 #define atomic_u32 atomic_uint
51 #define atomic_u32 u32
53 #elif ULONG_WIDTH == 32
55 #define atomic_u32 atomic_ulong
57 #define atomic_u32 u32
60 #error "unable to select the right atomic for an unsigned 32 bits word, be sure to have __STDC_WANT_IEC_60559_BFP_EXT__ defined"
64 #define atomic_s64 atomic_long
66 #define atomic_s64 s64
69 #error "unable to select the right atomic for a 64 bits signed word, be sure to have __STDC_WANT_IEC_60559_BFP_EXT__ defined"
72 #define atomic_load(x) __atomic_load_n(x,__ATOMIC_SEQ_CST)
73 #define atomic_store(x,y) __atomic_store_n(x,y,__ATOMIC_SEQ_CST)
78 * we don't know how to handle enum from the C "standard" perspective. this
79 * is based on empirical conclusions based on gcc.
80 * this is for compiler constant, not compiler constant _variables_
82 #define constant_u32 enum
84 #define ARRAY_N(x) (sizeof(x) / sizeof((x)[0]))