mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Denis Vlasenko <vda@ilport.com.ua>
To: Adrian Bunk <bunk@stusta.de>,
	Denis Vlasenko <vda@port.imtp.ilyichevsk.odessa.ua>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Matt Mackall <mpm@selenic.com>,
	vital@ilport.com.ua
Subject: Re: [PATCH] reduce inlined x86 memcpy by 2 bytes
Date: Tue, 22 Mar 2005 08:40:53 +0200	[thread overview]
Message-ID: <200503220840.53411.vda@ilport.com.ua> (raw)
In-Reply-To: <20050320131737.GD4449@stusta.de>

On Sunday 20 March 2005 15:17, Adrian Bunk wrote:
> Hi Denis,
> 
> what do your benchmarks say about replacing the whole assembler code 
> with a
> 
>   #define __memcpy __builtin_memcpy

It generates call to out-of-line memcpy()
if count is non-constant.

# cat t.c
extern char *a, *b;
extern int n;

void f() {
    __builtin_memcpy(a,b,n);
}

void g() {
    __builtin_memcpy(a,b,24);
}
# gcc -S -O2 --omit-frame-pointer t.c
# cat t.s
        .file   "t.c"
        .text
        .p2align 2,,3
.globl f
        .type   f, @function
f:
        subl    $16, %esp
        pushl   n
        pushl   b
        pushl   a
        call    memcpy
        addl    $28, %esp
        ret
        .size   f, .-f
        .p2align 2,,3
.globl g
        .type   g, @function
g:
        pushl   %edi
        pushl   %esi
        movl    a, %edi
        movl    b, %esi
        cld
        movl    $6, %ecx
        rep
        movsl
        popl    %esi
        popl    %edi
        ret
        .size   g, .-g
        .section        .note.GNU-stack,"",@progbits
        .ident  "GCC: (GNU) 3.4.1"

Proving that it is slower than inline is left
as an excercise to the reader :)

Kernel one will be inlined always.
void h) { __memcpy(a,b,n);} is
        movl    n, %eax
        pushl   %edi
        movl    %eax, %ecx
        pushl   %esi
        movl    a, %edi
        movl    b, %esi
        shrl    $2, %ecx
#APP
        rep ; movsl
        movl %eax,%ecx
        andl $3,%ecx
        jz 1f
        rep ; movsb
        1:
#NO_APP
        popl    %esi
        popl    %edi
        ret
--
vda


      reply	other threads:[~2005-03-22  6:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-18  9:21 Denis Vlasenko
2005-03-18 10:07 ` Denis Vlasenko
2005-03-20 13:17 ` Adrian Bunk
2005-03-22  6:40   ` Denis 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=200503220840.53411.vda@ilport.com.ua \
    --to=vda@ilport.com.ua \
    --cc=bunk@stusta.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpm@selenic.com \
    --cc=vda@port.imtp.ilyichevsk.odessa.ua \
    --cc=vital@ilport.com.ua \
    /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

Powered by JetHome