blob: eef612d1a136106feacc4d65939da21f3fcefa26 [file] [log] [blame]
Jens Axboe064c6362008-06-02 09:19:37 +02001#ifndef FIO_FFZ_H
2#define FIO_FFZ_H
3
Jens Axboe0ce8b112011-01-27 22:25:29 +01004static inline int __ffs(unsigned long word)
Jens Axboe064c6362008-06-02 09:19:37 +02005{
Jens Axboe09174442008-06-02 09:57:41 +02006 int r = 0;
Jens Axboe064c6362008-06-02 09:19:37 +02007
Jens Axboe0ce8b112011-01-27 22:25:29 +01008#if BITS_PER_LONG == 64
9 if ((word & 0xffffffff) == 0) {
10 r += 32;
11 word >>= 32;
12 }
13#endif
Jens Axboe064c6362008-06-02 09:19:37 +020014 if (!(word & 0xffff)) {
15 word >>= 16;
16 r += 16;
17 }
18 if (!(word & 0xff)) {
19 word >>= 8;
20 r += 8;
21 }
22 if (!(word & 0xf)) {
23 word >>= 4;
24 r += 4;
25 }
26 if (!(word & 3)) {
27 word >>= 2;
28 r += 2;
29 }
30 if (!(word & 1)) {
31 word >>= 1;
32 r += 1;
33 }
34
35 return r;
36}
37
Jens Axboe0ce8b112011-01-27 22:25:29 +010038static inline int ffz(unsigned long bitmask)
Jens Axboe064c6362008-06-02 09:19:37 +020039{
Jens Axboe09174442008-06-02 09:57:41 +020040 return __ffs(~bitmask);
Jens Axboe064c6362008-06-02 09:19:37 +020041}
42
43#endif