GLAST/LAT > DAQ and FSW > FSW > Doxygen Index > LDT / V0-4-0
Constituent: encdec     Tag: rad750

Functions | |
| static __inline int | FFS (unsigned int word) |
| Finds the first set bit (MSB = bit 0) in a 32-bit word. | |
| static __inline unsigned int | FFS_eliminate (unsigned int word, int bit) |
| Eliminates the specified bit, bit from word. | |
| static __inline unsigned int | FFS_mask (int bit) |
| Converts the bit to a bit mask. | |
CVS $Id
ABSTRACT
--------
This facility provides the interface and implementation of the Find First Set routines. These routines provide a machine independent interface to a machine dependent implementation to find the first set bit in a 32 bit word. On most machines, this consists of a single machine instruction
USAGE
-----
Two routines are provided, FFS() and FFS_eliminate(). These routines find and then eliminate the first set bit in a 32 bit word.
Example
-------
As example, consider counting the number of set bits in a 32-bit word.
int count_bits (unsigned int word) { int cnt = 0; while (word) { int bit; bit = FFS (word); cnt += 1; word = FFS_eliminate (word, bit); } return cnt; }
| static __inline int FFS | ( | unsigned int | word | ) | [static] |
Finds the first set bit (MSB = bit 0) in a 32-bit word.
On the PowerPCs, this is a direct map to the PPC instruction 'cntlz', count leading zeros.
The Intel implementation is an 'bsr' instruction with the bit numbers reversed to match a big endian machine.
The non PPC604 implementation is a straighforward piece of C code.
| static __inline unsigned int FFS_eliminate | ( | unsigned int | word, | |
| int | bit | |||
| ) | [static] |
Eliminates the specified bit, bit from word.
| word | The word to eliminate the bit from | |
| bit | The bit (MSB = 0) to eliminate |
| static __inline unsigned int FFS_mask | ( | int | bit | ) | [static] |
Converts the bit to a bit mask.
| bit | The bit (MSB = 0) to set. |
1.5.3