diff options
author | Rasmus Villemoes <linux@rasmusvillemoes.dk> | 2015-04-15 19:17:42 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-04-15 19:35:24 -0400 |
commit | 89c1e79eb302349fcaf0697bc9116a4ff16bfeb0 (patch) | |
tree | 350e75e6960b31e2fb29c919a1522bcce166aa84 /include/linux/bitmap.h | |
parent | 8a72ed6fa7e89c5ecd68803cd1160c35b079ea3b (diff) |
linux/bitmap.h: improve BITMAP_{LAST,FIRST}_WORD_MASK
The macro BITMAP_LAST_WORD_MASK can be implemented without a conditional,
which will generally lead to slightly better generated code (221 bytes
saved for allmodconfig-GCOV_KERNEL, ~2k with GCOV_KERNEL). As a small
bonus, this also ensures that the nbits parameter is expanded exactly
once.
In BITMAP_FIRST_WORD_MASK, if start is signed gcc is technically allowed
to assume it is positive (or divisible by BITS_PER_LONG), and hence just
do the simple mask. It doesn't seem to use this, and even on an
architecture like x86 where the shift only depends on the lower 5 or 6
bits, and these bits are not affected by the signedness of the expression,
gcc still generates code to compute the C99 mandated value of start %
BITS_PER_LONG. So just use a mask explicitly, also for consistency with
BITMAP_LAST_WORD_MASK.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Tejun Heo <tj@kernel.org>
Reviewed-by: George Spelvin <linux@horizon.com>
Cc: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/bitmap.h')
-rw-r--r-- | include/linux/bitmap.h | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index dbfbf4990005..be4fa5ddf36c 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h | |||
@@ -172,12 +172,8 @@ extern unsigned int bitmap_ord_to_pos(const unsigned long *bitmap, unsigned int | |||
172 | extern int bitmap_print_to_pagebuf(bool list, char *buf, | 172 | extern int bitmap_print_to_pagebuf(bool list, char *buf, |
173 | const unsigned long *maskp, int nmaskbits); | 173 | const unsigned long *maskp, int nmaskbits); |
174 | 174 | ||
175 | #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) % BITS_PER_LONG)) | 175 | #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) |
176 | #define BITMAP_LAST_WORD_MASK(nbits) \ | 176 | #define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1))) |
177 | ( \ | ||
178 | ((nbits) % BITS_PER_LONG) ? \ | ||
179 | (1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL \ | ||
180 | ) | ||
181 | 177 | ||
182 | #define small_const_nbits(nbits) \ | 178 | #define small_const_nbits(nbits) \ |
183 | (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) | 179 | (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) |