--- libecb/ecb.h 2011/05/26 17:57:32 1.10 +++ libecb/ecb.h 2011/05/26 18:21:04 1.13 @@ -32,7 +32,17 @@ #include -#define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) +/* many compilers define _GNUC_ to some versions but then only implement + * what their idiot authors think are the "more important" extensions, + * causing enourmous grief for some better fake benchmark numbers or so. + * we try to detect these and simply assume they are not gcc - if they have + * an issue with that they should have done it right in the first place. + */ +#if defined(__INTEL_COMPILER) || defined(__SUNPRO_C) || defined(__llvm__) +# define ECB_GCC_VERSION(major,minor) 0 +#else +# define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) +#endif #ifndef __cplusplus # if __STDC_VERSION__ >= 199901L @@ -78,19 +88,11 @@ #define ecb_hot ecb_attribute ((hot)) /* 4.3 */ #define ecb_cold ecb_attribute ((cold)) /* 4.3 */ -#if ECB_GCC_VERSION(4,5) -# define ecb_unreachable() __builtin_unreachable () -#else -/* this seems to work fine, but gcc always emits a warning for it :/ */ -ECB_HEADER_INLINE void ecb_unreachable () ecb_attribute ((noreturn)); -ECB_HEADER_INLINE void ecb_unreachable () { } -#endif - /* put into ifs if you are very sure that the expression */ /* is mostly true or mosty false. note that these return */ /* booleans, not the expression. */ -#define ecb_unlikely(expr) ecb_expect ((expr) ? 1 : 0, 0) -#define ecb_likely(expr) ecb_expect ((expr) ? 1 : 0, 1) +#define ecb_unlikely(expr) ecb_expect (!!(expr), 0) +#define ecb_likely(expr) ecb_expect (!!(expr), 1) /* try to tell the compiler that some condition is definitely true */ #define ecb_assume(cond) do { if (!(cond)) unreachable (); } while (0) @@ -128,6 +130,27 @@ } #endif +#if ECB_GCC_VERSION(4,3) +ECB_GCC_VERSION uint32_t ecb_bswap32 (uint32_t x) { return __builtin_bswap32 (x); } +#else +ECB_GCC_VERSION uint32_t +ecb_bswap32 (uint32_t x) +{ + return (x >> 24) + | ((x >> 8) & 0x0000ff00) + | ((x << 8) & 0x00ff0000) + | (x << 24); +} +#endif + +#if ECB_GCC_VERSION(4,5) +# define ecb_unreachable() __builtin_unreachable () +#else +/* this seems to work fine, but gcc always emits a warning for it :/ */ +ECB_HEADER_INLINE void ecb_unreachable () ecb_attribute ((noreturn)); +ECB_HEADER_INLINE void ecb_unreachable () { } +#endif + ECB_HEADER_INLINE unsigned char ecb_byteorder_helper () ecb_const { @@ -161,18 +184,5 @@ return (x >> (32 - count)) | (x << count); } -#if ECB_GCC_VERSION(4,3) -# define ecb_bswap32(x) __builtin_bswap32 (x) -#else -ECB_GCC_VERSION uint32_t -ecb_bswap32 (uint32_t x) -{ - return (x >> 24) - | ((x >> 8) & 0x0000ff00) - | ((x << 8) & 0x00ff0000) - | (x << 24); -} -#endif - #endif