Path: blob/master/tools/include/asm-generic/bitops/__fls.h
26295 views
/* SPDX-License-Identifier: GPL-2.0 */1#ifndef _ASM_GENERIC_BITOPS___FLS_H_2#define _ASM_GENERIC_BITOPS___FLS_H_34#include <asm/types.h>56/**7* generic___fls - find last (most-significant) set bit in a long word8* @word: the word to search9*10* Undefined if no set bit exists, so code should check against 0 first.11*/12static __always_inline unsigned int generic___fls(unsigned long word)13{14unsigned int num = BITS_PER_LONG - 1;1516#if BITS_PER_LONG == 6417if (!(word & (~0ul << 32))) {18num -= 32;19word <<= 32;20}21#endif22if (!(word & (~0ul << (BITS_PER_LONG-16)))) {23num -= 16;24word <<= 16;25}26if (!(word & (~0ul << (BITS_PER_LONG-8)))) {27num -= 8;28word <<= 8;29}30if (!(word & (~0ul << (BITS_PER_LONG-4)))) {31num -= 4;32word <<= 4;33}34if (!(word & (~0ul << (BITS_PER_LONG-2)))) {35num -= 2;36word <<= 2;37}38if (!(word & (~0ul << (BITS_PER_LONG-1))))39num -= 1;40return num;41}4243#ifndef __HAVE_ARCH___FLS44#define __fls(word) generic___fls(word)45#endif4647#endif /* _ASM_GENERIC_BITOPS___FLS_H_ */484950