2 * UCW Library -- Bit Operations
4 * (c) 2005 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
13 /* Find highest bit set (i.e., the floor of the binary logarithm) (bit-fls.c) */
15 int bit_fls(u32 x); /* bit_fls(0)=-1 */
17 /* Find lowest bit set, undefined for zero argument (bit-ffs.c) */
19 extern const byte ffs_table[256];
21 #ifdef __pentium4 /* On other ia32 machines, the C version is faster */
23 static inline uns bit_ffs(uns w)
25 asm("bsfl %1,%0" :"=r" (w) :"rm" (w));
31 static inline uns bit_ffs(uns w)
33 uns b = (w & 0xffff) ? 0 : 16;
34 b += ((w >> b) & 0xff) ? 0 : 8;
35 return b + ffs_table[(w >> b) & 0xff];