Tool and Library Support
A number of compiler and library vendors supply compiler intrinsics or library functions to perform find first set and/or related operations, which are frequently implemented in terms of the hardware instructions above:
| Tool/library | Name | Type | Input type(s) | Notes | Result for zero input |
|---|---|---|---|---|---|
| POSIX.1 compliant libc 4.3BSD libc OS X 10.3 libc |
ffs |
Library function | int | Includes glibc. POSIX does not supply the complementary log base 2 / clz. |
0 |
| FreeBSD 5.3 libc OS X 10.4 libc |
ffsl |
Library function | int, long | fls ("find last set") computes (log base 2) + 1. | 0 |
| FreeBSD 7.1 libc | ffsll, flsll |
Library function | long long | 0 | |
| GCC 3.2.2 | __builtin_ffs |
Built-in functions | unsigned int, unsigned long, unsigned long long |
Possibly available before 3.2.2. | 0 |
__builtin_ctz |
undefined | ||||
__builtin_clz |
undefined | ||||
| Visual Studio 2005 | _BitScanForward_BitScanReverse |
Compiler intrinsics | unsigned long, unsigned __int64 |
Returns zero on zero input, unlike x86 bsf/bsr | 0 |
| Visual Studio 2008 | __lzcnt |
Compiler intrinsic | unsigned short, unsigned int, unsigned __int64 |
Relies on AMD-only lzcnt instruction | Input size in bits |
| Intel C++ Compiler | _bit_scan_forward |
Compiler intrinsics | int | undefined | |
| NVIDIA CUDA | __clz |
Functions | 32-bit, 64-bit | Compiles to fewer instructions on the GeForce 400 Series | 32 |
__ffs |
0 | ||||
| LLVM | llvm.ctlz.*llvm.cttz.* |
Intrinsic | 8, 16, 32, 64, 256 | LLVM assembly language | Input size if arg 2 is 0, else undefined |
Read more about this topic: Find First Set
Famous quotes containing the words tool, library and/or support:
“One of the great reasons for the popularity of strikes is that they give the suppressed self a sense of power. For once the human tool knows itself a man, able to stand up and speak a word or strike a blow.”
—Charles Horton Cooley (18641929)
“Madam, a circulating library in a town is as an evergreen tree of diabolical knowledge; it blossoms through the year. And depend on it ... that they who are so fond of handling the leaves, will long for the fruit at last.”
—Richard Brinsley Sheridan (17511816)
“The moral qualities are more apt to grow when a human being is useful, and they increase in the woman who helps to support the family rather than in the one who gives herself to idleness and fashionable frivolities.”
—Elizabeth Cady Stanton (18151902)