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

Comparing libecb/ecb.h (file contents):
Revision 1.75 by root, Wed Jan 25 19:57:49 2012 UTC vs.
Revision 1.84 by root, Thu Mar 29 22:29:57 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__
84 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */ 88 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */
85 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ 89 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__
86 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") 90 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
87 #elif defined(__ARM_ARCH_6__ ) || defined(__ARM_ARCH_6J__ ) \ 91 #elif defined(__ARM_ARCH_6__ ) || defined(__ARM_ARCH_6J__ ) \
88 || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__) 92 || 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") 93 #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__ ) \ 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")
103 #elif defined(__mips__)
104 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
97 #endif 105 #endif
98 #endif 106 #endif
99#endif 107#endif
100 108
101#ifndef ECB_MEMORY_FENCE 109#ifndef ECB_MEMORY_FENCE
114 #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 122 #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
115 #include <mbarrier.h> 123 #include <mbarrier.h>
116 #define ECB_MEMORY_FENCE __machine_rw_barrier () 124 #define ECB_MEMORY_FENCE __machine_rw_barrier ()
117 #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () 125 #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier ()
118 #define ECB_MEMORY_FENCE_RELEASE __machine_w_barrier () 126 #define ECB_MEMORY_FENCE_RELEASE __machine_w_barrier ()
127 #elif __xlC__
128 #define ECB_MEMORY_FENCE __sync ()
119 #endif 129 #endif
120#endif 130#endif
121 131
122#ifndef ECB_MEMORY_FENCE 132#ifndef ECB_MEMORY_FENCE
123 #if !ECB_AVOID_PTHREADS 133 #if !ECB_AVOID_PTHREADS
393#endif 403#endif
394 404
395/* try to tell the compiler that some condition is definitely true */ 405/* try to tell the compiler that some condition is definitely true */
396#define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0) 406#define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0)
397 407
398ecb_function_ unsigned char ecb_byteorder_helper (void) ecb_const; 408ecb_inline unsigned char ecb_byteorder_helper (void) ecb_const;
399ecb_function_ unsigned char 409ecb_inline unsigned char
400ecb_byteorder_helper (void) 410ecb_byteorder_helper (void)
401{ 411{
402 const uint32_t u = 0x11223344; 412 const uint32_t u = 0x11223344;
403 return *(unsigned char *)&u; 413 return *(unsigned char *)&u;
404} 414}
405 415
406ecb_function_ ecb_bool ecb_big_endian (void) ecb_const; 416ecb_inline ecb_bool ecb_big_endian (void) ecb_const;
407ecb_function_ ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; } 417ecb_inline ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; }
408ecb_function_ ecb_bool ecb_little_endian (void) ecb_const; 418ecb_inline ecb_bool ecb_little_endian (void) ecb_const;
409ecb_function_ ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; } 419ecb_inline ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; }
410 420
411#if ECB_GCC_VERSION(3,0) || ECB_C99 421#if ECB_GCC_VERSION(3,0) || ECB_C99
412 #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0)) 422 #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0))
413#else 423#else
414 #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n))) 424 #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n)))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines