aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bitmap.c
diff options
context:
space:
mode:
authorRasmus Villemoes <linux@rasmusvillemoes.dk>2015-02-13 17:36:10 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-02-14 00:21:35 -0500
commitcfac1d080a00544e5cecd2d7c9ebe3d6a5cc18e6 (patch)
tree8f5d99e331fbd14fedaff8b58625ee4fd5e8190a /lib/bitmap.c
parent97fb8e940bc56b157517c812c9c6cbfc83d48d78 (diff)
lib: bitmap: yet another simplification in __bitmap_shift_right
If left is 0, we can just let mask be ~0UL, so that anding with it is a no-op. Conveniently, BITMAP_LAST_WORD_MASK provides precisely what we need, and we can eliminate left. Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib/bitmap.c')
-rw-r--r--lib/bitmap.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/bitmap.c b/lib/bitmap.c
index 761d2d4989ee..db88512c3451 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -113,9 +113,9 @@ EXPORT_SYMBOL(__bitmap_complement);
113void __bitmap_shift_right(unsigned long *dst, const unsigned long *src, 113void __bitmap_shift_right(unsigned long *dst, const unsigned long *src,
114 unsigned shift, unsigned nbits) 114 unsigned shift, unsigned nbits)
115{ 115{
116 unsigned k, lim = BITS_TO_LONGS(nbits), left = nbits % BITS_PER_LONG; 116 unsigned k, lim = BITS_TO_LONGS(nbits);
117 unsigned off = shift/BITS_PER_LONG, rem = shift % BITS_PER_LONG; 117 unsigned off = shift/BITS_PER_LONG, rem = shift % BITS_PER_LONG;
118 unsigned long mask = (1UL << left) - 1; 118 unsigned long mask = BITMAP_LAST_WORD_MASK(nbits);
119 for (k = 0; off + k < lim; ++k) { 119 for (k = 0; off + k < lim; ++k) {
120 unsigned long upper, lower; 120 unsigned long upper, lower;
121 121
@@ -127,12 +127,12 @@ void __bitmap_shift_right(unsigned long *dst, const unsigned long *src,
127 upper = 0; 127 upper = 0;
128 else { 128 else {
129 upper = src[off + k + 1]; 129 upper = src[off + k + 1];
130 if (off + k + 1 == lim - 1 && left) 130 if (off + k + 1 == lim - 1)
131 upper &= mask; 131 upper &= mask;
132 upper <<= (BITS_PER_LONG - rem); 132 upper <<= (BITS_PER_LONG - rem);
133 } 133 }
134 lower = src[off + k]; 134 lower = src[off + k];
135 if (left && off + k == lim - 1) 135 if (off + k == lim - 1)
136 lower &= mask; 136 lower &= mask;
137 lower >>= rem; 137 lower >>= rem;
138 dst[k] = lower | upper; 138 dst[k] = lower | upper;