All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dm-space-map-disk: improve bit testing
@ 2011-08-15 18:52 Mikulas Patocka
  2011-08-16 10:08 ` Joe Thornber
  0 siblings, 1 reply; 2+ messages in thread
From: Mikulas Patocka @ 2011-08-15 18:52 UTC (permalink / raw)
  To: Edward Thornber; +Cc: dm-devel

dm-space-map-disk: improve bit testing

This patch improves bit testing in bitmap_word_used:
* replace three tests with just one condition.
* make the test accurate --- the function returns 0 only if there exists
  a pair of two zeroed bits. Previously, the function returned 0 in some other
  cases too.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

---
 drivers/md/persistent-data/dm-space-map-disk.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Index: linux-3.0-fast/drivers/md/persistent-data/dm-space-map-disk.c
===================================================================
--- linux-3.0-fast.orig/drivers/md/persistent-data/dm-space-map-disk.c	2011-08-15 20:39:38.000000000 +0200
+++ linux-3.0-fast/drivers/md/persistent-data/dm-space-map-disk.c	2011-08-15 20:44:34.000000000 +0200
@@ -70,7 +70,6 @@ void *dm_bitmap_data(struct dm_block *b)
 
 #define WORD_MASK_LOW 0x5555555555555555ULL
 #define WORD_MASK_HIGH 0xAAAAAAAAAAAAAAAAULL
-#define WORD_MASK_ALL 0xFFFFFFFFFFFFFFFFULL
 
 static unsigned bitmap_word_used(void *addr, unsigned b)
 {
@@ -78,10 +77,9 @@ static unsigned bitmap_word_used(void *a
 	__le64 *w_le = words_le + (b >> ENTRIES_SHIFT);
 
 	uint64_t bits = le64_to_cpu(*w_le);
+	uint64_t mask = (bits - WORD_MASK_LOW) & WORD_MASK_HIGH;
 
-	return ((bits & WORD_MASK_LOW) == WORD_MASK_LOW ||
-		(bits & WORD_MASK_HIGH) == WORD_MASK_HIGH ||
-		(bits & WORD_MASK_ALL) == WORD_MASK_ALL);
+	return !(~bits & mask);
 }
 
 unsigned sm_lookup_bitmap(void *addr, unsigned b)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-08-16 10:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-15 18:52 [PATCH] dm-space-map-disk: improve bit testing Mikulas Patocka
2011-08-16 10:08 ` Joe Thornber

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.