]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
lib: bitmap: eliminate branch in __bitmap_shift_right
authorRasmus Villemoes <linux@rasmusvillemoes.dk>
Fri, 13 Feb 2015 22:36:05 +0000 (14:36 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 14 Feb 2015 05:21:35 +0000 (21:21 -0800)
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>
lib/bitmap.c

index 45e7d14ebdfdeb6403b900dd7b3e1cdc332e0b15..a7a8bc02892dbfbb1d3b7b1942cb3c9b030b9f6c 100644 (file)
@@ -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;
        }