… | |
… | |
111 | /* these two do the same thing */ |
111 | /* these two do the same thing */ |
112 | if (some_condition) ...; |
112 | if (some_condition) ...; |
113 | if (ecb_likely (some_condition)) ...; |
113 | if (ecb_likely (some_condition)) ...; |
114 | |
114 | |
115 | However, by using C<ecb_likely>, you tell the compiler that the condition |
115 | However, by using C<ecb_likely>, you tell the compiler that the condition |
116 | is likely to be true (and for C<ecb_unlikel>, that it is unlikely to be |
116 | is likely to be true (and for C<ecb_unlikely>, that it is unlikely to be |
117 | true). |
117 | true). |
118 | |
118 | |
119 | For example, when you check for a null pointer and expect this to be a |
119 | For example, when you check for a null pointer and expect this to be a |
120 | rare, exceptional, case, then use C<ecb_unlikely>: |
120 | rare, exceptional, case, then use C<ecb_unlikely>: |
121 | |
121 | |
… | |
… | |
222 | |
222 | |
223 | =item bool ecb_big_endian () |
223 | =item bool ecb_big_endian () |
224 | |
224 | |
225 | =item bool ecb_little_endian () |
225 | =item bool ecb_little_endian () |
226 | |
226 | |
|
|
227 | These two functions return true if the byte order is big endian |
|
|
228 | (most-significant byte first) or little endian (least-significant byte |
|
|
229 | first) respectively. |
|
|
230 | |
227 | =item int ecb_ctz32 (uint32_t x) |
231 | =item int ecb_ctz32 (uint32_t x) |
228 | |
232 | |
|
|
233 | Returns the index of the least significant bit set in C<x> (or |
|
|
234 | equivalently the number of bits set to 0 before the least significant |
|
|
235 | bit set), starting from 0. If C<x> is 0 the result is undefined. A |
|
|
236 | common use case is to compute the integer binary logarithm, i.e., |
|
|
237 | floor(log2(n)). For example: |
|
|
238 | |
|
|
239 | ecb_ctz32(3) = 1 |
|
|
240 | ecb_ctz32(6) = 2 |
|
|
241 | |
229 | =item int ecb_popcount32 (uint32_t x) |
242 | =item int ecb_popcount32 (uint32_t x) |
230 | |
243 | |
|
|
244 | Returns the number of bits set to 1 in C<x>. For example: |
|
|
245 | |
|
|
246 | ecb_popcount32(7) = 3 |
|
|
247 | ecb_popcount32(255) = 8 |
|
|
248 | |
231 | =item uint32_t ecb_bswap16 (uint32_t x) |
249 | =item uint32_t ecb_bswap16 (uint32_t x) |
232 | |
250 | |
233 | =item uint32_t ecb_bswap32 (uint32_t x) |
251 | =item uint32_t ecb_bswap32 (uint32_t x) |
234 | |
252 | |
235 | =item uint32_t ecb_rotr32 (uint32_t x, unsigned int count) |
253 | =item uint32_t ecb_rotr32 (uint32_t x, unsigned int count) |
236 | |
254 | |
237 | =item uint32_t ecb_rotl32 (uint32_t x, unsigned int count) |
255 | =item uint32_t ecb_rotl32 (uint32_t x, unsigned int count) |
238 | |
256 | |
|
|
257 | These two functions return the value of C<x> after shifting all the bits |
|
|
258 | by C<count> positions to the right or left respectively. |
|
|
259 | |
239 | =back |
260 | =back |
240 | |
261 | |
241 | =head2 ARITHMETIC |
262 | =head2 ARITHMETIC |
242 | |
263 | |
243 | =over 4 |
264 | =over 4 |
244 | |
265 | |
245 | =item x = ecb_mod (m, n) [MACRO] |
266 | =item x = ecb_mod (m, n) [MACRO] |
246 | |
267 | |
|
|
268 | Returns the positive remainder of the modulo operation between C<m> |
|
|
269 | and C<n>. |
|
|
270 | |
247 | =back |
271 | =back |
248 | |
272 | |
249 | =head2 UTILITY |
273 | =head2 UTILITY |
250 | |
274 | |
251 | =over 4 |
275 | =over 4 |