--- libecb/ecb.h 2012/06/29 00:56:30 1.107 +++ libecb/ecb.h 2012/06/30 21:43:58 1.110 @@ -31,7 +31,7 @@ #define ECB_H /* 16 bits major, 16 bits minor */ -#define ECB_VERSION 0x00010001 +#define ECB_VERSION 0x00010002 #ifdef _WIN32 typedef signed char int8_t; @@ -150,9 +150,16 @@ #if ECB_GCC_VERSION(4,7) /* see comment below (stdatomic.h) about the C11 memory model. */ #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST) - /*#elif defined __clang && __has_feature (cxx_atomic)*/ - /* see comment below (stdatomic.h) about the C11 memory model. */ - /*#define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST)*/ + + /* The __has_feature syntax from clang is so misdesigned that we cannot use it + * without risking compile time errors with other compilers. We *could* + * define our own ecb_clang_has_feature, but I just can't be bothered to work + * around * this shit time and again. + * #elif defined __clang && __has_feature (cxx_atomic) + * // see comment below (stdatomic.h) about the C11 memory model. + * #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST) + */ + #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ #define ECB_MEMORY_FENCE __sync_synchronize () #elif _MSC_VER >= 1400 /* VC++ 2005 */ @@ -556,6 +563,7 @@ #include /* for memcpy */ #else #define ECB_STDFP 0 + #include /* for frexp*, ldexp* */ #endif #ifndef ECB_NO_LIBM @@ -571,11 +579,10 @@ memcpy (&r, &x, 4); #else /* slow emulation, works for anything but -0 */ - ECB_EXTERN_C float frexpf (float v, int *e); uint32_t m; int e; - if (x == 0e0f ) return 0; + if (x == 0e0f ) return 0x00000000U; if (x > +3.40282346638528860e+38f) return 0x7f800000U; if (x < -3.40282346638528860e+38f) return 0xff800000U; if (x != x ) return 0x7fbfffffU; @@ -587,7 +594,7 @@ if (r) m = -m; - if (e < -125) + if (e <= -126) { m &= 0xffffffU; m >>= (-125 - e); @@ -612,8 +619,6 @@ memcpy (&r, &x, 4); #else /* emulation, only works for normals and subnormals and +0 */ - ECB_EXTERN_C float ldexpf (float x, int e); - int neg = x >> 31; int e = (x >> 23) & 0xffU; @@ -625,7 +630,7 @@ e = 1; /* we distrust ldexpf a bit and do the 2**-24 scaling by an extra multiply */ - r = ldexpf (x * (1.f / 0x1000000U), e - 126); + r = ldexpf (x * (0.5f / 0x800000U), e - 126); r = neg ? -r : r; #endif @@ -644,11 +649,10 @@ memcpy (&r, &x, 8); #else /* slow emulation, works for anything but -0 */ - ECB_EXTERN_C double frexp (double v, int *e); uint64_t m; int e; - if (x == 0e0 ) return 0; + if (x == 0e0 ) return 0x0000000000000000U; if (x > +1.79769313486231470e+308) return 0x7ff0000000000000U; if (x < -1.79769313486231470e+308) return 0xfff0000000000000U; if (x != x ) return 0X7ff7ffffffffffffU; @@ -660,7 +664,7 @@ if (r) m = -m; - if (e < -1021) + if (e <= -1022) { m &= 0x1fffffffffffffU; m >>= (-1021 - e); @@ -685,8 +689,6 @@ memcpy (&r, &x, 8); #else /* emulation, only works for normals and subnormals and +0 */ - ECB_EXTERN_C double ldexp (double x, int e); - int neg = x >> 63; int e = (x >> 52) & 0x7ffU; @@ -698,7 +700,7 @@ e = 1; /* we distrust ldexp a bit and do the 2**-53 scaling by an extra multiply */ - r = ldexp (x * (1. / 0x20000000000000U), e - 1022); + r = ldexp (x * (0.5 / 0x10000000000000U), e - 1022); r = neg ? -r : r; #endif