]> git.karo-electronics.de Git - linux-beck.git/blobdiff - lib/bitmap.c
lib/string.c: improve strrchr()
[linux-beck.git] / lib / bitmap.c
index db88512c34514ca6ee5d800e94038159c16fd8c1..a13c7f4e325a15e09307c1fd98fc230ee3dab990 100644 (file)
@@ -148,18 +148,19 @@ EXPORT_SYMBOL(__bitmap_shift_right);
  *   @dst : destination bitmap
  *   @src : source bitmap
  *   @shift : shift by this many bits
- *   @bits : bitmap size, in bits
+ *   @nbits : bitmap size, in bits
  *
  * Shifting left (multiplying) means moving bits in the LS -> MS
  * direction.  Zeros are fed into the vacated LS bit positions
  * and those MS bits shifted off the top are lost.
  */
 
-void __bitmap_shift_left(unsigned long *dst,
-                       const unsigned long *src, int shift, int bits)
+void __bitmap_shift_left(unsigned long *dst, const unsigned long *src,
+                       unsigned int shift, unsigned int nbits)
 {
-       int k, lim = BITS_TO_LONGS(bits), left = bits % BITS_PER_LONG;
-       int off = shift/BITS_PER_LONG, rem = shift % BITS_PER_LONG;
+       int k;
+       unsigned int lim = BITS_TO_LONGS(nbits);
+       unsigned int off = shift/BITS_PER_LONG, rem = shift % BITS_PER_LONG;
        for (k = lim - off - 1; k >= 0; --k) {
                unsigned long upper, lower;
 
@@ -168,17 +169,11 @@ void __bitmap_shift_left(unsigned long *dst,
                 * 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);
-               if (left && k + off == lim - 1)
-                       dst[k + off] &= (1UL << left) - 1;
+               upper = src[k] << rem;
+               dst[k + off] = lower | upper;
        }
        if (off)
                memset(dst, 0, off*sizeof(unsigned long));