qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] bitops: provide an inline implementation of find_first_bit
@ 2013-12-22 11:32 Aurelien Jarno
  2013-12-22 17:04 ` Richard Henderson
  2014-06-19  8:36 ` Paolo Bonzini
  0 siblings, 2 replies; 6+ messages in thread
From: Aurelien Jarno @ 2013-12-22 11:32 UTC (permalink / raw)
  To: qemu-devel; +Cc: Corentin Chary, Aurelien Jarno, Richard Henderson

find_first_bit has started to be used heavily in TCG code. The current
implementation based on find_next_bit is not optimal and can't be
optimized be the compiler if the bit array has a fixed size, which is
the case most of the time.

This new implementation does not use find_next_bit and is yet small
enough to be inlined.

Cc: Richard Henderson <rth@twiddle.net>
Cc: Corentin Chary <corentin.chary@gmail.com>

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
---
 include/qemu/bitops.h |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h
index 304c90c..041142a 100644
--- a/include/qemu/bitops.h
+++ b/include/qemu/bitops.h
@@ -157,7 +157,17 @@ unsigned long find_next_zero_bit(const unsigned long *addr,
 static inline unsigned long find_first_bit(const unsigned long *addr,
                                            unsigned long size)
 {
-    return find_next_bit(addr, size, 0);
+    unsigned long result, tmp;
+
+    for (result = 0; result < size; result += BITS_PER_LONG) {
+        tmp = *addr++;
+        if (tmp) {
+            result += ctzl(tmp);
+            return result < size ? result : size;
+        }
+    }
+    /* Not found */
+    return size;
 }
 
 /**
-- 
1.7.10.4

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

end of thread, other threads:[~2014-06-20  9:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-22 11:32 [Qemu-devel] [PATCH] bitops: provide an inline implementation of find_first_bit Aurelien Jarno
2013-12-22 17:04 ` Richard Henderson
2014-06-19  8:36 ` Paolo Bonzini
2014-06-20  8:48   ` Aurelien Jarno
2014-06-20  8:58     ` Paolo Bonzini
2014-06-20  9:43       ` Aurelien Jarno

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).