From: Richard Henderson <rth@twiddle.net>
To: Eric Blake <eblake@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
Alexey Kardashevskiy <aik@ozlabs.ru>
Cc: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2] utils: Add pow2ceil()
Date: Fri, 13 Mar 2015 12:04:02 -0700 [thread overview]
Message-ID: <550334A2.10005@twiddle.net> (raw)
In-Reply-To: <5501C2C6.1060501@redhat.com>
On 03/12/2015 09:45 AM, Eric Blake wrote:
> On 03/12/2015 09:29 AM, Richard Henderson wrote:
>> On 02/25/2015 02:45 AM, Markus Armbruster wrote:
>>> return 0x8000000000000000u >> (clz64(value - 1) - 1);
>>
>> I realize this was weeks ago, but it would certainly be preferable to shift a
>> small constant left than a large constant right.
>>
>> Most RISC machines can't form 0x8000000000000000ull without loading 1 and then
>> left shifting to start with. So end the end you're better off with
>>
>> return 1ull << (63 - clz64(value));
>
> Since the value being shifted is a constant either way, can't gcc figure
> out the equivalence and generate the optimal code to begin with? If
> not, should it be opened as a gcc bug for potential optimization?
With the simplest of tests,
unsigned long f(unsigned long x)
{
return 1UL << (63 - x);
}
unsigned long g(unsigned long x)
{
return 0x8000000000000000ul >> x;
}
the code is of similar size: 3 operations each.
But if you throw in the whole operation
1ul << (63 - (__builtin_clzl(x - 1) - 1))
vs
0x8...0ul >> (__builtin_clzl(x - 1) - 1)
then gcc is able to fold away one of the instructions and the 1UL alternative
is shorter.
r~
next prev parent reply other threads:[~2015-03-13 19:04 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-23 12:23 [Qemu-devel] [PATCH v2] utils: Add pow2ceil() Alexey Kardashevskiy
2015-02-23 13:59 ` Markus Armbruster
2015-02-23 16:17 ` Eric Blake
2015-02-23 17:40 ` Markus Armbruster
2015-02-23 21:20 ` Eric Blake
2015-02-24 9:39 ` Markus Armbruster
2015-02-24 11:39 ` Peter Maydell
2015-02-24 13:09 ` Markus Armbruster
2015-02-25 0:40 ` Alexey Kardashevskiy
2015-02-25 10:45 ` Markus Armbruster
2015-03-12 15:29 ` Richard Henderson
2015-03-12 16:45 ` Eric Blake
2015-03-13 19:04 ` Richard Henderson [this message]
2015-03-13 7:33 ` Markus Armbruster
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=550334A2.10005@twiddle.net \
--to=rth@twiddle.net \
--cc=aik@ozlabs.ru \
--cc=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/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 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.