… | |
… | |
58 | |
58 | |
59 | =over 4 |
59 | =over 4 |
60 | |
60 | |
61 | =item ecb_attribute ((attrs...)) |
61 | =item ecb_attribute ((attrs...)) |
62 | |
62 | |
63 | A simple wrapper that expands to C<__attribute__((attrs))> on GCC, and |
63 | A simple wrapper that expands to C<__attribute__((attrs))> on GCC, and to |
64 | to nothing on other compilers, so the effect is that only GCC sees these. |
64 | nothing on other compilers, so the effect is that only GCC sees these. |
|
|
65 | |
|
|
66 | Example: use the C<deprecated> attribute on a function. |
|
|
67 | |
|
|
68 | ecb_attribute((__deprecated__)) void |
|
|
69 | do_not_use_me_anymore (void); |
65 | |
70 | |
66 | =item ecb_unused |
71 | =item ecb_unused |
67 | |
72 | |
68 | Marks a function or a variable as "unused", which simply suppresses a |
73 | Marks a function or a variable as "unused", which simply suppresses a |
69 | warning by GCC when it detects it as unused. This is useful when you e.g. |
74 | warning by GCC when it detects it as unused. This is useful when you e.g. |
70 | declare a variable but do not always use it: |
75 | declare a variable but do not always use it: |
71 | |
76 | |
72 | { |
77 | { |
73 | int var ecb_unused; |
78 | int var ecb_unused; |
74 | |
79 | |
75 | #ifdef SOMECONDITION |
80 | #ifdef SOMECONDITION |
76 | var = ...; |
81 | var = ...; |
77 | return var; |
82 | return var; |
78 | #else |
83 | #else |
79 | return 0; |
84 | return 0; |
80 | #endif |
85 | #endif |
81 | } |
86 | } |
82 | |
87 | |
83 | =item ecb_noinline |
88 | =item ecb_noinline |
84 | |
89 | |
85 | Prevent a function from being inlined - it might be optimised away, but |
90 | Prevent a function from being inlined - it might be optimised away, but |
86 | not inlined into other functions. This is useful if you know your function |
91 | not inlined into other functions. This is useful if you know your function |
… | |
… | |
139 | branch optimisations. |
144 | branch optimisations. |
140 | |
145 | |
141 | Usually, you want to use the more intuitive C<ecb_likely> and |
146 | Usually, you want to use the more intuitive C<ecb_likely> and |
142 | C<ecb_unlikely> functions instead. |
147 | C<ecb_unlikely> functions instead. |
143 | |
148 | |
144 | =item bool ecb_likely (bool) |
149 | =item bool ecb_likely (cond) |
145 | |
150 | |
146 | =item bool ecb_unlikely (bool) |
151 | =item bool ecb_unlikely (cond) |
147 | |
152 | |
148 | These two functions expect a expression that is true or false and return |
153 | These two functions expect a expression that is true or false and return |
149 | C<1> or C<0>, respectively, so when used in the condition of an C<if> or |
154 | C<1> or C<0>, respectively, so when used in the condition of an C<if> or |
150 | other conditional statement, it will not change the program: |
155 | other conditional statement, it will not change the program: |
151 | |
156 | |
… | |
… | |
275 | equivalently the number of bits set to 0 before the least significant |
280 | equivalently the number of bits set to 0 before the least significant |
276 | bit set), starting from 0. If C<x> is 0 the result is undefined. A |
281 | bit set), starting from 0. If C<x> is 0 the result is undefined. A |
277 | common use case is to compute the integer binary logarithm, i.e., |
282 | common use case is to compute the integer binary logarithm, i.e., |
278 | floor(log2(n)). For example: |
283 | floor(log2(n)). For example: |
279 | |
284 | |
280 | ecb_ctz32(3) = 0 |
285 | ecb_ctz32 (3) = 0 |
281 | ecb_ctz32(6) = 1 |
286 | ecb_ctz32 (6) = 1 |
282 | |
287 | |
283 | =item int ecb_popcount32 (uint32_t x) |
288 | =item int ecb_popcount32 (uint32_t x) |
284 | |
289 | |
285 | Returns the number of bits set to 1 in C<x>. For example: |
290 | Returns the number of bits set to 1 in C<x>. For example: |
286 | |
291 | |
287 | ecb_popcount32(7) = 3 |
292 | ecb_popcount32 (7) = 3 |
288 | ecb_popcount32(255) = 8 |
293 | ecb_popcount32 (255) = 8 |
289 | |
294 | |
290 | =item uint32_t ecb_bswap16 (uint32_t x) |
295 | =item uint32_t ecb_bswap16 (uint32_t x) |
291 | |
296 | |
292 | =item uint32_t ecb_bswap32 (uint32_t x) |
297 | =item uint32_t ecb_bswap32 (uint32_t x) |
293 | |
298 | |