--- libecb/ecb.h 2011/08/04 14:47:53 1.64 +++ libecb/ecb.h 2011/09/25 21:27:02 1.69 @@ -73,8 +73,8 @@ #endif #ifndef ECB_MEMORY_FENCE - #if ECB_GCC_VERSION(2,5) - #if __x86 + #if ECB_GCC_VERSION(2,5) || defined(__INTEL_COMPILER) || defined(__clang__) + #if __i386__ #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE /* non-lock xchg might be enough */ #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */ @@ -86,16 +86,16 @@ #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") #elif defined(__ARM_ARCH_6__ ) || defined(__ARM_ARCH_6J__ ) \ || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__) - #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,4" : : "r" (0) : "memory") + #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,5" : : "r" (0) : "memory") #elif defined(__ARM_ARCH_7__ ) || defined(__ARM_ARCH_7A__ ) \ || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7R__ ) - #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dsb" : : : "memory") + #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") #endif #endif #endif #ifndef ECB_MEMORY_FENCE - #if ECB_GCC_VERSION(4,4) || defined(__INTEL_COMPILER) + #if ECB_GCC_VERSION(4,4) || defined(__INTEL_COMPILER) || defined(__clang__) #define ECB_MEMORY_FENCE __sync_synchronize () /*#define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); }) */ /*#define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); }) */ @@ -375,6 +375,22 @@ #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n))) #endif +#if __cplusplus + template + static inline T ecb_div_rd (T val, T div) + { + return val < 0 ? - ((-val + div - 1) / div) : (val ) / div; + } + template + static inline T ecb_div_ru (T val, T div) + { + return val < 0 ? - ((-val ) / div) : (val + div - 1) / div; + } +#else + #define ecb_div_rd(val,div) ((val) < 0 ? - ((-(val) + (div) - 1) / (div)) : ((val) ) / (div)) + #define ecb_div_ru(val,div) ((val) < 0 ? - ((-(val) ) / (div)) : ((val) + (div) - 1) / (div)) +#endif + #if ecb_cplusplus_does_not_suck /* does not work for local types (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm) */ template