… | |
… | |
64 | |
64 | |
65 | #define ECB_HEADER_INLINE static ECB_INLINE |
65 | #define ECB_HEADER_INLINE static ECB_INLINE |
66 | |
66 | |
67 | #if ECB_GCC_VERSION(3,1) |
67 | #if ECB_GCC_VERSION(3,1) |
68 | # define ecb_attribute(attrlist) __attribute__(attrlist) |
68 | # define ecb_attribute(attrlist) __attribute__(attrlist) |
69 | # define ecb_is_constant(c) __builtin_constant_p (c) |
69 | # define ecb_is_constant(expr) __builtin_constant_p (expr) |
70 | # define ecb_expect(expr,value) __builtin_expect ((expr),(value)) |
70 | # define ecb_expect(expr,value) __builtin_expect ((expr),(value)) |
71 | # define ecb_prefetch(addr,rw,locality) __builtin_prefetch (addr, rw, locality) |
71 | # define ecb_prefetch(addr,rw,locality) __builtin_prefetch (addr, rw, locality) |
72 | #else |
72 | #else |
73 | # define ecb_attribute(attrlist) |
73 | # define ecb_attribute(attrlist) |
74 | # define ecb_is_constant(c) 0 |
74 | # define ecb_is_constant(expr) 0 |
75 | # define ecb_expect(expr,value) (expr) |
75 | # define ecb_expect(expr,value) (expr) |
76 | # define ecb_prefetch(addr,rw,locality) |
76 | # define ecb_prefetch(addr,rw,locality) |
77 | #endif |
77 | #endif |
78 | |
78 | |
79 | /* no emulation for ecb_decltype */ |
79 | /* no emulation for ecb_decltype */ |
… | |
… | |
89 | #define ecb_const ecb_attribute ((const)) |
89 | #define ecb_const ecb_attribute ((const)) |
90 | #define ecb_pure ecb_attribute ((pure)) |
90 | #define ecb_pure ecb_attribute ((pure)) |
91 | #define ecb_hot ecb_attribute ((hot)) /* 4.3 */ |
91 | #define ecb_hot ecb_attribute ((hot)) /* 4.3 */ |
92 | #define ecb_cold ecb_attribute ((cold)) /* 4.3 */ |
92 | #define ecb_cold ecb_attribute ((cold)) /* 4.3 */ |
93 | |
93 | |
94 | /* put into ifs if you are very sure that the expression */ |
94 | /* put into if's if you are very sure that the expression */ |
95 | /* is mostly true or mosty false. note that these return */ |
95 | /* is mostly true or mosty false. note that these return */ |
96 | /* booleans, not the expression. */ |
96 | /* booleans, not the expression. */ |
97 | #define ecb_unlikely(expr) ecb_expect (!!(expr), 0) |
97 | #define ecb_unlikely(expr) ecb_expect (!!(expr), 0) |
98 | #define ecb_likely(expr) ecb_expect (!!(expr), 1) |
98 | #define ecb_likely(expr) ecb_expect (!!(expr), 1) |
99 | |
99 | |
… | |
… | |
165 | /* this seems to work fine, but gcc always emits a warning for it :/ */ |
165 | /* this seems to work fine, but gcc always emits a warning for it :/ */ |
166 | ECB_HEADER_INLINE void ecb_unreachable (void) ecb_noreturn; |
166 | ECB_HEADER_INLINE void ecb_unreachable (void) ecb_noreturn; |
167 | ECB_HEADER_INLINE void ecb_unreachable (void) { } |
167 | ECB_HEADER_INLINE void ecb_unreachable (void) { } |
168 | #endif |
168 | #endif |
169 | |
169 | |
170 | ECB_HEADER_INLINE unsigned char ecb_byteorder_helper () ecb_const; |
170 | ECB_HEADER_INLINE unsigned char ecb_byteorder_helper (void) ecb_const; |
171 | ECB_HEADER_INLINE unsigned char |
171 | ECB_HEADER_INLINE unsigned char |
172 | ecb_byteorder_helper () |
172 | ecb_byteorder_helper (void) |
173 | { |
173 | { |
174 | const uint32_t u = 0x11223344; |
174 | const uint32_t u = 0x11223344; |
175 | return *(unsigned char *)&u; |
175 | return *(unsigned char *)&u; |
176 | } |
176 | } |
177 | |
177 | |
178 | ECB_HEADER_INLINE ecb_bool ecb_big_endian () ecb_const; |
178 | ECB_HEADER_INLINE ecb_bool ecb_big_endian (void) ecb_const; |
179 | ECB_HEADER_INLINE ecb_bool ecb_big_endian () { return ecb_byteorder_helper () == 0x11; }; |
179 | ECB_HEADER_INLINE ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; }; |
180 | ECB_HEADER_INLINE ecb_bool ecb_little_endian () ecb_const; |
180 | ECB_HEADER_INLINE ecb_bool ecb_little_endian (void) ecb_const; |
181 | ECB_HEADER_INLINE ecb_bool ecb_little_endian () { return ecb_byteorder_helper () == 0x44; }; |
181 | ECB_HEADER_INLINE ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; }; |
182 | |
182 | |
183 | #define ecb_mod(m, n) ((m) < 0 ? ((n) - (-(m) % (n))) : ((m) % (n))) |
183 | #define ecb_mod(m, n) ((m) < 0 ? ((n) - (-(m) % (n))) : ((m) % (n))) |
184 | |
184 | |
185 | #if ecb_cplusplus_does_not_suck |
185 | #if ecb_cplusplus_does_not_suck |
186 | // does not work for local types (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm) |
186 | // does not work for local types (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm) |