… | |
… | |
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) |
76 | #if ECB_GCC_VERSION(2,5) |
77 | #if __x86 |
77 | #if __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 |
82 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
82 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "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") |
87 | #elif defined(__ARM_ARCH_6__ ) || defined(__ARM_ARCH_6J__ ) \ |
87 | #elif defined(__ARM_ARCH_6__ ) || defined(__ARM_ARCH_6J__ ) \ |
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,4" : : "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__ ("dsb" : : : "memory") |
92 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") |
93 | #endif |
93 | #endif |
94 | #endif |
94 | #endif |
95 | #endif |
95 | #endif |
96 | |
96 | |
97 | #ifndef ECB_MEMORY_FENCE |
97 | #ifndef ECB_MEMORY_FENCE |
… | |
… | |
373 | #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0)) |
373 | #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0)) |
374 | #else |
374 | #else |
375 | #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n))) |
375 | #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n))) |
376 | #endif |
376 | #endif |
377 | |
377 | |
|
|
378 | #define ecb_div_rd(val,div) ((val) < 0 ? - ((-(val) + (div) - 1) / (div)) : ((val) ) / (div)) |
|
|
379 | #define ecb_div_ru(val,div) ((val) < 0 ? - ((-(val) ) / (div)) : ((val) + (div) - 1) / (div)) |
|
|
380 | |
378 | #if ecb_cplusplus_does_not_suck |
381 | #if ecb_cplusplus_does_not_suck |
379 | /* does not work for local types (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm) */ |
382 | /* does not work for local types (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm) */ |
380 | template<typename T, int N> |
383 | template<typename T, int N> |
381 | static inline int ecb_array_length (const T (&arr)[N]) |
384 | static inline int ecb_array_length (const T (&arr)[N]) |
382 | { |
385 | { |