git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[GSoC][PATCH v2] Optimize ewah_bitmap.c for efficiency using trailing zeros for set bit iteration

From
Aryan Gupta <garyan447@gmail.com>
Date
Mar 13, 2024, 22:37 UTC
Message-ID
<20240313223751.50816-1-garyan447@gmail.com>
In-Reply-To
<20240310162614.62691-1-garyan447@gmail.com>
Signed-off-by: Aryan Gupta <garyan447@gmail.com>
---

Thank you Vicent for the guidance. I am still not sure how to do the performance measurement for this improvement. Any guidance would be appreciated.

 ewah/ewah_bitmap.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/ewah/ewah_bitmap.c b/ewah/ewah_bitmap.c
index 8785cbc54a..1a75f50682 100644
--- a/ewah/ewah_bitmap.c
+++ b/ewah/ewah_bitmap.c
@@ -257,12 +257,15 @@ void ewah_each_bit(struct ewah_bitmap *self, void (*callback)(size_t, void*), vo
 		for (k = 0; k < rlw_get_literal_words(word); ++k) {
 			int c;
 
-			/* todo: zero count optimization */
-			for (c = 0; c < BITS_IN_EWORD; ++c, ++pos) {
-				if ((self->buffer[pointer] & ((eword_t)1 << c)) != 0)
-					callback(pos, payload);
+			eword_t bitset = self->buffer[pointer]; 
+			while(bitset != 0) {
+				eword_t t = bitset & -bitset; 
+				int r = __builtin_ctzl(bitset); 
+				bitset ^= t; 
+				callback(pos+r, payload);
 			}
-
+			
+			pos += BITS_IN_EWORD;
 			++pointer;
 		}
 	}
-- 
2.25.1
Previous: Aryan GuptaNext: Karthik Nayak
Message 6 of 8 in “add zero count optimization in ewah_bitmap.c”
  1. Aryan GuptaMar 10, 2024
  2. [GSoC][PATCH 1/1] add zero count optimization in ewah_bitmap.cAryan Gupta, Mar 10, 2024
  3. Junio C HamanoMar 11, 2024
  4. Junio C HamanoMar 11, 2024
  5. Aryan GuptaMar 11, 2024
  6. [GSoC][PATCH v2] Optimize ewah_bitmap.c for efficiency using trailing zeros for set bit iterationAryan Gupta, Mar 13, 2024
  7. Karthik NayakMar 18, 2024
  8. Junio C HamanoMar 18, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.