ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CBOR-XS/ecb.h
(Generate patch)

Comparing CBOR-XS/ecb.h (file contents):
Revision 1.6 by root, Sun Jan 5 14:24:54 2014 UTC vs.
Revision 1.8 by root, Tue Feb 18 22:12:12 2014 UTC

87 #else 87 #else
88 #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) 88 #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
89 #endif 89 #endif
90#endif 90#endif
91 91
92#define ECB_C (__STDC__+0) /* this assumes that __STDC__ is either empty or a number */
93#define ECB_C99 (__STDC_VERSION__ >= 199901L)
94#define ECB_C11 (__STDC_VERSION__ >= 201112L)
95#define ECB_CPP (__cplusplus+0) 92#define ECB_CPP (__cplusplus+0)
96#define ECB_CPP11 (__cplusplus >= 201103L) 93#define ECB_CPP11 (__cplusplus >= 201103L)
94
95#if ECB_CPP
96 #define ECB_C 0
97 #define ECB_STDC_VERSION 0
98#else
99 #define ECB_C 1
100 #define ECB_STDC_VERSION __STDC_VERSION__
101#endif
102
103#define ECB_C99 (ECB_STDC_VERSION >= 199901L)
104#define ECB_C11 (ECB_STDC_VERSION >= 201112L)
97 105
98#if ECB_CPP 106#if ECB_CPP
99 #define ECB_EXTERN_C extern "C" 107 #define ECB_EXTERN_C extern "C"
100 #define ECB_EXTERN_C_BEG ECB_EXTERN_C { 108 #define ECB_EXTERN_C_BEG ECB_EXTERN_C {
101 #define ECB_EXTERN_C_END } 109 #define ECB_EXTERN_C_END }
165 173
166#ifndef ECB_MEMORY_FENCE 174#ifndef ECB_MEMORY_FENCE
167 #if ECB_GCC_VERSION(4,7) 175 #if ECB_GCC_VERSION(4,7)
168 /* see comment below (stdatomic.h) about the C11 memory model. */ 176 /* see comment below (stdatomic.h) about the C11 memory model. */
169 #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST) 177 #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST)
178 #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE)
179 #define ECB_MEMORY_FENCE_RELEASE __atomic_thread_fence (__ATOMIC_RELEASE)
170 180
171 /* The __has_feature syntax from clang is so misdesigned that we cannot use it 181 /* The __has_feature syntax from clang is so misdesigned that we cannot use it
172 * without risking compile time errors with other compilers. We *could* 182 * without risking compile time errors with other compilers. We *could*
173 * define our own ecb_clang_has_feature, but I just can't be bothered to work 183 * define our own ecb_clang_has_feature, but I just can't be bothered to work
174 * around this shit time and again. 184 * around this shit time and again.
175 * #elif defined __clang && __has_feature (cxx_atomic) 185 * #elif defined __clang && __has_feature (cxx_atomic)
176 * // see comment below (stdatomic.h) about the C11 memory model. 186 * // see comment below (stdatomic.h) about the C11 memory model.
177 * #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST) 187 * #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST)
188 * #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE)
189 * #define ECB_MEMORY_FENCE_RELEASE __c11_atomic_thread_fence (__ATOMIC_RELEASE)
178 */ 190 */
179 191
180 #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ 192 #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__
181 #define ECB_MEMORY_FENCE __sync_synchronize () 193 #define ECB_MEMORY_FENCE __sync_synchronize ()
182 #elif _MSC_VER >= 1500 /* VC++ 2008 */ 194 #elif _MSC_VER >= 1500 /* VC++ 2008 */
212 /* any fence other than seq_cst, which isn't very efficient for us. */ 224 /* any fence other than seq_cst, which isn't very efficient for us. */
213 /* Why that is, we don't know - either the C11 memory model is quite useless */ 225 /* Why that is, we don't know - either the C11 memory model is quite useless */
214 /* for most usages, or gcc and clang have a bug */ 226 /* for most usages, or gcc and clang have a bug */
215 /* I *currently* lean towards the latter, and inefficiently implement */ 227 /* I *currently* lean towards the latter, and inefficiently implement */
216 /* all three of ecb's fences as a seq_cst fence */ 228 /* all three of ecb's fences as a seq_cst fence */
229 /* Update, gcc-4.8 generates mfence for all c++ fences, but nothing */
230 /* for all __atomic_thread_fence's except seq_cst */
217 #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_seq_cst) 231 #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_seq_cst)
218 #endif 232 #endif
219#endif 233#endif
220 234
221#ifndef ECB_MEMORY_FENCE 235#ifndef ECB_MEMORY_FENCE
278 #define ecb_is_constant(expr) __builtin_constant_p (expr) 292 #define ecb_is_constant(expr) __builtin_constant_p (expr)
279 #define ecb_expect(expr,value) __builtin_expect ((expr),(value)) 293 #define ecb_expect(expr,value) __builtin_expect ((expr),(value))
280 #define ecb_prefetch(addr,rw,locality) __builtin_prefetch (addr, rw, locality) 294 #define ecb_prefetch(addr,rw,locality) __builtin_prefetch (addr, rw, locality)
281#else 295#else
282 #define ecb_attribute(attrlist) 296 #define ecb_attribute(attrlist)
297
298 /* possible C11 impl for integral types
299 typedef struct ecb_is_constant_struct ecb_is_constant_struct;
300 #define ecb_is_constant(expr) _Generic ((1 ? (struct ecb_is_constant_struct *)0 : (void *)((expr) - (expr)), ecb_is_constant_struct *: 0, default: 1)) */
301
283 #define ecb_is_constant(expr) 0 302 #define ecb_is_constant(expr) 0
284 #define ecb_expect(expr,value) (expr) 303 #define ecb_expect(expr,value) (expr)
285 #define ecb_prefetch(addr,rw,locality) 304 #define ecb_prefetch(addr,rw,locality)
286#endif 305#endif
287 306

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines