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 #include <asm/types.h>
0006 
0007 /**
0008  * __fls - find last (most-significant) set bit in a long word
0009  * @word: the word to search
0010  *
0011  * Undefined if no set bit exists, so code should check against 0 first.
0012  */
0013 static __always_inline unsigned long __fls(unsigned long word)
0014 {
0015     int num = BITS_PER_LONG - 1;
0016 
0017 #if BITS_PER_LONG == 64
0018     if (!(word & (~0ul << 32))) {
0019         num -= 32;
0020         word <<= 32;
0021     }
0022 #endif
0023     if (!(word & (~0ul << (BITS_PER_LONG-16)))) {
0024         num -= 16;
0025         word <<= 16;
0026     }
0027     if (!(word & (~0ul << (BITS_PER_LONG-8)))) {
0028         num -= 8;
0029         word <<= 8;
0030     }
0031     if (!(word & (~0ul << (BITS_PER_LONG-4)))) {
0032         num -= 4;
0033         word <<= 4;
0034     }
0035     if (!(word & (~0ul << (BITS_PER_LONG-2)))) {
0036         num -= 2;
0037         word <<= 2;
0038     }
0039     if (!(word & (~0ul << (BITS_PER_LONG-1))))
0040         num -= 1;
0041     return num;
0042 }
0043 
0044 #endif /* _ASM_GENERIC_BITOPS___FLS_H_ */