diff options
author | Thorsten Blum <thorsten.blum@toblux.com> | 2024-04-21 00:38:37 +0200 |
---|---|---|
committer | Arnd Bergmann <arnd@arndb.de> | 2024-05-03 17:04:50 +0200 |
commit | 9c313ccdfc079f71f16c9b3d3a6c6d60996b9367 (patch) | |
tree | f02cf54d4387467cf9f7b844afb2d62f7754c3dc /tools/include/asm-generic | |
parent | Linux 6.9-rc6 (diff) | |
download | linux-9c313ccdfc079f71f16c9b3d3a6c6d60996b9367.tar.xz linux-9c313ccdfc079f71f16c9b3d3a6c6d60996b9367.zip |
bitops: Change function return types from long to int
Change the return types of bitops functions (ffs, fls, and fns) from
long to int. The expected return values are in the range [0, 64], for
which int is sufficient.
Additionally, int aligns well with the return types of the corresponding
__builtin_* functions, potentially reducing overall type conversions.
Many of the existing bitops functions already return an int and don't
need to be changed. The bitops functions in arch/ should be considered
separately.
Adjust some return variables to match the function return types.
With GCC 13 and defconfig, these changes reduced the size of a test
kernel image by 5,432 bytes on arm64 and by 248 bytes on riscv; there
were no changes in size on x86_64, powerpc, or m68k.
Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Diffstat (limited to 'tools/include/asm-generic')
-rw-r--r-- | tools/include/asm-generic/bitops/__ffs.h | 4 | ||||
-rw-r--r-- | tools/include/asm-generic/bitops/__fls.h | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/tools/include/asm-generic/bitops/__ffs.h b/tools/include/asm-generic/bitops/__ffs.h index 9d1310519497..2d94c1e9b2f3 100644 --- a/tools/include/asm-generic/bitops/__ffs.h +++ b/tools/include/asm-generic/bitops/__ffs.h @@ -11,9 +11,9 @@ * * Undefined if no bit exists, so code should check against 0 first. */ -static __always_inline unsigned long __ffs(unsigned long word) +static __always_inline unsigned int __ffs(unsigned long word) { - int num = 0; + unsigned int num = 0; #if __BITS_PER_LONG == 64 if ((word & 0xffffffff) == 0) { diff --git a/tools/include/asm-generic/bitops/__fls.h b/tools/include/asm-generic/bitops/__fls.h index 54ccccf96e21..e974ec932ec1 100644 --- a/tools/include/asm-generic/bitops/__fls.h +++ b/tools/include/asm-generic/bitops/__fls.h @@ -10,9 +10,9 @@ * * Undefined if no set bit exists, so code should check against 0 first. */ -static __always_inline unsigned long generic___fls(unsigned long word) +static __always_inline unsigned int generic___fls(unsigned long word) { - int num = BITS_PER_LONG - 1; + unsigned int num = BITS_PER_LONG - 1; #if BITS_PER_LONG == 64 if (!(word & (~0ul << 32))) { |