Skip to content

Commit

Permalink
lib: bitmap: eliminate branch in __bitmap_shift_left
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 + off]; moving the shift of lower 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 dba94c2 commit 6d874ec
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,14 @@ void __bitmap_shift_left(unsigned long *dst, const unsigned long *src,
* word below and make them the bottom rem bits of result.
*/
if (rem && k > 0)
lower = src[k - 1];
lower = src[k - 1] >> (BITS_PER_LONG - rem);
else
lower = 0;
upper = src[k];
if (left && k == lim - 1)
upper &= (1UL << left) - 1;
dst[k + off] = upper << rem;
if (rem)
dst[k + off] |= lower >> (BITS_PER_LONG - rem);
upper <<= rem;
dst[k + off] = lower | upper;
if (left && k + off == lim - 1)
dst[k + off] &= (1UL << left) - 1;
}
Expand Down

0 comments on commit 6d874ec

Please sign in to comment.