Home | History | Annotate | Download | only in lib
      1 #ifndef FIO_FFZ_H
      2 #define FIO_FFZ_H
      3 
      4 static inline int __ffs(unsigned long word)
      5 {
      6 	int r = 0;
      7 
      8 #if BITS_PER_LONG == 64
      9 	if ((word & 0xffffffff) == 0) {
     10 		r += 32;
     11 		word >>= 32;
     12 	}
     13 #endif
     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 static inline int ffz(unsigned long bitmask)
     39 {
     40 	return __ffs(~bitmask);
     41 }
     42 
     43 #endif
     44