Skip to content

Commit 9c313cc

Browse files
tobluxarndb
authored andcommitted
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>
1 parent e67572c commit 9c313cc

File tree

8 files changed

+14
-14
lines changed

8 files changed

+14
-14
lines changed

include/asm-generic/bitops/__ffs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
*
1111
* Undefined if no bit exists, so code should check against 0 first.
1212
*/
13-
static __always_inline unsigned long generic___ffs(unsigned long word)
13+
static __always_inline unsigned int generic___ffs(unsigned long word)
1414
{
15-
int num = 0;
15+
unsigned int num = 0;
1616

1717
#if BITS_PER_LONG == 64
1818
if ((word & 0xffffffff) == 0) {

include/asm-generic/bitops/__fls.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
*
1111
* Undefined if no set bit exists, so code should check against 0 first.
1212
*/
13-
static __always_inline unsigned long generic___fls(unsigned long word)
13+
static __always_inline unsigned int generic___fls(unsigned long word)
1414
{
15-
int num = BITS_PER_LONG - 1;
15+
unsigned int num = BITS_PER_LONG - 1;
1616

1717
#if BITS_PER_LONG == 64
1818
if (!(word & (~0ul << 32))) {

include/asm-generic/bitops/builtin-__ffs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* Undefined if no bit exists, so code should check against 0 first.
1010
*/
11-
static __always_inline unsigned long __ffs(unsigned long word)
11+
static __always_inline unsigned int __ffs(unsigned long word)
1212
{
1313
return __builtin_ctzl(word);
1414
}

include/asm-generic/bitops/builtin-__fls.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* Undefined if no set bit exists, so code should check against 0 first.
1010
*/
11-
static __always_inline unsigned long __fls(unsigned long word)
11+
static __always_inline unsigned int __fls(unsigned long word)
1212
{
1313
return (sizeof(word) * 8) - 1 - __builtin_clzl(word);
1414
}

include/linux/bitops.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ static __always_inline __s64 sign_extend64(__u64 value, int index)
200200
return (__s64)(value << shift) >> shift;
201201
}
202202

203-
static inline unsigned fls_long(unsigned long l)
203+
static inline unsigned int fls_long(unsigned long l)
204204
{
205205
if (sizeof(l) == 4)
206206
return fls(l);
@@ -236,7 +236,7 @@ static inline int get_count_order_long(unsigned long l)
236236
* The result is not defined if no bits are set, so check that @word
237237
* is non-zero before calling this.
238238
*/
239-
static inline unsigned long __ffs64(u64 word)
239+
static inline unsigned int __ffs64(u64 word)
240240
{
241241
#if BITS_PER_LONG == 32
242242
if (((u32)word) == 0UL)
@@ -252,7 +252,7 @@ static inline unsigned long __ffs64(u64 word)
252252
* @word: The word to search
253253
* @n: Bit to find
254254
*/
255-
static inline unsigned long fns(unsigned long word, unsigned int n)
255+
static inline unsigned int fns(unsigned long word, unsigned int n)
256256
{
257257
unsigned int bit;
258258

tools/include/asm-generic/bitops/__ffs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
*
1212
* Undefined if no bit exists, so code should check against 0 first.
1313
*/
14-
static __always_inline unsigned long __ffs(unsigned long word)
14+
static __always_inline unsigned int __ffs(unsigned long word)
1515
{
16-
int num = 0;
16+
unsigned int num = 0;
1717

1818
#if __BITS_PER_LONG == 64
1919
if ((word & 0xffffffff) == 0) {

tools/include/asm-generic/bitops/__fls.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
*
1111
* Undefined if no set bit exists, so code should check against 0 first.
1212
*/
13-
static __always_inline unsigned long generic___fls(unsigned long word)
13+
static __always_inline unsigned int generic___fls(unsigned long word)
1414
{
15-
int num = BITS_PER_LONG - 1;
15+
unsigned int num = BITS_PER_LONG - 1;
1616

1717
#if BITS_PER_LONG == 64
1818
if (!(word & (~0ul << 32))) {

tools/include/linux/bitops.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static inline unsigned long hweight_long(unsigned long w)
7070
return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
7171
}
7272

73-
static inline unsigned fls_long(unsigned long l)
73+
static inline unsigned int fls_long(unsigned long l)
7474
{
7575
if (sizeof(l) == 4)
7676
return fls(l);

0 commit comments

Comments
 (0)