… | |
… | |
3 | =head2 ABOUT LIBECB |
3 | =head2 ABOUT LIBECB |
4 | |
4 | |
5 | Libecb is currently a simple header file that doesn't require any |
5 | Libecb is currently a simple header file that doesn't require any |
6 | configuration to use or include in your project. |
6 | configuration to use or include in your project. |
7 | |
7 | |
8 | It's part of the e-suite of libraries, other memembers of which include |
8 | It's part of the e-suite of libraries, other members of which include |
9 | libev and libeio. |
9 | libev and libeio. |
10 | |
10 | |
11 | Its homepage can be found here: |
11 | Its homepage can be found here: |
12 | |
12 | |
13 | http://software.schmorp.de/pkg/libecb |
13 | http://software.schmorp.de/pkg/libecb |
14 | |
14 | |
15 | It mainly provides a number of wrappers around GCC built-ins, together |
15 | It mainly provides a number of wrappers around GCC built-ins, together |
16 | with replacement functions for other compilers. In addition to this, |
16 | with replacement functions for other compilers. In addition to this, |
17 | it provides a number of other lowlevel C utilities, such endienness |
17 | it provides a number of other lowlevel C utilities, such as endianness |
18 | detection, byte swapping or bit rotations. |
18 | detection, byte swapping or bit rotations. |
19 | |
19 | |
20 | More might come. |
20 | More might come. |
21 | |
21 | |
22 | =head2 ABOUT THE HEADER |
22 | =head2 ABOUT THE HEADER |
… | |
… | |
27 | #include <ecb.h> |
27 | #include <ecb.h> |
28 | |
28 | |
29 | The header should work fine for both C and C++ compilation, and gives you |
29 | The header should work fine for both C and C++ compilation, and gives you |
30 | all of F<inttypes.h> in addition to the ECB symbols. |
30 | all of F<inttypes.h> in addition to the ECB symbols. |
31 | |
31 | |
32 | There are currently no objetc files to link to - future versions might |
32 | There are currently no object files to link to - future versions might |
33 | come with an (optional) object code library to link against, to reduce |
33 | come with an (optional) object code library to link against, to reduce |
34 | code size or gain access to additional features. |
34 | code size or gain access to additional features. |
35 | |
35 | |
36 | It also currently includes everything from F<inttypes.h>. |
36 | It also currently includes everything from F<inttypes.h>. |
37 | |
37 | |
… | |
… | |
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 | |
… | |
… | |
308 | =over 4 |
313 | =over 4 |
309 | |
314 | |
310 | =item x = ecb_mod (m, n) |
315 | =item x = ecb_mod (m, n) |
311 | |
316 | |
312 | Returns the positive remainder of the modulo operation between C<m> and |
317 | Returns the positive remainder of the modulo operation between C<m> and |
313 | C<n>. Unlike the C moduloe operator C<%>, this function ensures that the |
318 | C<n>. Unlike the C modulo operator C<%>, this function ensures that the |
314 | return value is always positive). |
319 | return value is always positive). |
315 | |
320 | |
316 | C<n> must be strictly positive (i.e. C<< >1 >>), while C<m> must be |
321 | C<n> must be strictly positive (i.e. C<< >1 >>), while C<m> must be |
317 | negatable, that is, both C<m> and C<-m> must be representable in its |
322 | negatable, that is, both C<m> and C<-m> must be representable in its |
318 | type. |
323 | type. |