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

Comparing libecb/ecb.h (file contents):
Revision 1.72 by root, Wed Jan 18 12:13:00 2012 UTC vs.
Revision 1.76 by root, Wed Jan 25 20:23:12 2012 UTC

72 #define ECB_MEMORY_FENCE do { } while (0) 72 #define ECB_MEMORY_FENCE do { } while (0)
73#endif 73#endif
74 74
75#ifndef ECB_MEMORY_FENCE 75#ifndef ECB_MEMORY_FENCE
76 #if ECB_GCC_VERSION(2,5) || defined(__INTEL_COMPILER) || defined(__clang__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 76 #if ECB_GCC_VERSION(2,5) || defined(__INTEL_COMPILER) || defined(__clang__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
77 #if __i386__ 77 #if __i386 || __i386__
78 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") 78 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory")
79 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE /* non-lock xchg might be enough */ 79 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE /* non-lock xchg might be enough */
80 #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */ 80 #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */
81 #elif __amd64 81 #elif __amd64 || __amd64__ || __x86_64 || __x86_64__
82 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") 82 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory")
83 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory") 83 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory")
84 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */ 84 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */
85 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ 85 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__
86 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") 86 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
88 || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__) 88 || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__)
89 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,5" : : "r" (0) : "memory") 89 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,5" : : "r" (0) : "memory")
90 #elif defined(__ARM_ARCH_7__ ) || defined(__ARM_ARCH_7A__ ) \ 90 #elif defined(__ARM_ARCH_7__ ) || defined(__ARM_ARCH_7A__ ) \
91 || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7R__ ) 91 || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7R__ )
92 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") 92 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory")
93 #elif defined(__sparc) 93 #elif __sparc || __sparc__
94 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #StoreLoad | #LoadLoad | #StoreStore" : : : "memory") 94 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad | " : : : "memory")
95 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadLoad" : : : "memory") 95 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory")
96 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #StoreStore") 96 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore")
97 #endif 97 #endif
98 #endif 98 #endif
99#endif 99#endif
100 100
101#ifndef ECB_MEMORY_FENCE 101#ifndef ECB_MEMORY_FENCE
386 386
387#if ECB_GCC_VERSION(4,5) 387#if ECB_GCC_VERSION(4,5)
388 #define ecb_unreachable() __builtin_unreachable () 388 #define ecb_unreachable() __builtin_unreachable ()
389#else 389#else
390 /* this seems to work fine, but gcc always emits a warning for it :/ */ 390 /* this seems to work fine, but gcc always emits a warning for it :/ */
391 ecb_function_ void ecb_unreachable (void) ecb_noreturn; 391 ecb_inline void ecb_unreachable (void) ecb_noreturn;
392 ecb_function_ void ecb_unreachable (void) { } 392 ecb_inline void ecb_unreachable (void) { }
393#endif 393#endif
394 394
395/* try to tell the compiler that some condition is definitely true */ 395/* try to tell the compiler that some condition is definitely true */
396#define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0) 396#define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0)
397 397
398ecb_function_ unsigned char ecb_byteorder_helper (void) ecb_const; 398ecb_inline unsigned char ecb_byteorder_helper (void) ecb_const;
399ecb_function_ unsigned char 399ecb_inline unsigned char
400ecb_byteorder_helper (void) 400ecb_byteorder_helper (void)
401{ 401{
402 const uint32_t u = 0x11223344; 402 const uint32_t u = 0x11223344;
403 return *(unsigned char *)&u; 403 return *(unsigned char *)&u;
404} 404}
405 405
406ecb_function_ ecb_bool ecb_big_endian (void) ecb_const; 406ecb_inline ecb_bool ecb_big_endian (void) ecb_const;
407ecb_function_ ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; } 407ecb_inline ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; }
408ecb_function_ ecb_bool ecb_little_endian (void) ecb_const; 408ecb_inline ecb_bool ecb_little_endian (void) ecb_const;
409ecb_function_ ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; } 409ecb_inline ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; }
410 410
411#if ECB_GCC_VERSION(3,0) || ECB_C99 411#if ECB_GCC_VERSION(3,0) || ECB_C99
412 #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0)) 412 #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0))
413#else 413#else
414 #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n))) 414 #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n)))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines