From: Paolo Bonzini <pbonzini@redhat.com>
To: Aurelien Jarno <aurelien@aurel32.net>, qemu-devel@nongnu.org
Cc: Corentin Chary <corentin.chary@gmail.com>,
Richard Henderson <rth@twiddle.net>
Subject: Re: [Qemu-devel] [PATCH] bitops: provide an inline implementation of find_first_bit
Date: Thu, 19 Jun 2014 10:36:18 +0200 [thread overview]
Message-ID: <53A2A102.4060807@redhat.com> (raw)
In-Reply-To: <1387711957-703-1-git-send-email-aurelien@aurel32.net>
Il 22/12/2013 12:32, Aurelien Jarno ha scritto:
> 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.
If you mean by fully unrolling the loop, that's right.
However...
> - 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;
> }
>
> /**
>
... you probably want to limit this to bitmaps that are of constant
size, and small enough that the compiler will unroll them.
So it probably would be a good idea to add an
if (!__builtin_constant_p(size) || size > 8 * BITS_PER_LONG)
return find_next_bit(addr, size, 0);
Not urgent since TCG is the only user of find_first_bit right now, but
worth considering.
Paolo
next prev parent reply other threads:[~2014-06-19 8:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2014-06-20 8:48 ` Aurelien Jarno
2014-06-20 8:58 ` Paolo Bonzini
2014-06-20 9:43 ` Aurelien Jarno
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=53A2A102.4060807@redhat.com \
--to=pbonzini@redhat.com \
--cc=aurelien@aurel32.net \
--cc=corentin.chary@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/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).