All of lore.kernel.org
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
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: Sat, 17 Jan 2009 16:10:50 -0800	[thread overview]
Message-ID: <4972738A.6030506@zytor.com> (raw)
In-Reply-To: <alpine.LFD.2.00.0901181045550.3006@localhost.localdomain>

Linus Torvalds wrote:
> 
> 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.
> 

When compiling with -O2 -mcmodel=kernel on gcc 4.3.2, you end up with
the same 7-byte sequence:

   4:   48 c7 c7 00 00 00 00    mov    $0x0,%rdi
                        7: R_X86_64_32S bluttan
  10:   48 c7 c7 ff ff ff ff    mov    $0xffffffffffffffff,%rdi

With -Os -mcmodel=kernel, it's a bit better:


   4:   48 c7 c7 00 00 00 00    mov    $0x0,%rdi
                        7: R_X86_64_32S bluttan
  10:   48 83 cf ff             or     $0xffffffffffffffff,%rdi

I would have expected it to have used leaq in the first case, but it's
the same length (7 bytes) and probably has higher latencies.

	-hpa

-- 
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.



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

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-17 15:19 "eliminate warn_on_slowpath()" change causes many gcc-3.2.3 warnings 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
2009-01-18  0:10             ` H. Peter Anvin [this message]

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=4972738A.6030506@zytor.com \
    --to=hpa@zytor.com \
    --cc=kyle@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mikpe@it.uu.se \
    --cc=mingo@elte.hu \
    --cc=torvalds@linux-foundation.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.