1 #ifndef FIO_FFZ_H 2 #define FIO_FFZ_H 3 4 #include <inttypes.h> 5 ffs64(uint64_t word)6static inline int ffs64(uint64_t word) 7 { 8 int r = 0; 9 10 if ((word & 0xffffffff) == 0) { 11 r += 32; 12 word >>= 32; 13 } 14 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 38 #ifndef ARCH_HAVE_FFZ 39 ffz(unsigned long bitmask)40static inline int ffz(unsigned long bitmask) 41 { 42 return ffs64(~bitmask); 43 } 44 45 #else 46 #define ffz(bitmask) arch_ffz(bitmask) 47 #endif 48 ffz64(uint64_t bitmask)49static inline int ffz64(uint64_t bitmask) 50 { 51 return ffs64(~bitmask); 52 } 53 54 #endif 55