… | |
… | |
30 | #ifndef ECB_H |
30 | #ifndef ECB_H |
31 | #define ECB_H |
31 | #define ECB_H |
32 | |
32 | |
33 | #include <inttypes.h> |
33 | #include <inttypes.h> |
34 | |
34 | |
|
|
35 | /* many compilers define _GNUC_ to some versions but then only implement |
|
|
36 | * what their idiot authors think are the "more important" extensions, |
|
|
37 | * causing enourmous grief for some better fake benchmark numbers or so. |
|
|
38 | * we try to detect these and simply assume they are not gcc - if they have |
|
|
39 | * an issue with that they should have done it right in the first place. |
|
|
40 | */ |
|
|
41 | #if defined(__INTEL_COMPILER) || defined(__SUNPRO_C) || defined(__llvm__) |
|
|
42 | # define ECB_GCC_VERSION(major,minor) 0 |
|
|
43 | #else |
35 | #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
44 | # define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
|
|
45 | #endif |
36 | |
46 | |
37 | #ifndef __cplusplus |
47 | #ifndef __cplusplus |
38 | # if __STDC_VERSION__ >= 199901L |
48 | # if __STDC_VERSION__ >= 199901L |
39 | # define ECB_INLINE inline |
49 | # define ECB_INLINE inline |
40 | typedef _Bool ecb_bool; |
50 | typedef _Bool ecb_bool; |
… | |
… | |
87 | #endif |
97 | #endif |
88 | |
98 | |
89 | /* put into ifs if you are very sure that the expression */ |
99 | /* put into ifs if you are very sure that the expression */ |
90 | /* is mostly true or mosty false. note that these return */ |
100 | /* is mostly true or mosty false. note that these return */ |
91 | /* booleans, not the expression. */ |
101 | /* booleans, not the expression. */ |
92 | #define ecb_unlikely(expr) ecb_expect ((expr) ? 1 : 0, 0) |
102 | #define ecb_unlikely(expr) ecb_expect (!!(expr), 0) |
93 | #define ecb_likely(expr) ecb_expect ((expr) ? 1 : 0, 1) |
103 | #define ecb_likely(expr) ecb_expect (!!(expr), 1) |
94 | |
104 | |
95 | /* try to tell the compiler that some condition is definitely true */ |
105 | /* try to tell the compiler that some condition is definitely true */ |
96 | #define ecb_assume(cond) do { if (!(cond)) unreachable (); } while (0) |
106 | #define ecb_assume(cond) do { if (!(cond)) unreachable (); } while (0) |
97 | |
107 | |
98 | /* count trailing zero bits and count # of one bits */ |
108 | /* count trailing zero bits and count # of one bits */ |
… | |
… | |
160 | { |
170 | { |
161 | return (x >> (32 - count)) | (x << count); |
171 | return (x >> (32 - count)) | (x << count); |
162 | } |
172 | } |
163 | |
173 | |
164 | #if ECB_GCC_VERSION(4,3) |
174 | #if ECB_GCC_VERSION(4,3) |
165 | # define ecb_bswap32(x) __builtin_bswap32 (x) |
175 | ECB_GCC_VERSION uint32_t ecb_bswap32 (uint32_t x) { return __builtin_bswap32 (x); } |
166 | #else |
176 | #else |
167 | ECB_GCC_VERSION uint32_t |
177 | ECB_GCC_VERSION uint32_t |
168 | ecb_bswap32 (uint32_t x) |
178 | ecb_bswap32 (uint32_t x) |
169 | { |
179 | { |
170 | return (x >> 24) |
180 | return (x >> 24) |