Skip to content

Commit fee4b19

Browse files
KAGA-KOKOtorvalds
authored andcommitted
bitops: remove "optimizations"
The mapsize optimizations which were moved from x86 to the generic code in commit 64970b6 increased the binary size on non x86 architectures. Looking into the real effects of the "optimizations" it turned out that they are not used in find_next_bit() and find_next_zero_bit(). The ones in find_first_bit() and find_first_zero_bit() are used in a couple of places but none of them is a real hot path. Remove the "optimizations" all together and call the library functions unconditionally. Boot-tested on x86 and compile tested on every cross compiler I have. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 8972331 commit fee4b19

2 files changed

Lines changed: 22 additions & 115 deletions

File tree

‎include/linux/bitops.h‎

Lines changed: 12 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ static inline unsigned fls_long(unsigned long l)
114114

115115
#ifdef __KERNEL__
116116
#ifdef CONFIG_GENERIC_FIND_FIRST_BIT
117-
extern unsigned long __find_first_bit(const unsigned long *addr,
118-
unsigned long size);
119117

120118
/**
121119
* find_first_bit - find the first set bit in a memory region
@@ -124,28 +122,8 @@ extern unsigned long __find_first_bit(const unsigned long *addr,
124122
*
125123
* Returns the bit number of the first set bit.
126124
*/
127-
static __always_inline unsigned long
128-
find_first_bit(const unsigned long *addr, unsigned long size)
129-
{
130-
/* Avoid a function call if the bitmap size is a constant */
131-
/* and not bigger than BITS_PER_LONG. */
132-
133-
/* insert a sentinel so that __ffs returns size if there */
134-
/* are no set bits in the bitmap */
135-
if (__builtin_constant_p(size) && (size < BITS_PER_LONG))
136-
return __ffs((*addr) | (1ul << size));
137-
138-
/* the result of __ffs(0) is undefined, so it needs to be */
139-
/* handled separately */
140-
if (__builtin_constant_p(size) && (size == BITS_PER_LONG))
141-
return ((*addr) == 0) ? BITS_PER_LONG : __ffs(*addr);
142-
143-
/* size is not constant or too big */
144-
return __find_first_bit(addr, size);
145-
}
146-
147-
extern unsigned long __find_first_zero_bit(const unsigned long *addr,
148-
unsigned long size);
125+
extern unsigned long find_first_bit(const unsigned long *addr,
126+
unsigned long size);
149127

150128
/**
151129
* find_first_zero_bit - find the first cleared bit in a memory region
@@ -154,102 +132,33 @@ extern unsigned long __find_first_zero_bit(const unsigned long *addr,
154132
*
155133
* Returns the bit number of the first cleared bit.
156134
*/
157-
static __always_inline unsigned long
158-
find_first_zero_bit(const unsigned long *addr, unsigned long size)
159-
{
160-
/* Avoid a function call if the bitmap size is a constant */
161-
/* and not bigger than BITS_PER_LONG. */
162-
163-
/* insert a sentinel so that __ffs returns size if there */
164-
/* are no set bits in the bitmap */
165-
if (__builtin_constant_p(size) && (size < BITS_PER_LONG)) {
166-
return __ffs(~(*addr) | (1ul << size));
167-
}
168-
169-
/* the result of __ffs(0) is undefined, so it needs to be */
170-
/* handled separately */
171-
if (__builtin_constant_p(size) && (size == BITS_PER_LONG))
172-
return (~(*addr) == 0) ? BITS_PER_LONG : __ffs(~(*addr));
173-
174-
/* size is not constant or too big */
175-
return __find_first_zero_bit(addr, size);
176-
}
135+
extern unsigned long find_first_zero_bit(const unsigned long *addr,
136+
unsigned long size);
137+
177138
#endif /* CONFIG_GENERIC_FIND_FIRST_BIT */
178139

179140
#ifdef CONFIG_GENERIC_FIND_NEXT_BIT
180-
extern unsigned long __find_next_bit(const unsigned long *addr,
181-
unsigned long size, unsigned long offset);
182141

183142
/**
184143
* find_next_bit - find the next set bit in a memory region
185144
* @addr: The address to base the search on
186145
* @offset: The bitnumber to start searching at
187146
* @size: The bitmap size in bits
188147
*/
189-
static __always_inline unsigned long
190-
find_next_bit(const unsigned long *addr, unsigned long size,
191-
unsigned long offset)
192-
{
193-
unsigned long value;
194-
195-
/* Avoid a function call if the bitmap size is a constant */
196-
/* and not bigger than BITS_PER_LONG. */
197-
198-
/* insert a sentinel so that __ffs returns size if there */
199-
/* are no set bits in the bitmap */
200-
if (__builtin_constant_p(size) && (size < BITS_PER_LONG)) {
201-
value = (*addr) & ((~0ul) << offset);
202-
value |= (1ul << size);
203-
return __ffs(value);
204-
}
205-
206-
/* the result of __ffs(0) is undefined, so it needs to be */
207-
/* handled separately */
208-
if (__builtin_constant_p(size) && (size == BITS_PER_LONG)) {
209-
value = (*addr) & ((~0ul) << offset);
210-
return (value == 0) ? BITS_PER_LONG : __ffs(value);
211-
}
212-
213-
/* size is not constant or too big */
214-
return __find_next_bit(addr, size, offset);
215-
}
216-
217-
extern unsigned long __find_next_zero_bit(const unsigned long *addr,
218-
unsigned long size, unsigned long offset);
148+
extern unsigned long find_next_bit(const unsigned long *addr,
149+
unsigned long size, unsigned long offset);
219150

220151
/**
221152
* find_next_zero_bit - find the next cleared bit in a memory region
222153
* @addr: The address to base the search on
223154
* @offset: The bitnumber to start searching at
224155
* @size: The bitmap size in bits
225156
*/
226-
static __always_inline unsigned long
227-
find_next_zero_bit(const unsigned long *addr, unsigned long size,
228-
unsigned long offset)
229-
{
230-
unsigned long value;
231-
232-
/* Avoid a function call if the bitmap size is a constant */
233-
/* and not bigger than BITS_PER_LONG. */
234-
235-
/* insert a sentinel so that __ffs returns size if there */
236-
/* are no set bits in the bitmap */
237-
if (__builtin_constant_p(size) && (size < BITS_PER_LONG)) {
238-
value = (~(*addr)) & ((~0ul) << offset);
239-
value |= (1ul << size);
240-
return __ffs(value);
241-
}
242-
243-
/* the result of __ffs(0) is undefined, so it needs to be */
244-
/* handled separately */
245-
if (__builtin_constant_p(size) && (size == BITS_PER_LONG)) {
246-
value = (~(*addr)) & ((~0ul) << offset);
247-
return (value == 0) ? BITS_PER_LONG : __ffs(value);
248-
}
249-
250-
/* size is not constant or too big */
251-
return __find_next_zero_bit(addr, size, offset);
252-
}
157+
158+
extern unsigned long find_next_zero_bit(const unsigned long *addr,
159+
unsigned long size,
160+
unsigned long offset);
161+
253162
#endif /* CONFIG_GENERIC_FIND_NEXT_BIT */
254163
#endif /* __KERNEL__ */
255164
#endif

‎lib/find_next_bit.c‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
/*
2121
* Find the next set bit in a memory region.
2222
*/
23-
unsigned long __find_next_bit(const unsigned long *addr,
24-
unsigned long size, unsigned long offset)
23+
unsigned long find_next_bit(const unsigned long *addr, unsigned long size,
24+
unsigned long offset)
2525
{
2626
const unsigned long *p = addr + BITOP_WORD(offset);
2727
unsigned long result = offset & ~(BITS_PER_LONG-1);
@@ -58,14 +58,14 @@ unsigned long __find_next_bit(const unsigned long *addr,
5858
found_middle:
5959
return result + __ffs(tmp);
6060
}
61-
EXPORT_SYMBOL(__find_next_bit);
61+
EXPORT_SYMBOL(find_next_bit);
6262

6363
/*
6464
* This implementation of find_{first,next}_zero_bit was stolen from
6565
* Linus' asm-alpha/bitops.h.
6666
*/
67-
unsigned long __find_next_zero_bit(const unsigned long *addr,
68-
unsigned long size, unsigned long offset)
67+
unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size,
68+
unsigned long offset)
6969
{
7070
const unsigned long *p = addr + BITOP_WORD(offset);
7171
unsigned long result = offset & ~(BITS_PER_LONG-1);
@@ -102,15 +102,14 @@ unsigned long __find_next_zero_bit(const unsigned long *addr,
102102
found_middle:
103103
return result + ffz(tmp);
104104
}
105-
EXPORT_SYMBOL(__find_next_zero_bit);
105+
EXPORT_SYMBOL(find_next_zero_bit);
106106
#endif /* CONFIG_GENERIC_FIND_NEXT_BIT */
107107

108108
#ifdef CONFIG_GENERIC_FIND_FIRST_BIT
109109
/*
110110
* Find the first set bit in a memory region.
111111
*/
112-
unsigned long __find_first_bit(const unsigned long *addr,
113-
unsigned long size)
112+
unsigned long find_first_bit(const unsigned long *addr, unsigned long size)
114113
{
115114
const unsigned long *p = addr;
116115
unsigned long result = 0;
@@ -131,13 +130,12 @@ unsigned long __find_first_bit(const unsigned long *addr,
131130
found:
132131
return result + __ffs(tmp);
133132
}
134-
EXPORT_SYMBOL(__find_first_bit);
133+
EXPORT_SYMBOL(find_first_bit);
135134

136135
/*
137136
* Find the first cleared bit in a memory region.
138137
*/
139-
unsigned long __find_first_zero_bit(const unsigned long *addr,
140-
unsigned long size)
138+
unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size)
141139
{
142140
const unsigned long *p = addr;
143141
unsigned long result = 0;
@@ -158,7 +156,7 @@ unsigned long __find_first_zero_bit(const unsigned long *addr,
158156
found:
159157
return result + ffz(tmp);
160158
}
161-
EXPORT_SYMBOL(__find_first_zero_bit);
159+
EXPORT_SYMBOL(find_first_zero_bit);
162160
#endif /* CONFIG_GENERIC_FIND_FIRST_BIT */
163161

164162
#ifdef __BIG_ENDIAN

0 commit comments

Comments
 (0)