… | |
… | |
54 | #else |
54 | #else |
55 | #define ECB_PTRSIZE 4 |
55 | #define ECB_PTRSIZE 4 |
56 | typedef uint32_t uintptr_t; |
56 | typedef uint32_t uintptr_t; |
57 | typedef int32_t intptr_t; |
57 | typedef int32_t intptr_t; |
58 | #endif |
58 | #endif |
|
|
59 | typedef intptr_t ptrdiff_t; |
59 | #else |
60 | #else |
60 | #include <inttypes.h> |
61 | #include <inttypes.h> |
61 | #if UINTMAX_MAX > 0xffffffffU |
62 | #if UINTMAX_MAX > 0xffffffffU |
62 | #define ECB_PTRSIZE 8 |
63 | #define ECB_PTRSIZE 8 |
63 | #else |
64 | #else |
… | |
… | |
78 | #else |
79 | #else |
79 | #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
80 | #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
80 | #endif |
81 | #endif |
81 | #endif |
82 | #endif |
82 | |
83 | |
|
|
84 | #define ECB_C (__STDC__+0) /* this assumes that __STDC__ is either empty or a number */ |
|
|
85 | #define ECB_C99 (__STDC_VERSION__ >= 199901L) |
|
|
86 | #define ECB_C11 (__STDC_VERSION__ >= 201112L) |
|
|
87 | #define ECB_CPP (__cplusplus+0) |
|
|
88 | #define ECB_CPP98 (__cplusplus >= 199711L) |
|
|
89 | #define ECB_CPP11 (__cplusplus >= 201103L) |
|
|
90 | |
83 | /*****************************************************************************/ |
91 | /*****************************************************************************/ |
84 | |
92 | |
85 | /* ECB_NO_THREADS - ecb is not used by multiple threads, ever */ |
93 | /* ECB_NO_THREADS - ecb is not used by multiple threads, ever */ |
86 | /* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */ |
94 | /* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */ |
87 | |
95 | |
… | |
… | |
89 | # define ECB_NO_SMP 1 |
97 | # define ECB_NO_SMP 1 |
90 | #endif |
98 | #endif |
91 | |
99 | |
92 | #if ECB_NO_THREADS || ECB_NO_SMP |
100 | #if ECB_NO_THREADS || ECB_NO_SMP |
93 | #define ECB_MEMORY_FENCE do { } while (0) |
101 | #define ECB_MEMORY_FENCE do { } while (0) |
|
|
102 | #endif |
|
|
103 | |
|
|
104 | #ifndef ECB_MEMORY_FENCE |
|
|
105 | #if ECB_C11 && !defined __STDC_NO_ATOMICS__ |
|
|
106 | /* we assume that these memory fences work on all variables/all memory accesses, */ |
|
|
107 | /* not just C11 atomics and atomic accesses */ |
|
|
108 | #include <stdatomic.h> |
|
|
109 | #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_acq_rel) |
|
|
110 | #define ECB_MEMORY_FENCE_ACQUIRE atomic_thread_fence (memory_order_acquire) |
|
|
111 | #define ECB_MEMORY_FENCE_RELEASE atomic_thread_fence (memory_order_release) |
|
|
112 | #endif |
94 | #endif |
113 | #endif |
95 | |
114 | |
96 | #ifndef ECB_MEMORY_FENCE |
115 | #ifndef ECB_MEMORY_FENCE |
97 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
116 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
98 | #if __i386 || __i386__ |
117 | #if __i386 || __i386__ |
… | |
… | |
174 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
193 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
175 | #endif |
194 | #endif |
176 | |
195 | |
177 | /*****************************************************************************/ |
196 | /*****************************************************************************/ |
178 | |
197 | |
179 | #define ECB_C99 (__STDC_VERSION__ >= 199901L) |
|
|
180 | |
|
|
181 | #if __cplusplus |
198 | #if __cplusplus |
182 | #define ecb_inline static inline |
199 | #define ecb_inline static inline |
183 | #elif ECB_GCC_VERSION(2,5) |
200 | #elif ECB_GCC_VERSION(2,5) |
184 | #define ecb_inline static __inline__ |
201 | #define ecb_inline static __inline__ |
185 | #elif ECB_C99 |
202 | #elif ECB_C99 |
… | |
… | |
223 | #elif ECB_GCC_VERSION(3,0) |
240 | #elif ECB_GCC_VERSION(3,0) |
224 | #define ecb_decltype(x) __typeof(x) |
241 | #define ecb_decltype(x) __typeof(x) |
225 | #endif |
242 | #endif |
226 | |
243 | |
227 | #define ecb_noinline ecb_attribute ((__noinline__)) |
244 | #define ecb_noinline ecb_attribute ((__noinline__)) |
228 | #define ecb_noreturn ecb_attribute ((__noreturn__)) |
|
|
229 | #define ecb_unused ecb_attribute ((__unused__)) |
245 | #define ecb_unused ecb_attribute ((__unused__)) |
230 | #define ecb_const ecb_attribute ((__const__)) |
246 | #define ecb_const ecb_attribute ((__const__)) |
231 | #define ecb_pure ecb_attribute ((__pure__)) |
247 | #define ecb_pure ecb_attribute ((__pure__)) |
|
|
248 | |
|
|
249 | #if ECB_C11 |
|
|
250 | #define ecb_noreturn _Noreturn |
|
|
251 | #else |
|
|
252 | #define ecb_noreturn ecb_attribute ((__noreturn__)) |
|
|
253 | #endif |
232 | |
254 | |
233 | #if ECB_GCC_VERSION(4,3) |
255 | #if ECB_GCC_VERSION(4,3) |
234 | #define ecb_artificial ecb_attribute ((__artificial__)) |
256 | #define ecb_artificial ecb_attribute ((__artificial__)) |
235 | #define ecb_hot ecb_attribute ((__hot__)) |
257 | #define ecb_hot ecb_attribute ((__hot__)) |
236 | #define ecb_cold ecb_attribute ((__cold__)) |
258 | #define ecb_cold ecb_attribute ((__cold__)) |