bitops: linux: Add fns() to find N'th set bit
Add the fns() function from Linux to find the N'th set bit in a word. This is needed by lib/find_bit.c which uses it in the FIND_NTH_BIT macro. Taken from Linux v6.19 Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com>
This commit is contained in:
@@ -194,6 +194,19 @@ static inline unsigned long __ffs64(u64 word)
|
|||||||
return __ffs((unsigned long)word);
|
return __ffs((unsigned long)word);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fns - find N'th set bit in a word
|
||||||
|
* @word: The word to search
|
||||||
|
* @n: Bit to find
|
||||||
|
*/
|
||||||
|
static inline unsigned int fns(unsigned long word, unsigned int n)
|
||||||
|
{
|
||||||
|
while (word && n--)
|
||||||
|
word &= word - 1;
|
||||||
|
|
||||||
|
return word ? __ffs(word) : BITS_PER_LONG;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* __set_bit - Set a bit in memory
|
* __set_bit - Set a bit in memory
|
||||||
* @nr: the bit to set
|
* @nr: the bit to set
|
||||||
|
|||||||
Reference in New Issue
Block a user