blob: e17a2e9c0a1e7cd60f3e99b8989ecc61bebed806 [file] [log] [blame]
Jens Axboe064c6362008-06-02 09:19:37 +02001#ifndef FIO_FFZ_H
2#define FIO_FFZ_H
3
4static inline int __ffs(int word)
5{
Jens Axboe09174442008-06-02 09:57:41 +02006 int r = 0;
Jens Axboe064c6362008-06-02 09:19:37 +02007
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{
Jens Axboe09174442008-06-02 09:57:41 +020034 return __ffs(~bitmask);
Jens Axboe064c6362008-06-02 09:19:37 +020035}
36
37#endif