mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: Kyle McMartin <kyle@infradead.org>, Ingo Molnar <mingo@elte.hu>,
	Mikael Pettersson <mikpe@it.uu.se>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: "eliminate warn_on_slowpath()" change causes many gcc-3.2.3 warnings
Date: Sun, 18 Jan 2009 11:01:44 +1100 (EST)	[thread overview]
Message-ID: <alpine.LFD.2.00.0901181045550.3006@localhost.localdomain> (raw)
In-Reply-To: <49726C56.6080905@zytor.com>



On Sat, 17 Jan 2009, H. Peter Anvin wrote:
> 
> At least on x86, the two ops should be the same cost?

Not with the code Kyle had, which forces a memory load.

But yes, with a constant address, it at least comes close. But with a 
small explicit constant value, the compiler can often do even better. For 
example, you can generate a 64-bit -1 in many ways, while a 64-bit random 
address is much more work to generate.

Of course, I don't know how much gcc takes advantage of this. Maybe it 
always just generates a silly "movq" rather than being smarter about it 
(eg "orl $-1,reg" can do it in four bytes, I think, because you can use a 
single-byte constant).

Of course, zero is even easier to generate, so NULL is the best constant 
of all, but generally small integers are more amenable to optimization 
than generic addresses. They're also generally easier to test for.

		Linus

  reply	other threads:[~2009-01-18  0:02 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-17 15:19 Mikael Pettersson
2009-01-17 16:18 ` Ingo Molnar
2009-01-17 20:01   ` H. Peter Anvin
2009-01-17 20:44     ` Kyle McMartin
2009-01-17 20:57       ` Kyle McMartin
2009-01-17 21:07       ` H. Peter Anvin
2009-01-17 21:38         ` Kyle McMartin
2009-01-17 23:37       ` Linus Torvalds
2009-01-17 23:40         ` H. Peter Anvin
2009-01-18  0:01           ` Linus Torvalds [this message]
2009-01-18  0:10             ` H. Peter Anvin

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=alpine.LFD.2.00.0901181045550.3006@localhost.localdomain \
    --to=torvalds@linux-foundation.org \
    --cc=hpa@zytor.com \
    --cc=kyle@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mikpe@it.uu.se \
    --cc=mingo@elte.hu \
    /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

all inboxes | Powered by JetHome®