… | |
… | |
54 | * or so. |
54 | * or so. |
55 | * we try to detect these and simply assume they are not gcc - if they have |
55 | * we try to detect these and simply assume they are not gcc - if they have |
56 | * an issue with that they should have done it right in the first place. |
56 | * an issue with that they should have done it right in the first place. |
57 | */ |
57 | */ |
58 | #ifndef ECB_GCC_VERSION |
58 | #ifndef ECB_GCC_VERSION |
59 | #if defined(__INTEL_COMPILER) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__llvm__) || defined(__clang__) |
59 | #if !defined(__GNUC_MINOR__) || defined(__INTEL_COMPILER) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__llvm__) || defined(__clang__) |
60 | #define ECB_GCC_VERSION(major,minor) 0 |
60 | #define ECB_GCC_VERSION(major,minor) 0 |
61 | #else |
61 | #else |
62 | #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
62 | #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
63 | #endif |
63 | #endif |
64 | #endif |
64 | #endif |
65 | |
65 | |
66 | #define ECB_C99 (__STDC_VERSION__ >= 199901L) |
66 | #define ECB_C99 (__STDC_VERSION__ >= 199901L) |
67 | |
67 | |
68 | #if __cplusplus |
68 | #if __cplusplus |
69 | #define ECB_INLINE static inline |
69 | #define ecb_inline static inline |
70 | #elif ECB_GCC_VERSION(2,5) |
70 | #elif ECB_GCC_VERSION(2,5) |
71 | #define ECB_INLINE static __inline__ |
71 | #define ecb_inline static __inline__ |
72 | #elif ECB_C99 |
72 | #elif ECB_C99 |
73 | #define ECB_INLINE static inline |
73 | #define ecb_inline static inline |
74 | #else |
74 | #else |
75 | #define ECB_INLINE static |
75 | #define ecb_inline static |
76 | #endif |
76 | #endif |
77 | |
77 | |
78 | #if ECB_GCC_VERSION(3,3) |
78 | #if ECB_GCC_VERSION(3,3) |
79 | #define ecb_restrict __restrict__ |
79 | #define ecb_restrict __restrict__ |
80 | #elif ECB_C99 |
80 | #elif ECB_C99 |
… | |
… | |
88 | #define ECB_CONCAT_(a, b) a ## b |
88 | #define ECB_CONCAT_(a, b) a ## b |
89 | #define ECB_CONCAT(a, b) ECB_CONCAT_(a, b) |
89 | #define ECB_CONCAT(a, b) ECB_CONCAT_(a, b) |
90 | #define ECB_STRINGIFY_(a) # a |
90 | #define ECB_STRINGIFY_(a) # a |
91 | #define ECB_STRINGIFY(a) ECB_STRINGIFY_(a) |
91 | #define ECB_STRINGIFY(a) ECB_STRINGIFY_(a) |
92 | |
92 | |
93 | #define ecb_function_ ECB_INLINE |
93 | #define ecb_function_ ecb_inline |
94 | |
94 | |
95 | #if ECB_GCC_VERSION(3,1) |
95 | #if ECB_GCC_VERSION(3,1) |
96 | #define ecb_attribute(attrlist) __attribute__(attrlist) |
96 | #define ecb_attribute(attrlist) __attribute__(attrlist) |
97 | #define ecb_is_constant(expr) __builtin_constant_p (expr) |
97 | #define ecb_is_constant(expr) __builtin_constant_p (expr) |
98 | #define ecb_expect(expr,value) __builtin_expect ((expr),(value)) |
98 | #define ecb_expect(expr,value) __builtin_expect ((expr),(value)) |
… | |
… | |
145 | ecb_function_ int |
145 | ecb_function_ int |
146 | ecb_ctz32 (uint32_t x) |
146 | ecb_ctz32 (uint32_t x) |
147 | { |
147 | { |
148 | int r = 0; |
148 | int r = 0; |
149 | |
149 | |
150 | x &= -x; /* this isolates the lowest bit */ |
150 | x &= (uint32_t)-(int32_t)x; /* this isolates the lowest bit */ |
151 | |
151 | |
152 | if (x & 0xaaaaaaaa) r += 1; |
152 | if (x & 0xaaaaaaaa) r += 1; |
153 | if (x & 0xcccccccc) r += 2; |
153 | if (x & 0xcccccccc) r += 2; |
154 | if (x & 0xf0f0f0f0) r += 4; |
154 | if (x & 0xf0f0f0f0) r += 4; |
155 | if (x & 0xff00ff00) r += 8; |
155 | if (x & 0xff00ff00) r += 8; |
… | |
… | |
234 | } |
234 | } |
235 | #else |
235 | #else |
236 | #define ecb_array_length(name) (sizeof (name) / sizeof (name [0])) |
236 | #define ecb_array_length(name) (sizeof (name) / sizeof (name [0])) |
237 | #endif |
237 | #endif |
238 | |
238 | |
239 | ECB_INLINE uint32_t ecb_rotr32 (uint32_t x, unsigned int count) ecb_const; |
239 | ecb_inline uint32_t ecb_rotr32 (uint32_t x, unsigned int count) ecb_const; |
240 | ECB_INLINE uint32_t |
240 | ecb_inline uint32_t |
241 | ecb_rotr32 (uint32_t x, unsigned int count) |
241 | ecb_rotr32 (uint32_t x, unsigned int count) |
242 | { |
242 | { |
243 | return (x << (32 - count)) | (x >> count); |
243 | return (x << (32 - count)) | (x >> count); |
244 | } |
244 | } |
245 | |
245 | |
246 | ECB_INLINE uint32_t ecb_rotl32 (uint32_t x, unsigned int count) ecb_const; |
246 | ecb_inline uint32_t ecb_rotl32 (uint32_t x, unsigned int count) ecb_const; |
247 | ECB_INLINE uint32_t |
247 | ecb_inline uint32_t |
248 | ecb_rotl32 (uint32_t x, unsigned int count) |
248 | ecb_rotl32 (uint32_t x, unsigned int count) |
249 | { |
249 | { |
250 | return (x >> (32 - count)) | (x << count); |
250 | return (x >> (32 - count)) | (x << count); |
251 | } |
251 | } |
252 | |
252 | |