Use a simpler algorithm to calculate the result of ffs() and fls64().
This generates slightly better code and increases readability.
Kernel image size is reduced by ~3kb (gcc 15.1.0 + defconfig).
Suggested-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
*/
static inline int ffs(int word)
{
- unsigned long mask = 2 * BITS_PER_LONG - 1;
unsigned int val = (unsigned int)word;
- return (1 + (__flogr(-val & val) ^ (BITS_PER_LONG - 1))) & mask;
+ return BITS_PER_LONG - __flogr(-val & val);
}
/**
*/
static inline int fls64(unsigned long word)
{
- unsigned long mask = 2 * BITS_PER_LONG - 1;
-
- return (1 + (__flogr(word) ^ (BITS_PER_LONG - 1))) & mask;
+ return BITS_PER_LONG - __flogr(word);
}
/**