All of lore.kernel.org
 help / color / mirror / Atom feed
From: Denys Vlasenko <vda.linux@googlemail.com>
To: Jan Hubicka <jh@suse.cz>
Cc: Roland Dreier <rdreier@cisco.com>,
	Arjan van de Ven <arjan@infradead.org>,
	Stephen Hemminger <shemminger@linux-foundation.org>,
	Andi Kleen <ak@suse.de>,
	discuss@x86-64.org, linux-kernel@vger.kernel.org
Subject: Re: [discuss] [PATCH] x86-64: memset optimization
Date: Tue, 21 Aug 2007 11:16:10 +0100	[thread overview]
Message-ID: <200708211116.11035.vda.linux@googlemail.com> (raw)
In-Reply-To: <20070820185637.GL27714@kam.mff.cuni.cz>

On Monday 20 August 2007 19:56, Jan Hubicka wrote:
> >  > > The problem is with the optimization flags: passing -Os causes the
> >  > > compiler to be stupid and not inline any memset/memcpy functions.
> >  >
> >  > you get what you ask for.. if you don't want that then don't ask for
> >  > it ;)
> >
> > Well, the compiler is really being dumb about -Os and in fact it's
> > giving bigger code, so I'm not really getting what I ask for.
> >
> > With my gcc at least (x86_64, gcc (GCC) 4.1.3 20070812 (prerelease)
> > (Ubuntu 4.1.2-15ubuntu2)) and Andi's example:
> >
> > #include <string.h>
> >
> > f(char x[6]) {
> >         memset(x, 1, 6);
> > }
> >
> > compiling with -O2 gives
> >
> > 0000000000000000 <f>:
> >    0:	c7 07 01 01 01 01    	movl   $0x1010101,(%rdi)
> >    6:	66 c7 47 04 01 01    	movw   $0x101,0x4(%rdi)
> >    c:	c3                   	retq
>
> GCC mainline (ie future GCC4.3.0) now give:
> 0000000000000000 <f>:
>    0:   b0 01                   mov    $0x1,%al
>    2:   b9 06 00 00 00          mov    $0x6,%ecx
>    7:   f3 aa                   rep stos %al,%es:(%rdi)
>    9:   c3                      retq
> That is smallest, definitly not fastest.
> GCC up to 4.3.0 won't be able to inline memset with non-0 operand...

No, it's not smallest. This one is smaller by 1 byte, maybe faster
(rep ... prefix is microcoded -> slower) and frees %ecx for other uses:

        mov    $0x01010101,%eax  # 5 bytes
        stosl                    # 1 byte
        stosw                    # 2 bytes
        retq
--
vda

      reply	other threads:[~2007-08-21 10:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-17 23:34 [PATCH] x86-64: memset optimization Stephen Hemminger
2007-08-18  7:17 ` Eric Dumazet
2007-08-18  9:46 ` Andi Kleen
2007-08-18 14:56   ` Stephen Hemminger
2007-08-18 18:55     ` Andi Kleen
2007-08-19  5:04       ` Stephen Hemminger
2007-08-19 18:24         ` [discuss] " Andi Kleen
2007-08-20 15:52           ` Stephen Hemminger
2007-08-20 15:51             ` Arjan van de Ven
2007-08-20 17:03               ` Roland Dreier
2007-08-20 18:16                 ` Andi Kleen
2007-08-20 18:56                 ` Jan Hubicka
2007-08-21 10:16                   ` Denys Vlasenko [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=200708211116.11035.vda.linux@googlemail.com \
    --to=vda.linux@googlemail.com \
    --cc=ak@suse.de \
    --cc=arjan@infradead.org \
    --cc=discuss@x86-64.org \
    --cc=jh@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdreier@cisco.com \
    --cc=shemminger@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.