Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _ASM_GENERIC_BITOPS_FLS64_H_
0003 #define _ASM_GENERIC_BITOPS_FLS64_H_
0004 
0005 #include <asm/types.h>
0006 
0007 /**
0008  * fls64 - find last set bit in a 64-bit word
0009  * @x: the word to search
0010  *
0011  * This is defined in a similar way as the libc and compiler builtin
0012  * ffsll, but returns the position of the most significant set bit.
0013  *
0014  * fls64(value) returns 0 if value is 0 or the position of the last
0015  * set bit if value is nonzero. The last (most significant) bit is
0016  * at position 64.
0017  */
0018 #if BITS_PER_LONG == 32
0019 static __always_inline int fls64(__u64 x)
0020 {
0021     __u32 h = x >> 32;
0022     if (h)
0023         return fls(h) + 32;
0024     return fls(x);
0025 }
0026 #elif BITS_PER_LONG == 64
0027 static __always_inline int fls64(__u64 x)
0028 {
0029     if (x == 0)
0030         return 0;
0031     return __fls(x) + 1;
0032 }
0033 #else
0034 #error BITS_PER_LONG not 32 or 64
0035 #endif
0036 
0037 #endif /* _ASM_GENERIC_BITOPS_FLS64_H_ */