/* SPDX-License-Identifier: GPL-2.0 */1#ifndef _ASM_GENERIC_BITOPS_FLS_H_2#define _ASM_GENERIC_BITOPS_FLS_H_34/**5* generic_fls - find last (most-significant) bit set6* @x: the word to search7*8* This is defined the same way as ffs.9* Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.10*/1112static __always_inline int generic_fls(unsigned int x)13{14int r = 32;1516if (!x)17return 0;18if (!(x & 0xffff0000u)) {19x <<= 16;20r -= 16;21}22if (!(x & 0xff000000u)) {23x <<= 8;24r -= 8;25}26if (!(x & 0xf0000000u)) {27x <<= 4;28r -= 4;29}30if (!(x & 0xc0000000u)) {31x <<= 2;32r -= 2;33}34if (!(x & 0x80000000u)) {35x <<= 1;36r -= 1;37}38return r;39}4041#ifndef __HAVE_ARCH_FLS42#define fls(x) generic_fls(x)43#endif4445#endif /* _ASM_GENERIC_BITOPS_FLS_H_ */464748