… | |
… | |
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") |
|
|
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 __lwsync () |
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 | |
398 | ecb_function_ unsigned char ecb_byteorder_helper (void) ecb_const; |
408 | ecb_inline unsigned char ecb_byteorder_helper (void) ecb_const; |
399 | ecb_function_ unsigned char |
409 | ecb_inline unsigned char |
400 | ecb_byteorder_helper (void) |
410 | ecb_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 | |
406 | ecb_function_ ecb_bool ecb_big_endian (void) ecb_const; |
416 | ecb_inline ecb_bool ecb_big_endian (void) ecb_const; |
407 | ecb_function_ ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; } |
417 | ecb_inline ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; } |
408 | ecb_function_ ecb_bool ecb_little_endian (void) ecb_const; |
418 | ecb_inline ecb_bool ecb_little_endian (void) ecb_const; |
409 | ecb_function_ ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; } |
419 | ecb_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))) |