Commit fee4b19fb3f28d17c0b9f9ea0668db5275697178

Authored by Thomas Gleixner
Committed by Linus Torvalds
1 parent 8972331292

bitops: remove "optimizations"

The mapsize optimizations which were moved from x86 to the generic
code in commit 64970b68d2b3ed32b964b0b30b1b98518fde388e 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>

Showing 2 changed files with 22 additions and 115 deletions Side-by-side Diff

include/linux/bitops.h
... ... @@ -114,8 +114,6 @@
114 114  
115 115 #ifdef __KERNEL__
116 116 #ifdef CONFIG_GENERIC_FIND_FIRST_BIT
117   -extern unsigned long __find_first_bit(const unsigned long *addr,
118   - unsigned long size);
119 117  
120 118 /**
121 119 * find_first_bit - find the first set bit in a memory region
122 120  
... ... @@ -124,29 +122,9 @@
124 122 *
125 123 * Returns the bit number of the first set bit.
126 124 */
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. */
  125 +extern unsigned long find_first_bit(const unsigned long *addr,
  126 + unsigned long size);
132 127  
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);
149   -
150 128 /**
151 129 * find_first_zero_bit - find the first cleared bit in a memory region
152 130 * @addr: The address to start the search at
153 131  
154 132  
... ... @@ -154,31 +132,12 @@
154 132 *
155 133 * Returns the bit number of the first cleared bit.
156 134 */
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. */
  135 +extern unsigned long find_first_zero_bit(const unsigned long *addr,
  136 + unsigned long size);
162 137  
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   -}
177 138 #endif /* CONFIG_GENERIC_FIND_FIRST_BIT */
178 139  
179 140 #ifdef CONFIG_GENERIC_FIND_NEXT_BIT
180   -extern unsigned long __find_next_bit(const unsigned long *addr,
181   - unsigned long size, unsigned long offset);
182 141  
183 142 /**
184 143 * find_next_bit - find the next set bit in a memory region
185 144  
186 145  
187 146  
188 147  
... ... @@ -186,70 +145,20 @@
186 145 * @offset: The bitnumber to start searching at
187 146 * @size: The bitmap size in bits
188 147 */
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;
  148 +extern unsigned long find_next_bit(const unsigned long *addr,
  149 + unsigned long size, unsigned long offset);
194 150  
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);
219   -
220 151 /**
221 152 * find_next_zero_bit - find the next cleared bit in a memory region
222 153 * @addr: The address to base the search on
223 154 * @offset: The bitnumber to start searching at
224 155 * @size: The bitmap size in bits
225 156 */
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 157  
232   - /* Avoid a function call if the bitmap size is a constant */
233   - /* and not bigger than BITS_PER_LONG. */
  158 +extern unsigned long find_next_zero_bit(const unsigned long *addr,
  159 + unsigned long size,
  160 + unsigned long offset);
234 161  
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   -}
253 162 #endif /* CONFIG_GENERIC_FIND_NEXT_BIT */
254 163 #endif /* __KERNEL__ */
255 164 #endif
... ... @@ -20,8 +20,8 @@
20 20 /*
21 21 * Find the next set bit in a memory region.
22 22 */
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)
25 25 {
26 26 const unsigned long *p = addr + BITOP_WORD(offset);
27 27 unsigned long result = offset & ~(BITS_PER_LONG-1);
28 28  
... ... @@ -58,14 +58,14 @@
58 58 found_middle:
59 59 return result + __ffs(tmp);
60 60 }
61   -EXPORT_SYMBOL(__find_next_bit);
  61 +EXPORT_SYMBOL(find_next_bit);
62 62  
63 63 /*
64 64 * This implementation of find_{first,next}_zero_bit was stolen from
65 65 * Linus' asm-alpha/bitops.h.
66 66 */
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)
69 69 {
70 70 const unsigned long *p = addr + BITOP_WORD(offset);
71 71 unsigned long result = offset & ~(BITS_PER_LONG-1);
72 72  
... ... @@ -102,15 +102,14 @@
102 102 found_middle:
103 103 return result + ffz(tmp);
104 104 }
105   -EXPORT_SYMBOL(__find_next_zero_bit);
  105 +EXPORT_SYMBOL(find_next_zero_bit);
106 106 #endif /* CONFIG_GENERIC_FIND_NEXT_BIT */
107 107  
108 108 #ifdef CONFIG_GENERIC_FIND_FIRST_BIT
109 109 /*
110 110 * Find the first set bit in a memory region.
111 111 */
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)
114 113 {
115 114 const unsigned long *p = addr;
116 115 unsigned long result = 0;
117 116  
... ... @@ -131,13 +130,12 @@
131 130 found:
132 131 return result + __ffs(tmp);
133 132 }
134   -EXPORT_SYMBOL(__find_first_bit);
  133 +EXPORT_SYMBOL(find_first_bit);
135 134  
136 135 /*
137 136 * Find the first cleared bit in a memory region.
138 137 */
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)
141 139 {
142 140 const unsigned long *p = addr;
143 141 unsigned long result = 0;
... ... @@ -158,7 +156,7 @@
158 156 found:
159 157 return result + ffz(tmp);
160 158 }
161   -EXPORT_SYMBOL(__find_first_zero_bit);
  159 +EXPORT_SYMBOL(find_first_zero_bit);
162 160 #endif /* CONFIG_GENERIC_FIND_FIRST_BIT */
163 161  
164 162 #ifdef __BIG_ENDIAN