Skip to content

Commit

Permalink
lib: bitmap: eliminate branch in __bitmap_shift_right
Browse files Browse the repository at this point in the history
We can shift the bits from lower and upper into place before assembling
dst[k]; moving the shift of upper into the branch where we already know
that rem is non-zero allows us to remove a conditional.

Signed-off-by: Rasmus Villemoes <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Villemoes authored and torvalds committed Feb 14, 2015
1 parent 2fbad29 commit 9d8a6b2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ void __bitmap_shift_right(unsigned long *dst, const unsigned long *src,
upper = src[off + k + 1];
if (off + k + 1 == lim - 1 && left)
upper &= mask;
upper <<= (BITS_PER_LONG - rem);
}
lower = src[off + k];
if (left && off + k == lim - 1)
lower &= mask;
dst[k] = lower >> rem;
if (rem)
dst[k] |= upper << (BITS_PER_LONG - rem);
lower >>= rem;
dst[k] = lower | upper;
if (left && k == lim - 1)
dst[k] &= mask;
}
Expand Down

0 comments on commit 9d8a6b2

Please sign in to comment.