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

* Re: [PATCH] dm-space-map-disk: improve bit testing
  2011-08-15 18:52 [PATCH] dm-space-map-disk: improve bit testing Mikulas Patocka
@ 2011-08-16 10:08 ` Joe Thornber
  0 siblings, 0 replies; 2+ messages in thread
From: Joe Thornber @ 2011-08-16 10:08 UTC (permalink / raw)
  To: Mikulas Patocka; +Cc: dm-devel

On Mon, Aug 15, 2011 at 02:52:14PM -0400, Mikulas Patocka wrote:
> dm-space-map-disk: improve bit testing

Very nice, thanks.  btw, you can get rid of WORD_MASK_LOW too:

diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
index 8d2c4c2..fbfa6f3 100644
--- a/drivers/md/persistent-data/dm-space-map-disk.c
+++ b/drivers/md/persistent-data/dm-space-map-disk.c
@@ -69,7 +69,6 @@ void *dm_bitmap_data(struct dm_block *b)
 	return dm_block_data(b) + sizeof(struct disk_bitmap_header);
 }
 
-#define WORD_MASK_LOW 0x5555555555555555ULL
 #define WORD_MASK_HIGH 0xAAAAAAAAAAAAAAAAULL
 
 static unsigned bitmap_word_used(void *addr, unsigned b)
@@ -78,7 +77,7 @@ static unsigned bitmap_word_used(void *addr, unsigned b)
 	__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;
+	uint64_t mask = (bits + WORD_MASK_HIGH + 1) & WORD_MASK_HIGH;
 
 	return !(~bits & mask);
 }

^ permalink raw reply related	[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.