1*4882a593Smuzhiyun #ifndef _ASM_GENERIC_BITOPS_FLS64_H_ 2*4882a593Smuzhiyun #define _ASM_GENERIC_BITOPS_FLS64_H_ 3*4882a593Smuzhiyun 4*4882a593Smuzhiyun #include <asm/types.h> 5*4882a593Smuzhiyun 6*4882a593Smuzhiyun /** 7*4882a593Smuzhiyun * fls64 - find last set bit in a 64-bit word 8*4882a593Smuzhiyun * @x: the word to search 9*4882a593Smuzhiyun * 10*4882a593Smuzhiyun * This is defined in a similar way as the libc and compiler builtin 11*4882a593Smuzhiyun * ffsll, but returns the position of the most significant set bit. 12*4882a593Smuzhiyun * 13*4882a593Smuzhiyun * fls64(value) returns 0 if value is 0 or the position of the last 14*4882a593Smuzhiyun * set bit if value is nonzero. The last (most significant) bit is 15*4882a593Smuzhiyun * at position 64. 16*4882a593Smuzhiyun */ 17*4882a593Smuzhiyun #if BITS_PER_LONG == 32 fls64(__u64 x)18*4882a593Smuzhiyunstatic __always_inline int fls64(__u64 x) 19*4882a593Smuzhiyun { 20*4882a593Smuzhiyun __u32 h = x >> 32; 21*4882a593Smuzhiyun if (h) 22*4882a593Smuzhiyun return fls(h) + 32; 23*4882a593Smuzhiyun return fls(x); 24*4882a593Smuzhiyun } 25*4882a593Smuzhiyun #elif BITS_PER_LONG == 64 fls64(__u64 x)26*4882a593Smuzhiyunstatic __always_inline int fls64(__u64 x) 27*4882a593Smuzhiyun { 28*4882a593Smuzhiyun if (x == 0) 29*4882a593Smuzhiyun return 0; 30*4882a593Smuzhiyun return __fls(x) + 1; 31*4882a593Smuzhiyun } 32*4882a593Smuzhiyun #else 33*4882a593Smuzhiyun #error BITS_PER_LONG not 32 or 64 34*4882a593Smuzhiyun #endif 35*4882a593Smuzhiyun 36*4882a593Smuzhiyun #endif /* _ASM_GENERIC_BITOPS_FLS64_H_ */ 37