[Patch 2/23] mask v2 - Tighten unused bitmap bit handling

Paul Jackson
2004-04-01T21:11:54Z

Patch_2_of_23 - Dont generate nonzero unused bits in bitmap
Tighten up bitmap so it does not generate nonzero bits
in the unused tail if it is not given any on input.

Diffstat Patch_2_of_23:
bitmap.c | 18 ++++++++++++++----
1 files changed, 14 insertions(+), 4 deletions(-)

===================================================================
--- 2.6.4.orig/lib/bitmap.c 2004-03-31 21:20:02.000000000 -0800
+++ 2.6.4/lib/bitmap.c 2004-03-31 21:22:31.000000000 -0800
@@ -38,6 +38,15 @@
* implemented so as to filter out or avoid being affected by
* possible one bits in the tail.
*
+ * These operations actually provide a slightly stronger guarantee.
+ * If all input masks to a given operation have only zero bits in
+ * their tail, then any output masks from such an operation will
+ * also have only zero bits in the tail. These bitmap operations
+ * themselves don't require that input bitmap arguments to bitmap
+ * operations have zero tails; but these operations will not
+ * generate any ones in tails, if not provided such. This enables
+ * certain efficiencies in users of bitmaps.
+ *
* Bitmaps are declared using the DECLARE_BITMAP() macro in
* include/linux/types.h. Subsequent operations on a bitmap that
* take a bit position, such as set_bit(), must only be provided
@@ -101,11 +110,12 @@

void bitmap_complement(unsigned long *bitmap, int bits)
{
- int k;
- int nr = BITS_TO_LONGS(bits);
-
- for (k = 0; k < nr; ++k)
+ int k, lim = bits/BITS_PER_LONG;
+ for (k = 0; k < lim; ++k)
bitmap[k] = ~bitmap[k];
+
+ if (bits % BITS_PER_LONG)
+ bitmap[k] = ~bitmap[k] & ((1UL << (bits % BITS_PER_LONG)) - 1);
}
EXPORT_SYMBOL(bitmap_complement);