… | |
… | |
101 | #else |
101 | #else |
102 | return 0; |
102 | return 0; |
103 | #endif |
103 | #endif |
104 | } |
104 | } |
105 | |
105 | |
106 | =item ECB_INLINE |
106 | =item ecb_inline |
107 | |
107 | |
108 | This is not actually an attribute, but you use it like one. It expands |
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 |
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, |
110 | supported. It should be used to declare functions that should be inlined, |
111 | for code size or speed reasons. |
111 | for code size or speed reasons. |
112 | |
112 | |
113 | Example: inline this function, it surely will reduce codesize. |
113 | Example: inline this function, it surely will reduce codesize. |
114 | |
114 | |
115 | ECB_INLINE int |
115 | ecb_inline int |
116 | negmul (int a, int b) |
116 | negmul (int a, int b) |
117 | { |
117 | { |
118 | return - (a * b); |
118 | return - (a * b); |
119 | } |
119 | } |
120 | |
120 | |
… | |
… | |
414 | |
414 | |
415 | =item int ecb_ctz32 (uint32_t x) |
415 | =item int ecb_ctz32 (uint32_t x) |
416 | |
416 | |
417 | 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 |
418 | 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 |
419 | 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: |
420 | case is to compute the integer binary logarithm, i.e., C<floor (log2 |
|
|
421 | (n))>. For example: |
|
|
422 | |
420 | |
423 | ecb_ctz32 (3) = 0 |
421 | ecb_ctz32 (3) = 0 |
424 | ecb_ctz32 (6) = 1 |
422 | ecb_ctz32 (6) = 1 |
425 | |
423 | |
426 | =item int ecb_popcount32 (uint32_t x) |
424 | =item int ecb_popcount32 (uint32_t x) |
… | |
… | |
432 | |
430 | |
433 | =item uint32_t ecb_bswap16 (uint32_t x) |
431 | =item uint32_t ecb_bswap16 (uint32_t x) |
434 | |
432 | |
435 | =item uint32_t ecb_bswap32 (uint32_t x) |
433 | =item uint32_t ecb_bswap32 (uint32_t x) |
436 | |
434 | |
|
|
435 | =item uint64_t ecb_bswap64 (uint64_t x) |
|
|
436 | |
437 | These two functions return the value of the 16-bit (32-bit) value C<x> |
437 | These functions return the value of the 16-bit (32-bit, 64-bit) value |
438 | after reversing the order of bytes (0x11223344 becomes 0x44332211). |
438 | C<x> after reversing the order of bytes (0x11223344 becomes 0x44332211 in |
|
|
439 | C<ecb_bswap32>). |
|
|
440 | |
|
|
441 | =item uint8_t ecb_rotl8 (uint8_t x, unsigned int count) |
|
|
442 | |
|
|
443 | =item uint16_t ecb_rotl16 (uint16_t x, unsigned int count) |
|
|
444 | |
|
|
445 | =item uint32_t ecb_rotl32 (uint32_t x, unsigned int count) |
|
|
446 | |
|
|
447 | =item uint64_t ecb_rotl64 (uint64_t x, unsigned int count) |
|
|
448 | |
|
|
449 | =item uint8_t ecb_rotr8 (uint8_t x, unsigned int count) |
|
|
450 | |
|
|
451 | =item uint16_t ecb_rotr16 (uint16_t x, unsigned int count) |
439 | |
452 | |
440 | =item uint32_t ecb_rotr32 (uint32_t x, unsigned int count) |
453 | =item uint32_t ecb_rotr32 (uint32_t x, unsigned int count) |
441 | |
454 | |
442 | =item uint32_t ecb_rotl32 (uint32_t x, unsigned int count) |
455 | =item uint64_t ecb_rotr64 (uint64_t x, unsigned int count) |
443 | |
456 | |
444 | These two functions return the value of C<x> after rotating all the bits |
457 | These two families of functions return the value of C<x> after rotating |
445 | by C<count> positions to the right or left respectively. |
458 | all the bits by C<count> positions to the right (C<ecb_rotr>) or left |
|
|
459 | (C<ecb_rotl>). |
446 | |
460 | |
447 | Current GCC versions understand these functions and usually compile them |
461 | Current GCC versions understand these functions and usually compile them |
448 | to "optimal" code (e.g. a single C<roll> on x86). |
462 | to "optimal" code (e.g. a single C<rol> or a combination of C<shld> on |
|
|
463 | x86). |
449 | |
464 | |
450 | =back |
465 | =back |
451 | |
466 | |
452 | =head2 ARITHMETIC |
467 | =head2 ARITHMETIC |
453 | |
468 | |
… | |
… | |
463 | C<ecb_mod> implements the mathematical modulo operation, which is missing |
478 | C<ecb_mod> implements the mathematical modulo operation, which is missing |
464 | in the language. |
479 | in the language. |
465 | |
480 | |
466 | C<n> must be strictly positive (i.e. C<< >= 1 >>), while C<m> must be |
481 | C<n> must be strictly positive (i.e. C<< >= 1 >>), while C<m> must be |
467 | negatable, that is, both C<m> and C<-m> must be representable in its |
482 | negatable, that is, both C<m> and C<-m> must be representable in its |
468 | type (this typically includes the minimum signed integer value, the same |
483 | type (this typically excludes the minimum signed integer value, the same |
469 | limitation as for C</> and C<%> in C). |
484 | limitation as for C</> and C<%> in C). |
470 | |
485 | |
471 | Current GCC versions compile this into an efficient branchless sequence on |
486 | Current GCC versions compile this into an efficient branchless sequence on |
472 | almost all CPUs. |
487 | almost all CPUs. |
473 | |
488 | |