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

Comparing libecb/ecb.h (file contents):
Revision 1.74 by root, Wed Jan 18 12:51:44 2012 UTC vs.
Revision 1.79 by root, Sat Feb 4 17:57:47 2012 UTC

66/*****************************************************************************/ 66/*****************************************************************************/
67 67
68/* ECB_NO_THREADS - ecb is not used by multiple threads, ever */ 68/* ECB_NO_THREADS - ecb is not used by multiple threads, ever */
69/* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */ 69/* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */
70 70
71#if ECB_NO_THREADS
72# define ECB_NO_SMP 1
73#endif
74
71#if ECB_NO_THREADS || ECB_NO_SMP 75#if ECB_NO_THREADS || ECB_NO_SMP
72 #define ECB_MEMORY_FENCE do { } while (0) 76 #define ECB_MEMORY_FENCE do { } while (0)
73#endif 77#endif
74 78
75#ifndef ECB_MEMORY_FENCE 79#ifndef ECB_MEMORY_FENCE
76 #if ECB_GCC_VERSION(2,5) || defined(__INTEL_COMPILER) || defined(__clang__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 80 #if ECB_GCC_VERSION(2,5) || defined(__INTEL_COMPILER) || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
77 #if __i386 || __i386__ 81 #if __i386 || __i386__
78 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") 82 #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 */ 83 #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 */ 84 #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */
81 #elif __amd64 || __amd64__ || __x86_64 || __x86_64__ 85 #elif __amd64 || __amd64__ || __x86_64 || __x86_64__
90 #elif defined(__ARM_ARCH_7__ ) || defined(__ARM_ARCH_7A__ ) \ 94 #elif defined(__ARM_ARCH_7__ ) || defined(__ARM_ARCH_7A__ ) \
91 || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7R__ ) 95 || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7R__ )
92 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") 96 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory")
93 #elif __sparc || __sparc__ 97 #elif __sparc || __sparc__
94 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad | " : : : "memory") 98 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad | " : : : "memory")
95 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") 99 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory")
96 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") 100 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore")
101 #elif defined(__s390__) || defined(__s390x__)
102 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory")
97 #endif 103 #endif
98 #endif 104 #endif
99#endif 105#endif
100 106
101#ifndef ECB_MEMORY_FENCE 107#ifndef ECB_MEMORY_FENCE
386 392
387#if ECB_GCC_VERSION(4,5) 393#if ECB_GCC_VERSION(4,5)
388 #define ecb_unreachable() __builtin_unreachable () 394 #define ecb_unreachable() __builtin_unreachable ()
389#else 395#else
390 /* this seems to work fine, but gcc always emits a warning for it :/ */ 396 /* this seems to work fine, but gcc always emits a warning for it :/ */
391 ecb_function_ void ecb_unreachable (void) ecb_noreturn; 397 ecb_inline void ecb_unreachable (void) ecb_noreturn;
392 ecb_function_ void ecb_unreachable (void) { } 398 ecb_inline void ecb_unreachable (void) { }
393#endif 399#endif
394 400
395/* try to tell the compiler that some condition is definitely true */ 401/* try to tell the compiler that some condition is definitely true */
396#define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0) 402#define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0)
397 403
398ecb_function_ unsigned char ecb_byteorder_helper (void) ecb_const; 404ecb_inline unsigned char ecb_byteorder_helper (void) ecb_const;
399ecb_function_ unsigned char 405ecb_inline unsigned char
400ecb_byteorder_helper (void) 406ecb_byteorder_helper (void)
401{ 407{
402 const uint32_t u = 0x11223344; 408 const uint32_t u = 0x11223344;
403 return *(unsigned char *)&u; 409 return *(unsigned char *)&u;
404} 410}
405 411
406ecb_function_ ecb_bool ecb_big_endian (void) ecb_const; 412ecb_inline ecb_bool ecb_big_endian (void) ecb_const;
407ecb_function_ ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; } 413ecb_inline ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; }
408ecb_function_ ecb_bool ecb_little_endian (void) ecb_const; 414ecb_inline ecb_bool ecb_little_endian (void) ecb_const;
409ecb_function_ ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; } 415ecb_inline ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; }
410 416
411#if ECB_GCC_VERSION(3,0) || ECB_C99 417#if ECB_GCC_VERSION(3,0) || ECB_C99
412 #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0)) 418 #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0))
413#else 419#else
414 #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n))) 420 #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n)))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines