… | |
… | |
100 | return var; |
100 | return var; |
101 | #else |
101 | #else |
102 | return 0; |
102 | return 0; |
103 | #endif |
103 | #endif |
104 | } |
104 | } |
|
|
105 | |
|
|
106 | =item ecb_inline |
|
|
107 | |
|
|
108 | This is not actually an attribute, but you use it like one. It expands |
|
|
109 | either to C<static inline> or to just C<static>, if inline isn't |
|
|
110 | supported. It should be used to declare functions that should be inlined, |
|
|
111 | for code size or speed reasons. |
|
|
112 | |
|
|
113 | Example: inline this function, it surely will reduce codesize. |
|
|
114 | |
|
|
115 | ecb_inline int |
|
|
116 | negmul (int a, int b) |
|
|
117 | { |
|
|
118 | return - (a * b); |
|
|
119 | } |
105 | |
120 | |
106 | =item ecb_noinline |
121 | =item ecb_noinline |
107 | |
122 | |
108 | Prevent a function from being inlined - it might be optimised away, but |
123 | Prevent a function from being inlined - it might be optimised away, but |
109 | not inlined into other functions. This is useful if you know your function |
124 | not inlined into other functions. This is useful if you know your function |
… | |
… | |
399 | |
414 | |
400 | =item int ecb_ctz32 (uint32_t x) |
415 | =item int ecb_ctz32 (uint32_t x) |
401 | |
416 | |
402 | Returns the index of the least significant bit set in C<x> (or |
417 | Returns the index of the least significant bit set in C<x> (or |
403 | equivalently the number of bits set to 0 before the least significant bit |
418 | equivalently the number of bits set to 0 before the least significant bit |
404 | set), starting from 0. If C<x> is 0 the result is undefined. A common use |
419 | set), starting from 0. If C<x> is 0 the result is undefined. For example: |
405 | case is to compute the integer binary logarithm, i.e., C<floor (log2 |
|
|
406 | (n))>. For example: |
|
|
407 | |
420 | |
408 | ecb_ctz32 (3) = 0 |
421 | ecb_ctz32 (3) = 0 |
409 | ecb_ctz32 (6) = 1 |
422 | ecb_ctz32 (6) = 1 |
410 | |
423 | |
411 | =item int ecb_popcount32 (uint32_t x) |
424 | =item int ecb_popcount32 (uint32_t x) |
… | |
… | |
448 | C<ecb_mod> implements the mathematical modulo operation, which is missing |
461 | C<ecb_mod> implements the mathematical modulo operation, which is missing |
449 | in the language. |
462 | in the language. |
450 | |
463 | |
451 | C<n> must be strictly positive (i.e. C<< >= 1 >>), while C<m> must be |
464 | C<n> must be strictly positive (i.e. C<< >= 1 >>), while C<m> must be |
452 | negatable, that is, both C<m> and C<-m> must be representable in its |
465 | negatable, that is, both C<m> and C<-m> must be representable in its |
453 | type (this typically includes the minimum signed integer value, the same |
466 | type (this typically excludes the minimum signed integer value, the same |
454 | limitation as for C</> and C<%> in C). |
467 | limitation as for C</> and C<%> in C). |
455 | |
468 | |
456 | Current GCC versions compile this into an efficient branchless sequence on |
469 | Current GCC versions compile this into an efficient branchless sequence on |
457 | many systems. |
470 | almost all CPUs. |
458 | |
471 | |
459 | For example, when you want to rotate forward through the members of an |
472 | For example, when you want to rotate forward through the members of an |
460 | array for increasing C<m> (which might be negative), then you should use |
473 | array for increasing C<m> (which might be negative), then you should use |
461 | C<ecb_mod>, as the C<%> operator might give either negative results, or |
474 | C<ecb_mod>, as the C<%> operator might give either negative results, or |
462 | change direction for negative values: |
475 | change direction for negative values: |