ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/libecb/ecb.pod
(Generate patch)

Comparing cvsroot/libecb/ecb.pod (file contents):
Revision 1.27 by root, Wed Jun 1 01:29:36 2011 UTC vs.
Revision 1.34 by root, Fri Jun 17 21:16:12 2011 UTC

101 #else 101 #else
102 return 0; 102 return 0;
103 #endif 103 #endif
104 } 104 }
105 105
106=item ecb_inline
107
108This is not actually an attribute, but you use it like one. It expands
109either to C<static inline> or to just C<static>, if inline isn't
110supported. It should be used to declare functions that should be inlined,
111for code size or speed reasons.
112
113Example: 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 }
120
106=item ecb_noinline 121=item ecb_noinline
107 122
108Prevent a function from being inlined - it might be optimised away, but 123Prevent a function from being inlined - it might be optimised away, but
109not inlined into other functions. This is useful if you know your function 124not inlined into other functions. This is useful if you know your function
110is rarely called and large enough for inlining not to be helpful. 125is rarely called and large enough for inlining not to be helpful.
399 414
400=item int ecb_ctz32 (uint32_t x) 415=item int ecb_ctz32 (uint32_t x)
401 416
402Returns the index of the least significant bit set in C<x> (or 417Returns the index of the least significant bit set in C<x> (or
403equivalently the number of bits set to 0 before the least significant bit 418equivalently the number of bits set to 0 before the least significant bit
404set), starting from 0. If C<x> is 0 the result is undefined. A common use 419set), starting from 0. If C<x> is 0 the result is undefined. For example:
405case 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)
417 430
418=item uint32_t ecb_bswap16 (uint32_t x) 431=item uint32_t ecb_bswap16 (uint32_t x)
419 432
420=item uint32_t ecb_bswap32 (uint32_t x) 433=item uint32_t ecb_bswap32 (uint32_t x)
421 434
435=item uint64_t ecb_bswap64 (uint64_t x)
436
422These two functions return the value of the 16-bit (32-bit) value C<x> 437These functions return the value of the 16-bit (32-bit, 64-bit) value
423after reversing the order of bytes (0x11223344 becomes 0x44332211). 438C<x> after reversing the order of bytes (0x11223344 becomes 0x44332211 in
439C<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)
424 452
425=item uint32_t ecb_rotr32 (uint32_t x, unsigned int count) 453=item uint32_t ecb_rotr32 (uint32_t x, unsigned int count)
426 454
427=item uint32_t ecb_rotl32 (uint32_t x, unsigned int count) 455=item uint64_t ecb_rotr64 (uint64_t x, unsigned int count)
428 456
429These two functions return the value of C<x> after rotating all the bits 457These two families of functions return the value of C<x> after rotating
430by C<count> positions to the right or left respectively. 458all the bits by C<count> positions to the right (C<ecb_rotr>) or left
459(C<ecb_rotl>).
431 460
432Current GCC versions understand these functions and usually compile them 461Current GCC versions understand these functions and usually compile them
433to "optimal" code (e.g. a single C<roll> on x86). 462to "optimal" code (e.g. a single C<rol> or a combination of C<shld> on
463x86).
434 464
435=back 465=back
436 466
437=head2 ARITHMETIC 467=head2 ARITHMETIC
438 468
448C<ecb_mod> implements the mathematical modulo operation, which is missing 478C<ecb_mod> implements the mathematical modulo operation, which is missing
449in the language. 479in the language.
450 480
451C<n> must be strictly positive (i.e. C<< >= 1 >>), while C<m> must be 481C<n> must be strictly positive (i.e. C<< >= 1 >>), while C<m> must be
452negatable, that is, both C<m> and C<-m> must be representable in its 482negatable, that is, both C<m> and C<-m> must be representable in its
453type (this typically includes the minimum signed integer value, the same 483type (this typically excludes the minimum signed integer value, the same
454limitation as for C</> and C<%> in C). 484limitation as for C</> and C<%> in C).
455 485
456Current GCC versions compile this into an efficient branchless sequence on 486Current GCC versions compile this into an efficient branchless sequence on
457many systems. 487almost all CPUs.
458 488
459For example, when you want to rotate forward through the members of an 489For example, when you want to rotate forward through the members of an
460array for increasing C<m> (which might be negative), then you should use 490array for increasing C<m> (which might be negative), then you should use
461C<ecb_mod>, as the C<%> operator might give either negative results, or 491C<ecb_mod>, as the C<%> operator might give either negative results, or
462change direction for negative values: 492change direction for negative values:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines