Skip to content

Commit 6c4e0cb

Browse files
hcahcaAlexander Gordeev
authored andcommitted
s390/bitops: Switch to generic ffs() if supported by compiler
Use generic ffs() / __builtin_ffs() if supported by the compiler. GCC 16 will have support for __builtin_ffs(). See gcc commit f50cff9766c5 ("s390: Implement clz and ctz for SI mode"). In the distant future when GCC 16 becomes the minimum supported version, this allows to get rid of the flogr inline assembly. Kernel image size is reduced by ~500 bytes (gcc 16 beta + defconfig). Acked-by: Alexander Gordeev <agordeev@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com> Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
1 parent 7b80a23 commit 6c4e0cb

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

arch/s390/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ config KASAN_SHADOW_OFFSET
4949
depends on KASAN
5050
default 0x1C000000000000
5151

52+
config CC_HAS_BUILTIN_FFS
53+
def_bool !(CC_IS_GCC && GCC_VERSION < 160000)
54+
help
55+
GCC versions before 16.0.0 generate library calls to ffs()
56+
for __builtin_ffs() even when __has_builtin(__builtin_ffs)
57+
is true.
58+
5259
config CC_ASM_FLAG_OUTPUT_BROKEN
5360
def_bool CC_IS_GCC && GCC_VERSION < 140200
5461
help

arch/s390/include/asm/bitops.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ static inline bool test_bit_inv(unsigned long nr,
122122
return test_bit(nr ^ (BITS_PER_LONG - 1), ptr);
123123
}
124124

125+
#ifndef CONFIG_CC_HAS_BUILTIN_FFS
126+
125127
/**
126128
* __flogr - find leftmost one
127129
* @word - The word to search
@@ -194,6 +196,12 @@ static __always_inline __flatten int ffs(int word)
194196
return BITS_PER_LONG - __flogr(-val & val);
195197
}
196198

199+
#else /* CONFIG_CC_HAS_BUILTIN_FFS */
200+
201+
#include <asm-generic/bitops/builtin-ffs.h>
202+
203+
#endif /* CONFIG_CC_HAS_BUILTIN_FFS */
204+
197205
#include <asm-generic/bitops/builtin-__ffs.h>
198206
#include <asm-generic/bitops/ffz.h>
199207
#include <asm-generic/bitops/builtin-__fls.h>

0 commit comments

Comments
 (0)