Skip to content

Commit 7d95ee2

Browse files
YuryNorovnotcarbide
authored andcommitted
lib: inline _find_next_bit() wrappers
lib/find_bit.c declares five single-line wrappers for _find_next_bit(). We may turn those wrappers to inline functions. It eliminates unneeded function calls and opens room for compile-time optimizations. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Yury Norov <[email protected]> Acked-by: Rasmus Villemoes <[email protected]> Acked-by: Andy Shevchenko <[email protected]> Cc: Alexey Klimov <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: David Sterba <[email protected]> Cc: Dennis Zhou <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Cc: Jianpeng Ma <[email protected]> Cc: Joe Perches <[email protected]> Cc: John Paul Adrian Glaubitz <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Rich Felker <[email protected]> Cc: Stefano Brivio <[email protected]> Cc: Wei Yang <[email protected]> Cc: Wolfram Sang <[email protected]> Cc: Yoshinori Sato <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Stephen Rothwell <[email protected]>
1 parent b856148 commit 7d95ee2

File tree

3 files changed

+37
-64
lines changed

3 files changed

+37
-64
lines changed

include/asm-generic/bitops/find.h

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
#ifndef _ASM_GENERIC_BITOPS_FIND_H_
33
#define _ASM_GENERIC_BITOPS_FIND_H_
44

5+
extern unsigned long _find_next_bit(const unsigned long *addr1,
6+
const unsigned long *addr2, unsigned long nbits,
7+
unsigned long start, unsigned long invert, unsigned long le);
8+
59
#ifndef find_next_bit
610
/**
711
* find_next_bit - find the next set bit in a memory region
@@ -12,8 +16,12 @@
1216
* Returns the bit number for the next set bit
1317
* If no bits are set, returns @size.
1418
*/
15-
extern unsigned long find_next_bit(const unsigned long *addr, unsigned long
16-
size, unsigned long offset);
19+
static inline
20+
unsigned long find_next_bit(const unsigned long *addr, unsigned long size,
21+
unsigned long offset)
22+
{
23+
return _find_next_bit(addr, NULL, size, offset, 0UL, 0);
24+
}
1725
#endif
1826

1927
#ifndef find_next_and_bit
@@ -27,9 +35,13 @@ extern unsigned long find_next_bit(const unsigned long *addr, unsigned long
2735
* Returns the bit number for the next set bit
2836
* If no bits are set, returns @size.
2937
*/
30-
extern unsigned long find_next_and_bit(const unsigned long *addr1,
38+
static inline
39+
unsigned long find_next_and_bit(const unsigned long *addr1,
3140
const unsigned long *addr2, unsigned long size,
32-
unsigned long offset);
41+
unsigned long offset)
42+
{
43+
return _find_next_bit(addr1, addr2, size, offset, 0UL, 0);
44+
}
3345
#endif
3446

3547
#ifndef find_next_zero_bit
@@ -42,8 +54,12 @@ extern unsigned long find_next_and_bit(const unsigned long *addr1,
4254
* Returns the bit number of the next zero bit
4355
* If no bits are zero, returns @size.
4456
*/
45-
extern unsigned long find_next_zero_bit(const unsigned long *addr, unsigned
46-
long size, unsigned long offset);
57+
static inline
58+
unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size,
59+
unsigned long offset)
60+
{
61+
return _find_next_bit(addr, NULL, size, offset, ~0UL, 0);
62+
}
4763
#endif
4864

4965
#ifdef CONFIG_GENERIC_FIND_FIRST_BIT

include/asm-generic/bitops/le.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#ifndef _ASM_GENERIC_BITOPS_LE_H_
33
#define _ASM_GENERIC_BITOPS_LE_H_
44

5+
#include <asm-generic/bitops/find.h>
56
#include <asm/types.h>
67
#include <asm/byteorder.h>
78

@@ -32,13 +33,21 @@ static inline unsigned long find_first_zero_bit_le(const void *addr,
3233
#define BITOP_LE_SWIZZLE ((BITS_PER_LONG-1) & ~0x7)
3334

3435
#ifndef find_next_zero_bit_le
35-
extern unsigned long find_next_zero_bit_le(const void *addr,
36-
unsigned long size, unsigned long offset);
36+
static inline
37+
unsigned long find_next_zero_bit_le(const void *addr, unsigned
38+
long size, unsigned long offset)
39+
{
40+
return _find_next_bit(addr, NULL, size, offset, ~0UL, 1);
41+
}
3742
#endif
3843

3944
#ifndef find_next_bit_le
40-
extern unsigned long find_next_bit_le(const void *addr,
41-
unsigned long size, unsigned long offset);
45+
static inline
46+
unsigned long find_next_bit_le(const void *addr, unsigned
47+
long size, unsigned long offset)
48+
{
49+
return _find_next_bit(addr, NULL, size, offset, 0UL, 1);
50+
}
4251
#endif
4352

4453
#ifndef find_first_zero_bit_le

lib/find_bit.c

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* searching it for one bits.
2929
* - The optional "addr2", which is anded with "addr1" if present.
3030
*/
31-
static unsigned long _find_next_bit(const unsigned long *addr1,
31+
unsigned long _find_next_bit(const unsigned long *addr1,
3232
const unsigned long *addr2, unsigned long nbits,
3333
unsigned long start, unsigned long invert, unsigned long le)
3434
{
@@ -67,37 +67,7 @@ static unsigned long _find_next_bit(const unsigned long *addr1,
6767

6868
return min(start + __ffs(tmp), nbits);
6969
}
70-
#endif
71-
72-
#ifndef find_next_bit
73-
/*
74-
* Find the next set bit in a memory region.
75-
*/
76-
unsigned long find_next_bit(const unsigned long *addr, unsigned long size,
77-
unsigned long offset)
78-
{
79-
return _find_next_bit(addr, NULL, size, offset, 0UL, 0);
80-
}
81-
EXPORT_SYMBOL(find_next_bit);
82-
#endif
83-
84-
#ifndef find_next_zero_bit
85-
unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size,
86-
unsigned long offset)
87-
{
88-
return _find_next_bit(addr, NULL, size, offset, ~0UL, 0);
89-
}
90-
EXPORT_SYMBOL(find_next_zero_bit);
91-
#endif
92-
93-
#if !defined(find_next_and_bit)
94-
unsigned long find_next_and_bit(const unsigned long *addr1,
95-
const unsigned long *addr2, unsigned long size,
96-
unsigned long offset)
97-
{
98-
return _find_next_bit(addr1, addr2, size, offset, 0UL, 0);
99-
}
100-
EXPORT_SYMBOL(find_next_and_bit);
70+
EXPORT_SYMBOL(_find_next_bit);
10171
#endif
10272

10373
#ifndef find_first_bit
@@ -156,28 +126,6 @@ unsigned long find_last_bit(const unsigned long *addr, unsigned long size)
156126
EXPORT_SYMBOL(find_last_bit);
157127
#endif
158128

159-
#ifdef __BIG_ENDIAN
160-
161-
#ifndef find_next_zero_bit_le
162-
unsigned long find_next_zero_bit_le(const void *addr, unsigned
163-
long size, unsigned long offset)
164-
{
165-
return _find_next_bit(addr, NULL, size, offset, ~0UL, 1);
166-
}
167-
EXPORT_SYMBOL(find_next_zero_bit_le);
168-
#endif
169-
170-
#ifndef find_next_bit_le
171-
unsigned long find_next_bit_le(const void *addr, unsigned
172-
long size, unsigned long offset)
173-
{
174-
return _find_next_bit(addr, NULL, size, offset, 0UL, 1);
175-
}
176-
EXPORT_SYMBOL(find_next_bit_le);
177-
#endif
178-
179-
#endif /* __BIG_ENDIAN */
180-
181129
unsigned long find_next_clump8(unsigned long *clump, const unsigned long *addr,
182130
unsigned long size, unsigned long offset)
183131
{

0 commit comments

Comments
 (0)