Path: blob/master/include/asm-generic/bitops/__fls.h
10818 views
#ifndef _ASM_GENERIC_BITOPS___FLS_H_1#define _ASM_GENERIC_BITOPS___FLS_H_23#include <asm/types.h>45/**6* __fls - find last (most-significant) set bit in a long word7* @word: the word to search8*9* Undefined if no set bit exists, so code should check against 0 first.10*/11static __always_inline unsigned long __fls(unsigned long word)12{13int num = BITS_PER_LONG - 1;1415#if BITS_PER_LONG == 6416if (!(word & (~0ul << 32))) {17num -= 32;18word <<= 32;19}20#endif21if (!(word & (~0ul << (BITS_PER_LONG-16)))) {22num -= 16;23word <<= 16;24}25if (!(word & (~0ul << (BITS_PER_LONG-8)))) {26num -= 8;27word <<= 8;28}29if (!(word & (~0ul << (BITS_PER_LONG-4)))) {30num -= 4;31word <<= 4;32}33if (!(word & (~0ul << (BITS_PER_LONG-2)))) {34num -= 2;35word <<= 2;36}37if (!(word & (~0ul << (BITS_PER_LONG-1))))38num -= 1;39return num;40}4142#endif /* _ASM_GENERIC_BITOPS___FLS_H_ */434445