Skip to content

Commit de88e74

Browse files
hcahcaAlexander Gordeev
authored andcommitted
s390/bitops: Slightly optimize ffs() and fls64()
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>
1 parent f9de6cd commit de88e74

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

arch/s390/include/asm/bitops.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,9 @@ static inline unsigned long __ffs(unsigned long word)
193193
*/
194194
static inline int ffs(int word)
195195
{
196-
unsigned long mask = 2 * BITS_PER_LONG - 1;
197196
unsigned int val = (unsigned int)word;
198197

199-
return (1 + (__flogr(-val & val) ^ (BITS_PER_LONG - 1))) & mask;
198+
return BITS_PER_LONG - __flogr(-val & val);
200199
}
201200

202201
/**
@@ -223,9 +222,7 @@ static inline unsigned long __fls(unsigned long word)
223222
*/
224223
static inline int fls64(unsigned long word)
225224
{
226-
unsigned long mask = 2 * BITS_PER_LONG - 1;
227-
228-
return (1 + (__flogr(word) ^ (BITS_PER_LONG - 1))) & mask;
225+
return BITS_PER_LONG - __flogr(word);
229226
}
230227

231228
/**

0 commit comments

Comments
 (0)