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/**4* fls - find last (most-significant) bit set5* @x: the word to search6*7* This is defined the same way as ffs.8* Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.9*/1011static __always_inline int fls(int x)12{13int r = 32;1415if (!x)16return 0;17if (!(x & 0xffff0000u)) {18x <<= 16;19r -= 16;20}21if (!(x & 0xff000000u)) {22x <<= 8;23r -= 8;24}25if (!(x & 0xf0000000u)) {26x <<= 4;27r -= 4;28}29if (!(x & 0xc0000000u)) {30x <<= 2;31r -= 2;32}33if (!(x & 0x80000000u)) {34x <<= 1;35r -= 1;36}37return r;38}3940#endif /* _ASM_GENERIC_BITOPS_FLS_H_ */414243