--- libecb/ecb.h 2011/06/11 17:34:57 1.40 +++ libecb/ecb.h 2011/06/17 15:17:26 1.46 @@ -30,7 +30,23 @@ #ifndef ECB_H #define ECB_H -#include +#ifdef _WIN32 + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef signed short int16_t; + typedef unsigned short uint16_t; + typedef signed int int32_t; + typedef unsigned int uint32_t; + #if __GNUC__ + typedef signed long long int64_t; + typedef unsigned long long uint64_t; + #else + typedef signed __int64 int64_t; + typedef unsigned __int64 uint64_t; + #endif +#else + #include +#endif /* many compilers define _GNUC_ to some versions but then only implement * what their idiot authors think are the "more important" extensions, @@ -40,7 +56,7 @@ * an issue with that they should have done it right in the first place. */ #ifndef ECB_GCC_VERSION - #if defined(__INTEL_COMPILER) || defined(__SUNPRO_C) || defined(__llvm__) + #if defined(__INTEL_COMPILER) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__llvm__) || defined(__clang__) #define ECB_GCC_VERSION(major,minor) 0 #else #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) @@ -50,13 +66,13 @@ #define ECB_C99 (__STDC_VERSION__ >= 199901L) #if __cplusplus - #define ECB_INLINE static inline + #define ecb_inline static inline #elif ECB_GCC_VERSION(2,5) - #define ECB_INLINE static __inline__ + #define ecb_inline static __inline__ #elif ECB_C99 - #define ECB_INLINE static inline + #define ecb_inline static inline #else - #define ECB_INLINE static + #define ecb_inline static #endif #if ECB_GCC_VERSION(3,3) @@ -74,7 +90,7 @@ #define ECB_STRINGIFY_(a) # a #define ECB_STRINGIFY(a) ECB_STRINGIFY_(a) -#define ecb_function_ ECB_INLINE +#define ecb_function_ ecb_inline #if ECB_GCC_VERSION(3,1) #define ecb_attribute(attrlist) __attribute__(attrlist) @@ -120,9 +136,6 @@ #define ecb_likely(expr) ecb_expect_true (expr) #define ecb_unlikely(expr) ecb_expect_false (expr) -/* try to tell the compiler that some condition is definitely true */ -#define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0) - /* count trailing zero bits and count # of one bits */ #if ECB_GCC_VERSION(3,4) #define ecb_ctz32(x) __builtin_ctz (x) @@ -134,7 +147,7 @@ { int r = 0; - x &= -x; /* this isolates the lowest bit */ + x &= (uint32_t)-(int32_t)x; /* this isolates the lowest bit */ if (x & 0xaaaaaaaa) r += 1; if (x & 0xcccccccc) r += 2; @@ -190,6 +203,9 @@ ecb_function_ void ecb_unreachable (void) { } #endif +/* try to tell the compiler that some condition is definitely true */ +#define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0) + ecb_function_ unsigned char ecb_byteorder_helper (void) ecb_const; ecb_function_ unsigned char ecb_byteorder_helper (void) @@ -199,9 +215,9 @@ } ecb_function_ ecb_bool ecb_big_endian (void) ecb_const; -ecb_function_ ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; }; +ecb_function_ ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; } ecb_function_ ecb_bool ecb_little_endian (void) ecb_const; -ecb_function_ ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; }; +ecb_function_ ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; } #if ECB_GCC_VERSION(3,0) || ECB_C99 #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0)) @@ -220,15 +236,15 @@ #define ecb_array_length(name) (sizeof (name) / sizeof (name [0])) #endif -ECB_INLINE uint32_t ecb_rotr32 (uint32_t x, unsigned int count) ecb_const; -ECB_INLINE uint32_t +ecb_inline uint32_t ecb_rotr32 (uint32_t x, unsigned int count) ecb_const; +ecb_inline uint32_t ecb_rotr32 (uint32_t x, unsigned int count) { return (x << (32 - count)) | (x >> count); } -ECB_INLINE uint32_t ecb_rotl32 (uint32_t x, unsigned int count) ecb_const; -ECB_INLINE uint32_t +ecb_inline uint32_t ecb_rotl32 (uint32_t x, unsigned int count) ecb_const; +ecb_inline uint32_t ecb_rotl32 (uint32_t x, unsigned int count) { return (x >> (32 - count)) | (x << count);