From: Miles Bader <miles@gnu.org>
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Christoph Lameter <cl@linux.com>, Tejun Heo <tj@kernel.org>,
Pekka Enbeerg <penberg@cs.helsinki.fi>,
linux-kernel@vger.kernel.org,
Eric Dumazet <eric.dumazet@gmail.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Subject: Re: x86: A fast way to check capabilities of the current cpu
Date: Thu, 16 Dec 2010 15:25:25 +0900 [thread overview]
Message-ID: <buowrnakze2.fsf@dhlpc061.dev.necel.com> (raw)
In-Reply-To: <4D093580.9000303@zytor.com> (H. Peter Anvin's message of "Wed, 15 Dec 2010 13:39:12 -0800")
"H. Peter Anvin" <hpa@zytor.com> writes:
>> In this case it this_cpu_*_test_bit() return an int, but they act as a
>> bool and are used in if()s; where is the catch?
>
> If they aren't, and are stored in a variable for whatever reason, then
> the || form will generate additional instructions to booleanize the
> value for no good reason.
It doesn't actually have to "booleanize" the value if it's used in a
boolean context though (and, AFAICT, usually won't).
My vague impression is that when used in a boolean context, gcc will
often generate the same or "equivalent" code for both variants -- but
sometimes a||b seems to generate better code; e.g.:
static inline int test1a (int a, int b) { return a ? 1 : b; }
int test1b (int a, int b) { if (test1a (a,b)) return a+b; else return 37; }
static inline int test2a (int a, int b) { return a || b; }
int test2b (int a, int b) { if (test2a (a,b)) return a+b; else return 37; }
=>
test1b:
testl %edi, %edi
jne .L2
movl $37, %eax
testl %esi, %esi
jne .L2
rep
ret
.L2:
leal (%rsi,%rdi), %eax
ret
test2b:
leal (%rsi,%rdi), %edx
movl $37, %eax
orl %edi, %esi
cmovne %edx, %eax
ret
.ident "GCC: (Debian 4.5.1-8) 4.5.1"
-Miles
--
Is it true that nothing can be known? If so how do we know this? -Woody Allen
next prev parent reply other threads:[~2010-12-16 6:33 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-15 20:07 x86: A fast way to check capabilities of the current cpu Christoph Lameter
2010-12-15 20:11 ` x86: Avoid passing struct cpuinfo pointer to mce_available Christoph Lameter
2010-12-15 20:56 ` x86: A fast way to check capabilities of the current cpu Andrew Morton
2010-12-15 21:03 ` H. Peter Anvin
2010-12-15 21:30 ` Miguel Ojeda
2010-12-15 21:39 ` H. Peter Anvin
2010-12-15 21:48 ` Miguel Ojeda
2010-12-16 6:25 ` Miles Bader [this message]
2010-12-16 10:17 ` Miguel Ojeda
2010-12-16 10:29 ` Miles Bader
2010-12-16 15:38 ` H. Peter Anvin
2010-12-17 4:26 ` Miles Bader
2011-01-21 17:11 ` Tejun Heo
2011-01-21 17:21 ` Christoph Lameter
2011-01-21 17:28 ` Tejun Heo
2011-01-21 17:46 ` Christoph Lameter
2011-01-21 17:48 ` Tejun Heo
2011-01-21 17:57 ` Christoph Lameter
2011-01-21 18:12 ` Tejun Heo
2011-01-21 18:20 ` Christoph Lameter
2011-01-21 22:32 ` H. Peter Anvin
2011-01-24 17:05 ` Christoph Lameter
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=buowrnakze2.fsf@dhlpc061.dev.necel.com \
--to=miles@gnu.org \
--cc=akpm@linux-foundation.org \
--cc=cl@linux.com \
--cc=eric.dumazet@gmail.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=miguel.ojeda.sandonis@gmail.com \
--cc=penberg@cs.helsinki.fi \
--cc=tj@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox