… | |
… | |
86 | #define ecb_const ecb_attribute ((const)) |
86 | #define ecb_const ecb_attribute ((const)) |
87 | #define ecb_pure ecb_attribute ((pure)) |
87 | #define ecb_pure ecb_attribute ((pure)) |
88 | #define ecb_hot ecb_attribute ((hot)) /* 4.3 */ |
88 | #define ecb_hot ecb_attribute ((hot)) /* 4.3 */ |
89 | #define ecb_cold ecb_attribute ((cold)) /* 4.3 */ |
89 | #define ecb_cold ecb_attribute ((cold)) /* 4.3 */ |
90 | |
90 | |
91 | #if ECB_GCC_VERSION(4,5) |
|
|
92 | # define ecb_unreachable() __builtin_unreachable () |
|
|
93 | #else |
|
|
94 | /* this seems to work fine, but gcc always emits a warning for it :/ */ |
|
|
95 | ECB_HEADER_INLINE void ecb_unreachable () ecb_attribute ((noreturn)); |
|
|
96 | ECB_HEADER_INLINE void ecb_unreachable () { } |
|
|
97 | #endif |
|
|
98 | |
|
|
99 | /* put into ifs if you are very sure that the expression */ |
91 | /* put into ifs if you are very sure that the expression */ |
100 | /* is mostly true or mosty false. note that these return */ |
92 | /* is mostly true or mosty false. note that these return */ |
101 | /* booleans, not the expression. */ |
93 | /* booleans, not the expression. */ |
102 | #define ecb_unlikely(expr) ecb_expect (!!(expr), 0) |
94 | #define ecb_unlikely(expr) ecb_expect (!!(expr), 0) |
103 | #define ecb_likely(expr) ecb_expect (!!(expr), 1) |
95 | #define ecb_likely(expr) ecb_expect (!!(expr), 1) |
… | |
… | |
136 | |
128 | |
137 | return x >> 24; |
129 | return x >> 24; |
138 | } |
130 | } |
139 | #endif |
131 | #endif |
140 | |
132 | |
|
|
133 | #if ECB_GCC_VERSION(4,3) |
|
|
134 | ECB_GCC_VERSION uint32_t ecb_bswap32 (uint32_t x) { return __builtin_bswap32 (x); } |
|
|
135 | #else |
|
|
136 | ECB_GCC_VERSION uint32_t |
|
|
137 | ecb_bswap32 (uint32_t x) |
|
|
138 | { |
|
|
139 | return (x >> 24) |
|
|
140 | | ((x >> 8) & 0x0000ff00) |
|
|
141 | | ((x << 8) & 0x00ff0000) |
|
|
142 | | (x << 24); |
|
|
143 | } |
|
|
144 | #endif |
|
|
145 | |
|
|
146 | #if ECB_GCC_VERSION(4,5) |
|
|
147 | # define ecb_unreachable() __builtin_unreachable () |
|
|
148 | #else |
|
|
149 | /* this seems to work fine, but gcc always emits a warning for it :/ */ |
|
|
150 | ECB_HEADER_INLINE void ecb_unreachable () ecb_attribute ((noreturn)); |
|
|
151 | ECB_HEADER_INLINE void ecb_unreachable () { } |
|
|
152 | #endif |
|
|
153 | |
141 | ECB_HEADER_INLINE unsigned char |
154 | ECB_HEADER_INLINE unsigned char |
142 | ecb_byteorder_helper () ecb_const |
155 | ecb_byteorder_helper () ecb_const |
143 | { |
156 | { |
144 | const uint32_t u = 0x11223344; |
157 | const uint32_t u = 0x11223344; |
145 | return *(unsigned char *)&u; |
158 | return *(unsigned char *)&u; |
… | |
… | |
169 | ecb_rotl32 (uint32_t x, unsigned int count) |
182 | ecb_rotl32 (uint32_t x, unsigned int count) |
170 | { |
183 | { |
171 | return (x >> (32 - count)) | (x << count); |
184 | return (x >> (32 - count)) | (x << count); |
172 | } |
185 | } |
173 | |
186 | |
174 | #if ECB_GCC_VERSION(4,3) |
|
|
175 | ECB_GCC_VERSION uint32_t ecb_bswap32 (uint32_t x) { return __builtin_bswap32 (x); } |
|
|
176 | #else |
|
|
177 | ECB_GCC_VERSION uint32_t |
|
|
178 | ecb_bswap32 (uint32_t x) |
|
|
179 | { |
|
|
180 | return (x >> 24) |
|
|
181 | | ((x >> 8) & 0x0000ff00) |
|
|
182 | | ((x << 8) & 0x00ff0000) |
|
|
183 | | (x << 24); |
|
|
184 | } |
|
|
185 | #endif |
187 | #endif |
186 | |
188 | |
187 | #endif |
|
|
188 | |
|
|