Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _ASM_GENERIC_BITOPS_FLS_H_
0003 #define _ASM_GENERIC_BITOPS_FLS_H_
0004 
0005 /**
0006  * fls - find last (most-significant) bit set
0007  * @x: the word to search
0008  *
0009  * This is defined the same way as ffs.
0010  * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
0011  */
0012 
0013 static __always_inline int fls(unsigned int x)
0014 {
0015     int r = 32;
0016 
0017     if (!x)
0018         return 0;
0019     if (!(x & 0xffff0000u)) {
0020         x <<= 16;
0021         r -= 16;
0022     }
0023     if (!(x & 0xff000000u)) {
0024         x <<= 8;
0025         r -= 8;
0026     }
0027     if (!(x & 0xf0000000u)) {
0028         x <<= 4;
0029         r -= 4;
0030     }
0031     if (!(x & 0xc0000000u)) {
0032         x <<= 2;
0033         r -= 2;
0034     }
0035     if (!(x & 0x80000000u)) {
0036         x <<= 1;
0037         r -= 1;
0038     }
0039     return r;
0040 }
0041 
0042 #endif /* _ASM_GENERIC_BITOPS_FLS_H_ */