public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andi Kleen <andi@firstfloor.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andi Kleen <andi@firstfloor.org>, Ingo Molnar <mingo@elte.hu>,
	Jeff Garzik <jeff@garzik.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	x86@kernel.org
Subject: Re: [PATCH] X86-32: Let gcc decide whether to inline memcpy was Re: New x86 warning
Date: Wed, 22 Apr 2009 23:15:01 +0200	[thread overview]
Message-ID: <20090422211501.GD13896@one.firstfloor.org> (raw)
In-Reply-To: <alpine.LFD.2.00.0904221354320.3101@localhost.localdomain>

On Wed, Apr 22, 2009 at 01:56:54PM -0700, Linus Torvalds wrote:
> 
> 
> On Wed, 22 Apr 2009, Andi Kleen wrote:
> > 
> > Modern gcc (and that is all that is supported now) should be able to
> > generate this code on its own already.  So if you call __builtin_* it
> > will  just work (that is what 64bit does) without that explicit code.
> 
> Last time we tried that, it wasn't true. Gcc wouldn't inline even trivial 
> cases of constant sizes.

AFAIK it's all true on 3.2+ when it can figure out the alignment
(but some gcc versions had problems passing the alignment around e.g.
through inlining), under the assumption that out of line can do
a better job with unaligned data. That's not true with my patch,
but could be true in theory.

Quick test here:

char a[10];
char b[2];
char c[4];
char d[8];

short x;
long y;

char xyz[100];


f()
{
#define C(x) memcpy(&x, xyz, sizeof(x));
        C(x)
        C(y)
        C(a)
        C(b)
        C(c)
        C(d)
}

and everything gets inlined with gcc 3.2 which is the oldest
we still care about:

gcc version 3.2.3

        movzwl  xyz+8(%rip), %eax
        movzwl  xyz(%rip), %ecx
        movq    xyz(%rip), %rdx
        movw    %ax, a+8(%rip)
        movw    %cx, x(%rip)
        movw    %cx, b(%rip)
        movl    xyz(%rip), %eax
        movq    %rdx, y(%rip)
        movq    %rdx, a(%rip)
        movq    %rdx, d(%rip)
        movl    %eax, c(%rip)
        ret

-Andi
-- 
ak@linux.intel.com -- Speaking for myself only.

  reply	other threads:[~2009-04-22 21:11 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-22  6:46 New x86 warning Jeff Garzik
2009-04-22  7:01 ` Ingo Molnar
2009-04-22  8:45   ` [PATCH] X86-32: Let gcc decide whether to inline memcpy was " Andi Kleen
2009-04-22 18:00     ` [tip:x86/asm] x86: use __builtin_memcpy() on 32 bits tip-bot for Andi Kleen
2009-04-22 20:56     ` [PATCH] X86-32: Let gcc decide whether to inline memcpy was Re: New x86 warning Linus Torvalds
2009-04-22 21:15       ` Andi Kleen [this message]
2009-04-22 21:19         ` Linus Torvalds
2009-04-22 22:04           ` Andi Kleen
2009-04-23  6:08             ` fresh data was " Andi Kleen
2009-04-23  6:36               ` Ingo Molnar
2009-04-23  7:37                 ` Andi Kleen
2009-04-23  6:30             ` Ingo Molnar
2009-04-23  7:43               ` Andi Kleen
2009-04-22 23:49     ` Joe Damato
2009-04-23  1:48       ` H. Peter Anvin
2009-04-23 21:22         ` Joe Damato
2009-04-23 22:09           ` H. Peter Anvin
2009-04-24  8:44           ` Andi Kleen
2009-04-23  6:09       ` Andi Kleen

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=20090422211501.GD13896@one.firstfloor.org \
    --to=andi@firstfloor.org \
    --cc=hpa@zytor.com \
    --cc=jeff@garzik.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=x86@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