xref: /OK3568_Linux_fs/kernel/include/asm-generic/bitops/builtin-fls.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef _ASM_GENERIC_BITOPS_BUILTIN_FLS_H_
3*4882a593Smuzhiyun #define _ASM_GENERIC_BITOPS_BUILTIN_FLS_H_
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun /**
6*4882a593Smuzhiyun  * fls - find last (most-significant) bit set
7*4882a593Smuzhiyun  * @x: the word to search
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * This is defined the same way as ffs.
10*4882a593Smuzhiyun  * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
11*4882a593Smuzhiyun  */
fls(unsigned int x)12*4882a593Smuzhiyun static __always_inline int fls(unsigned int x)
13*4882a593Smuzhiyun {
14*4882a593Smuzhiyun 	return x ? sizeof(x) * 8 - __builtin_clz(x) : 0;
15*4882a593Smuzhiyun }
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #endif
18