aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRasmus Villemoes <linux@rasmusvillemoes.dk>2018-10-30 18:05:02 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-10-31 11:54:12 -0400
commitc8cebc553368209426f7279736db4f88f1853396 (patch)
tree9e7a7962d243563191df1080d0221e9e5a4d746a
parent7275b097851a5e2e0dd4da039c7e96b59ac5314e (diff)
linux/bitmap.h: remove redundant uses of small_const_nbits()
In the _zero, _fill and _copy functions, the small_const_nbits branch is redundant. If nbits is small and const, gcc knows full well that BITS_TO_LONGS(nbits) is 1, so len is also a compile-time constant (sizeof(long)), and calling memset or memcpy with a length argument of sizeof(long) makes gcc generate the expected code anyway: #include <string.h> void a(unsigned long *x) { memset(x, 0, 8); } void b(unsigned long *x) { memset(x, 0xff, 8); } void c(unsigned long *x, const unsigned long *y) { memcpy(x, y, 8); } turns into 0000000000000000 <a>: 0: 48 c7 07 00 00 00 00 movq $0x0,(%rdi) 7: c3 retq 8: 0f 1f 84 00 00 00 00 nopl 0x0(%rax,%rax,1) f: 00 0000000000000010 <b>: 10: 48 c7 07 ff ff ff ff movq $0xffffffffffffffff,(%rdi) 17: c3 retq 18: 0f 1f 84 00 00 00 00 nopl 0x0(%rax,%rax,1) 1f: 00 0000000000000020 <c>: 20: 48 8b 06 mov (%rsi),%rax 23: 48 89 07 mov %rax,(%rdi) 26: c3 retq Link: http://lkml.kernel.org/r/20180818131623.8755-4-linux@rasmusvillemoes.dk Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Cc: Yury Norov <ynorov@caviumnetworks.com> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk> Cc: Sudeep Holla <sudeep.holla@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--include/linux/bitmap.h24
1 files changed, 6 insertions, 18 deletions
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index a9805bacbd7c..004cd42a3c4d 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -214,33 +214,21 @@ extern int bitmap_print_to_pagebuf(bool list, char *buf,
214 214
215static inline void bitmap_zero(unsigned long *dst, unsigned int nbits) 215static inline void bitmap_zero(unsigned long *dst, unsigned int nbits)
216{ 216{
217 if (small_const_nbits(nbits)) 217 unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
218 *dst = 0UL; 218 memset(dst, 0, len);
219 else {
220 unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
221 memset(dst, 0, len);
222 }
223} 219}
224 220
225static inline void bitmap_fill(unsigned long *dst, unsigned int nbits) 221static inline void bitmap_fill(unsigned long *dst, unsigned int nbits)
226{ 222{
227 if (small_const_nbits(nbits)) 223 unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
228 *dst = ~0UL; 224 memset(dst, 0xff, len);
229 else {
230 unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
231 memset(dst, 0xff, len);
232 }
233} 225}
234 226
235static inline void bitmap_copy(unsigned long *dst, const unsigned long *src, 227static inline void bitmap_copy(unsigned long *dst, const unsigned long *src,
236 unsigned int nbits) 228 unsigned int nbits)
237{ 229{
238 if (small_const_nbits(nbits)) 230 unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
239 *dst = *src; 231 memcpy(dst, src, len);
240 else {
241 unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
242 memcpy(dst, src, len);
243 }
244} 232}
245 233
246/* 234/*