Be sure to use internal __ffs, not glibc variant
[fio.git] / lib / ffz.h
CommitLineData
064c636d
JA
1#ifndef FIO_FFZ_H
2#define FIO_FFZ_H
3
4static inline int __ffs(int word)
5{
09174445 6 int r = 0;
064c636d
JA
7
8 if (!(word & 0xffff)) {
9 word >>= 16;
10 r += 16;
11 }
12 if (!(word & 0xff)) {
13 word >>= 8;
14 r += 8;
15 }
16 if (!(word & 0xf)) {
17 word >>= 4;
18 r += 4;
19 }
20 if (!(word & 3)) {
21 word >>= 2;
22 r += 2;
23 }
24 if (!(word & 1)) {
25 word >>= 1;
26 r += 1;
27 }
28
29 return r;
30}
31
32static inline int ffz(unsigned int bitmask)
33{
09174445 34 return __ffs(~bitmask);
064c636d
JA
35}
36
37#endif