memmove optimization on X86_64

Pierre Habouzit madcoder@debian.org
Sun May 6 08:28:00 GMT 2007


On Sun, May 06, 2007 at 02:52:14AM +0200, insight insight wrote:
> Hello,
> i use glibc 2.4 on X86_64 and in debugging a C program, i have looked
> at the code of memmove
> and I was quite surprise by the code produced. no inline function or
> macro and more disturbing
> byte by byte copy and not 64 bits by 64 bits copy....
> 
> code of the loop of memmove on my computer :
> 
> -    0x2b3481a26290    <memmove+144>:        movzx  eax,BYTE PTR [rbx]
> -    0x2b3481a26293    <memmove+147>:        add    rbx,0x1
> -    0x2b3481a26297    <memmove+151>:        mov    BYTE PTR [rbp],al
> -    0x2b3481a2629a    <memmove+154>:        add    rbp,0x1
> -    0x2b3481a2629e    <memmove+158>:        sub    rdx,0x1
> -    0x2b3481a262a2    <memmove+162>:        jne    0x2b3481a26290
> 
>  memset (or bzero) is much more optimized, because it seems to use
> inline function or macro if number of bytes to set is less than a
> certain number and else a function with 64 bits sets in memory in the
> loop.
> but these functions should used inline functions in every situations,
> the function is else incredibly long to initialize the loop...
> i thought that the "rep stosd" was used    (in 64 bits, i dont know if
> it is "rep stosq", long time i dont use assembler)
> 
> Was I juste unlucky with this version of glibc on X86_64 ?

  That has (IMHO) nothing to do with the glibc, as the libc has nothing
to do with code generation, your compiler does.

  Which compiler did you used, if gcc did you turned optimisations (-O2
usually) on ?

-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20070506/655f20a3/attachment.sig>


More information about the Libc-alpha mailing list