2 * UCW Library -- Bit Operations
4 * (c) 2005 Martin Mares <mj@ucw.cz>
5 * (c) 2012 Pavel Charvat <pchar@ucw.cz>
7 * This software may be freely distributed and used according to the terms
8 * of the GNU Lesser General Public License.
14 #ifdef CONFIG_UCW_CLEAN_ABI
15 #define bit_fls ucw_bit_fls
16 #define ffs_table ucw_ffs_table
19 /* Find highest bit set (i.e., the floor of the binary logarithm) (bit-fls.c) */
21 int bit_fls(u32 x); /* bit_fls(0)=-1 */
23 /* Find lowest bit set, undefined for zero argument (bit-ffs.c) */
25 extern const byte ffs_table[256];
27 #ifdef __pentium4 /* On other ia32 machines, the C version is faster */
29 static inline uns bit_ffs(uns w)
31 asm("bsfl %1,%0" :"=r" (w) :"rm" (w));
37 static inline uns bit_ffs(uns w)
39 uns b = (w & 0xffff) ? 0 : 16;
40 b += ((w >> b) & 0xff) ? 0 : 8;
41 return b + ffs_table[(w >> b) & 0xff];
46 /* Count the number of bits set */
48 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
50 static inline uns bit_count(uns w)
52 return __builtin_popcount(w);
57 static inline uns bit_count(uns w)