… | |
… | |
61 | |
61 | |
62 | =head2 OPTIMISATION HINTS |
62 | =head2 OPTIMISATION HINTS |
63 | |
63 | |
64 | =over 4 |
64 | =over 4 |
65 | |
65 | |
66 | =item bool ecb_is_constant(expr) |
66 | =item bool ecb_is_constant(expr) [MACRO] |
67 | |
67 | |
68 | Returns true iff the expression can be deduced to be a compile-time |
68 | Returns true iff the expression can be deduced to be a compile-time |
69 | constant, and false otherwise. |
69 | constant, and false otherwise. |
70 | |
70 | |
71 | For example, when you have a C<rndm16> function that returns a 16 bit |
71 | For example, when you have a C<rndm16> function that returns a 16 bit |
… | |
… | |
89 | return is_constant (n) && !(n & (n - 1)) |
89 | return is_constant (n) && !(n & (n - 1)) |
90 | ? rndm16 () & (num - 1) |
90 | ? rndm16 () & (num - 1) |
91 | : (n * (uint32_t)rndm16 ()) >> 16; |
91 | : (n * (uint32_t)rndm16 ()) >> 16; |
92 | } |
92 | } |
93 | |
93 | |
94 | =item bool ecb_expect (expr, value) |
94 | =item bool ecb_expect (expr, value) [MACRO] |
95 | |
95 | |
96 | Evaluates C<expr> and returns it. In addition, it tells the compiler that |
96 | Evaluates C<expr> and returns it. In addition, it tells the compiler that |
97 | the C<expr> evaluates to C<value> a lot, which can be used for static |
97 | the C<expr> evaluates to C<value> a lot, which can be used for static |
98 | branch optimisations. |
98 | branch optimisations. |
99 | |
99 | |
100 | Usually, you want to use the more intuitive C<ecb_likely> and |
100 | Usually, you want to use the more intuitive C<ecb_likely> and |
101 | C<ecb_unlikely> functions instead. |
101 | C<ecb_unlikely> functions instead. |
102 | |
102 | |
103 | =item bool ecb_likely (bool) |
103 | =item bool ecb_likely (bool) [MACRO] |
104 | |
104 | |
105 | =item bool ecb_unlikely (bool) |
105 | =item bool ecb_unlikely (bool) [MACRO] |
106 | |
106 | |
107 | These two functions expect a expression that is true or false and return |
107 | These two functions expect a expression that is true or false and return |
108 | C<1> or C<0>, respectively, so when used in the condition of an C<if> or |
108 | C<1> or C<0>, respectively, so when used in the condition of an C<if> or |
109 | other conditional statement, it will not change the program: |
109 | other conditional statement, it will not change the program: |
110 | |
110 | |
… | |
… | |
140 | { |
140 | { |
141 | if (ecb_unlikely (current + size > end)) |
141 | if (ecb_unlikely (current + size > end)) |
142 | real_reserve_method (size); /* presumably noinline */ |
142 | real_reserve_method (size); /* presumably noinline */ |
143 | } |
143 | } |
144 | |
144 | |
145 | =item bool ecb_assume (cond) |
145 | =item bool ecb_assume (cond) [MACRO] |
146 | |
146 | |
147 | Try to tell the compiler that some condition is true, even if it's not |
147 | Try to tell the compiler that some condition is true, even if it's not |
148 | obvious. |
148 | obvious. |
149 | |
149 | |
150 | This can be used to teach the compiler about invariants or other |
150 | This can be used to teach the compiler about invariants or other |
… | |
… | |
176 | |
176 | |
177 | This function does nothing itself, except tell the compiler that it will |
177 | This function does nothing itself, except tell the compiler that it will |
178 | never be executed. Apart from supressing a warning in some cases, this |
178 | never be executed. Apart from supressing a warning in some cases, this |
179 | function can be used to implement C<ecb_assume> or similar functions. |
179 | function can be used to implement C<ecb_assume> or similar functions. |
180 | |
180 | |
181 | =item bool ecb_prefetch (addr, rw, locality) |
181 | =item bool ecb_prefetch (addr, rw, locality) [MACRO] |
182 | |
182 | |
183 | Tells the compiler to try to prefetch memory at the given C<addr>ess |
183 | Tells the compiler to try to prefetch memory at the given C<addr>ess |
184 | for either reading (c<rw> = 0) or writing (C<rw> = 1). A C<locality> of |
184 | for either reading (c<rw> = 0) or writing (C<rw> = 1). A C<locality> of |
185 | C<0> means that there will only be one access later, C<3> means that |
185 | C<0> means that there will only be one access later, C<3> means that |
186 | the data will likely be accessed very often, and values in between mean |
186 | the data will likely be accessed very often, and values in between mean |
… | |
… | |
226 | |
226 | |
227 | =item int ecb_ctz32 (uint32_t x) |
227 | =item int ecb_ctz32 (uint32_t x) |
228 | |
228 | |
229 | =item int ecb_popcount32 (uint32_t x) |
229 | =item int ecb_popcount32 (uint32_t x) |
230 | |
230 | |
|
|
231 | =item uint32_t ecb_bswap16 (uint32_t x) |
|
|
232 | |
231 | =item uint32_t ecb_bswap32 (uint32_t x) |
233 | =item uint32_t ecb_bswap32 (uint32_t x) |
232 | |
234 | |
233 | =item uint32_t ecb_bswap16 (uint32_t x) |
|
|
234 | |
|
|
235 | =item uint32_t ecb_rotr32 (uint32_t x, unsigned int count) |
235 | =item uint32_t ecb_rotr32 (uint32_t x, unsigned int count) |
236 | |
236 | |
237 | =item uint32_t ecb_rotl32 (uint32_t x, unsigned int count) |
237 | =item uint32_t ecb_rotl32 (uint32_t x, unsigned int count) |
238 | |
238 | |
239 | =back |
239 | =back |
… | |
… | |
248 | |
248 | |
249 | =head2 UTILITY |
249 | =head2 UTILITY |
250 | |
250 | |
251 | =over 4 |
251 | =over 4 |
252 | |
252 | |
253 | =item ecb_array_length (name) [MACRO] |
253 | =item element_count = ecb_array_length (name) [MACRO] |
254 | |
254 | |
255 | =back |
255 | =back |
256 | |
256 | |
257 | |
257 | |