4 * Inline functions for bit manipulation.
6 * The author dedicates this file to the public domain.
7 * You can do whatever you want with this file.
10 #ifndef _WIMLIB_BITOPS_H
11 #define _WIMLIB_BITOPS_H
13 #include "wimlib/compiler.h"
14 #include "wimlib/types.h"
16 /* Find Last Set bit */
18 static inline unsigned
22 return compiler_fls32(v);
25 while ((v >>= 1) != 0)
31 static inline unsigned
35 return compiler_fls64(v);
38 while ((v >>= 1) != 0)
44 static inline unsigned
45 flsw(machine_word_t v)
47 BUILD_BUG_ON(WORDSIZE != 4 && WORDSIZE != 8);
54 /* Find First Set bit */
56 static inline unsigned
60 return compiler_ffs32(v);
63 for (bit = 0; !(v & 1); bit++, v >>= 1)
69 static inline unsigned
73 return compiler_ffs64(v);
76 for (bit = 0; !(v & 1); bit++, v >>= 1)
82 static inline unsigned
83 ffsw(machine_word_t v)
85 BUILD_BUG_ON(WORDSIZE != 4 && WORDSIZE != 8);
92 #endif /* _WIMLIB_BITOPS_H */