Skip to content

Commit 9d8a6b2

Browse files
Villemoestorvalds
authored andcommitted
lib: bitmap: eliminate branch in __bitmap_shift_right
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 <linux@rasmusvillemoes.dk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 2fbad29 commit 9d8a6b2

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎lib/bitmap.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ void __bitmap_shift_right(unsigned long *dst, const unsigned long *src,
129129
upper = src[off + k + 1];
130130
if (off + k + 1 == lim - 1 && left)
131131
upper &= mask;
132+
upper <<= (BITS_PER_LONG - rem);
132133
}
133134
lower = src[off + k];
134135
if (left && off + k == lim - 1)
135136
lower &= mask;
136-
dst[k] = lower >> rem;
137-
if (rem)
138-
dst[k] |= upper << (BITS_PER_LONG - rem);
137+
lower >>= rem;
138+
dst[k] = lower | upper;
139139
if (left && k == lim - 1)
140140
dst[k] &= mask;
141141
}

0 commit comments

Comments
 (0)