Jens Axboe | 064c636 | 2008-06-02 09:19:37 +0200 | [diff] [blame] | 1 | #ifndef FIO_FFZ_H |
| 2 | #define FIO_FFZ_H |
| 3 | |
| 4 | static inline int __ffs(int word) |
| 5 | { |
Jens Axboe | 0917444 | 2008-06-02 09:57:41 +0200 | [diff] [blame] | 6 | int r = 0; |
Jens Axboe | 064c636 | 2008-06-02 09:19:37 +0200 | [diff] [blame] | 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 | |
| 32 | static inline int ffz(unsigned int bitmask) |
| 33 | { |
Jens Axboe | 0917444 | 2008-06-02 09:57:41 +0200 | [diff] [blame] | 34 | return __ffs(~bitmask); |
Jens Axboe | 064c636 | 2008-06-02 09:19:37 +0200 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | #endif |