mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-03-30 10:55:03 +00:00
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>
This commit is contained in:
parent
97fb8e940b
commit
cfac1d080a
1 changed files with 4 additions and 4 deletions
|
@ -113,9 +113,9 @@ EXPORT_SYMBOL(__bitmap_complement);
|
||||||
void __bitmap_shift_right(unsigned long *dst, const unsigned long *src,
|
void __bitmap_shift_right(unsigned long *dst, const unsigned long *src,
|
||||||
unsigned shift, unsigned nbits)
|
unsigned shift, unsigned nbits)
|
||||||
{
|
{
|
||||||
unsigned k, lim = BITS_TO_LONGS(nbits), left = nbits % BITS_PER_LONG;
|
unsigned k, lim = BITS_TO_LONGS(nbits);
|
||||||
unsigned off = shift/BITS_PER_LONG, rem = shift % BITS_PER_LONG;
|
unsigned off = shift/BITS_PER_LONG, rem = shift % BITS_PER_LONG;
|
||||||
unsigned long mask = (1UL << left) - 1;
|
unsigned long mask = BITMAP_LAST_WORD_MASK(nbits);
|
||||||
for (k = 0; off + k < lim; ++k) {
|
for (k = 0; off + k < lim; ++k) {
|
||||||
unsigned long upper, lower;
|
unsigned long upper, lower;
|
||||||
|
|
||||||
|
@ -127,12 +127,12 @@ void __bitmap_shift_right(unsigned long *dst, const unsigned long *src,
|
||||||
upper = 0;
|
upper = 0;
|
||||||
else {
|
else {
|
||||||
upper = src[off + k + 1];
|
upper = src[off + k + 1];
|
||||||
if (off + k + 1 == lim - 1 && left)
|
if (off + k + 1 == lim - 1)
|
||||||
upper &= mask;
|
upper &= mask;
|
||||||
upper <<= (BITS_PER_LONG - rem);
|
upper <<= (BITS_PER_LONG - rem);
|
||||||
}
|
}
|
||||||
lower = src[off + k];
|
lower = src[off + k];
|
||||||
if (left && off + k == lim - 1)
|
if (off + k == lim - 1)
|
||||||
lower &= mask;
|
lower &= mask;
|
||||||
lower >>= rem;
|
lower >>= rem;
|
||||||
dst[k] = lower | upper;
|
dst[k] = lower | upper;
|
||||||
|
|
Loading…
Add table
Reference in a new issue