|
|
1 | =head1 LIBECB |
|
|
2 | |
|
|
3 | You suck, we don't(tm) |
|
|
4 | |
|
|
5 | =head2 ABOUT THE HEADER |
|
|
6 | |
|
|
7 | - how to include it |
|
|
8 | - it includes inttypes.h |
|
|
9 | - no .a |
|
|
10 | - whats a bool |
1 | |
11 | |
2 | =head2 GCC ATTRIBUTES |
12 | =head2 GCC ATTRIBUTES |
|
|
13 | |
|
|
14 | blabla where to put, what others |
3 | |
15 | |
4 | =over 4 |
16 | =over 4 |
5 | |
17 | |
6 | =item ecb_attribute ((attrs...)) |
18 | =item ecb_attribute ((attrs...)) |
7 | |
19 | |
8 | A simple wrapper that expands to C<__attribute__((attrs))> on GCC, and |
20 | A simple wrapper that expands to C<__attribute__((attrs))> on GCC, and |
9 | to nothing on other compilers, so the effect is that only GCC sees these. |
21 | to nothing on other compilers, so the effect is that only GCC sees these. |
10 | |
22 | |
|
|
23 | =item ecb_unused |
|
|
24 | |
|
|
25 | Marks a function or a variable as "unused", which simply suppresses a |
|
|
26 | warning by GCC when it detects it as unused. This is useful when you e.g. |
|
|
27 | declare a variable but do not always use it: |
|
|
28 | |
|
|
29 | { |
|
|
30 | int var ecb_unused; |
|
|
31 | |
|
|
32 | #ifdef SOMECONDITION |
|
|
33 | var = ...; |
|
|
34 | return var; |
|
|
35 | #else |
|
|
36 | return 0; |
|
|
37 | #endif |
|
|
38 | } |
|
|
39 | |
11 | =item ecb_noinline |
40 | =item ecb_noinline |
12 | |
41 | |
|
|
42 | Prevent a function from being inlined - it might be optimsied away, but |
|
|
43 | not inlined into other functions. This is useful if you know your function |
|
|
44 | is rarely called and large enough for inlining not to be helpful. |
|
|
45 | |
13 | =item ecb_noreturn |
46 | =item ecb_noreturn |
14 | |
|
|
15 | =item ecb_unused |
|
|
16 | |
47 | |
17 | =item ecb_const |
48 | =item ecb_const |
18 | |
49 | |
19 | =item ecb_pure |
50 | =item ecb_pure |
20 | |
51 | |
… | |
… | |
30 | |
61 | |
31 | =over 4 |
62 | =over 4 |
32 | |
63 | |
33 | =item bool ecb_is_constant(expr) |
64 | =item bool ecb_is_constant(expr) |
34 | |
65 | |
|
|
66 | Returns true iff the expression can be deduced to be a compile-time |
|
|
67 | constant, and false otherwise. |
|
|
68 | |
|
|
69 | For example, when you have a C<rndm16> function that returns a 16 bit |
|
|
70 | random number, and you have a function that maps this to a range from |
|
|
71 | 0..n-1, then you could use this inline fucntion in a header file: |
|
|
72 | |
|
|
73 | ecb_inline uint32_t |
|
|
74 | rndm (uint32_t n) |
|
|
75 | { |
|
|
76 | return n * (uint32_t)rndm16 ()) >> 16; |
|
|
77 | } |
|
|
78 | |
|
|
79 | However, for powers of two, you could use a normal mask, but that is only |
|
|
80 | worth it if, at compile time, you can detect this case. This is the case |
|
|
81 | when the passed number is a constant and also a power of two (C<n & (n - |
|
|
82 | 1) == 0>): |
|
|
83 | |
|
|
84 | ecb_inline uint32_t |
|
|
85 | rndm (uint32_t n) |
|
|
86 | { |
|
|
87 | return is_constant (n) && !(n & (n - 1)) |
|
|
88 | ? rndm16 () & (num - 1) |
|
|
89 | : (uint32_t)rndm16 ()) >> 16; |
|
|
90 | } |
|
|
91 | |
|
|
92 | |
|
|
93 | |
35 | =item bool ecb_expect(expr,value) |
94 | =item bool ecb_expect(expr,value) |
36 | |
95 | |
37 | =item bool ecb_unlikely(bool) |
96 | =item bool ecb_unlikely(bool) |
38 | |
97 | |
39 | =item bool ecb_likely(bool) |
98 | =item bool ecb_likely(bool) |
… | |
… | |
46 | |
105 | |
47 | =back |
106 | =back |
48 | |
107 | |
49 | =head2 BIT FIDDLING / BITSTUFFS |
108 | =head2 BIT FIDDLING / BITSTUFFS |
50 | |
109 | |
51 | bool ecb_big_endian (); |
110 | =item bool ecb_big_endian () |
|
|
111 | |
52 | bool ecb_little_endian (); |
112 | =item bool ecb_little_endian () |
|
|
113 | |
53 | int ecb_ctz32 (uint32_t x); |
114 | =item int ecb_ctz32 (uint32_t x) |
|
|
115 | |
54 | int ecb_popcount32 (uint32_t x); |
116 | =item int ecb_popcount32 (uint32_t x) |
|
|
117 | |
55 | uint32_t ecb_bswap32 (uint32_t x); |
118 | =item uint32_t ecb_bswap32 (uint32_t x) |
|
|
119 | |
56 | uint32_t ecb_bswap16 (uint32_t x); |
120 | =item uint32_t ecb_bswap16 (uint32_t x) |
|
|
121 | |
57 | uint32_t ecb_rotr32 (uint32_t x, unsigned int count); |
122 | =item uint32_t ecb_rotr32 (uint32_t x, unsigned int count) |
|
|
123 | |
58 | uint32_t ecb_rotl32 (uint32_t x, unsigned int count); |
124 | =item uint32_t ecb_rotl32 (uint32_t x, unsigned int count) |
|
|
125 | |
|
|
126 | =back |
59 | |
127 | |
60 | =head2 ARITHMETIC |
128 | =head2 ARITHMETIC |
61 | |
129 | |
62 | x = ecb_mod (m, n) |
130 | =over 4 |
|
|
131 | |
|
|
132 | =item x = ecb_mod (m, n) [MACRO] |
|
|
133 | |
|
|
134 | =back |
63 | |
135 | |
64 | =head2 UTILITY |
136 | =head2 UTILITY |
65 | |
137 | |
|
|
138 | =over 4 |
|
|
139 | |
66 | ecb_array_length (name) |
140 | =item ecb_array_length (name) [MACRO] |
|
|
141 | |
|
|
142 | =back |
67 | |
143 | |
68 | |
144 | |