From: Peter Lieven <pl@dlhnet.de>
To: "qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Cc: Kevin Wolf <kwolf@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Orit Wasserman <owasserm@redhat.com>,
Stefan Hajnoczi <stefanha@gmail.com>
Subject: [Qemu-devel] [RFC][PATCH 7/9] bitops: use vector algorithm to optimize find_next_bit()
Date: Tue, 12 Mar 2013 16:52:46 +0100 [thread overview]
Message-ID: <513F4F4E.1060009@dlhnet.de> (raw)
this patch adds the usage of buffer_find_nonzero_offset()
to skip large areas of zeroes.
compared to loop unrolling this adds another 50% performance
benefit for skipping large areas of zeroes.
Signed-off-by: Peter Lieven <pl@kamp.de>
---
util/bitops.c | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/util/bitops.c b/util/bitops.c
index e72237a..0a056ff 100644
--- a/util/bitops.c
+++ b/util/bitops.c
@@ -42,10 +42,27 @@ unsigned long find_next_bit(const unsigned long *addr, unsigned long size,
size -= BITS_PER_LONG;
result += BITS_PER_LONG;
}
- while (size & ~(BITS_PER_LONG-1)) {
- if ((tmp = *(p++))) {
- goto found_middle;
+ while (size >= BITS_PER_LONG) {
+ if ((tmp = *p)) {
+ goto found_middle;
+ }
+ if (((uintptr_t) p) % sizeof(VECTYPE) == 0
+ && size >= BITS_PER_BYTE*8*sizeof(VECTYPE)) {
+ unsigned long tmp2 =
+ buffer_find_nonzero_offset(p, ((size/BITS_PER_BYTE) & ~(8*sizeof(VECTYPE)-1)));
+ result += tmp2 * BITS_PER_BYTE;
+ size -= tmp2 * BITS_PER_BYTE;
+ p += tmp2 / sizeof(unsigned long);
+ if (!size) {
+ return result;
+ }
+ if (tmp2) {
+ if ((tmp = *p)) {
+ goto found_middle;
+ }
+ }
}
+ p++;
result += BITS_PER_LONG;
size -= BITS_PER_LONG;
}
--
1.7.9.5
next reply other threads:[~2013-03-12 15:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-12 15:52 Peter Lieven [this message]
2013-03-12 16:04 ` [Qemu-devel] [RFC][PATCH 7/9] bitops: use vector algorithm to optimize find_next_bit() Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=513F4F4E.1060009@dlhnet.de \
--to=pl@dlhnet.de \
--cc=kwolf@redhat.com \
--cc=owasserm@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).