This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gcc-3.4-pre ia32, Compound Literals and optimisation, memcpy(20 bytes)


  Hello,

  I noticed that memcpy() was called by a simple pattern even when
 providing options: -Os -march=i386 -minline-all-stringops
 In fact the option "-Os" helps a lot to call the memcpy.
 Here is the snipset which produce the call to memcpy(),
 it seems that the optimiser miss that the "Compound Literals"
 GCC extension should be done on the memory variable and not
 on a copy on stack and then memcopy'ed. This is handled without
 problem with GCC-3.3, no intermediate temporary structure.
  I do not really care of calling memcpy() because I already
 have the patch to create a memcpy per section, but anyways
 I do a byte memcpy to reduce code size and the assembly
 of this function "joystick_init()" is a lot more complex
 than needed.

  Thanks for reading,
  Etienne.

[etienne@localhost gujin]$ cat tst.c
struct joystick_str {
    unsigned short Xmin, Xmid, Xmax, Ymin, Ymid, Ymax;
    unsigned short unused;
    unsigned last_nbtick;
    } joystick;
 
void joystick_init (unsigned Ax, unsigned Ay)
  {
  joystick = (const struct joystick_str) {
          .Xmin = Ax, .Xmid = Ax, .Xmax = Ax,
          .Ymin = Ay, .Ymid = Ay, .Ymax = Ay,
          };
  }
 
[etienne@localhost gujin]$ ../toolchain-3.4/bin/gcc -v
Reading specs from
/home/etienne/projet/toolchain-3.4/bin/../lib/gcc/i686-pc-linux-gnu/3.4.0/specs
Configured with: ../configure --prefix=/home/etienne/projet/toolchain
--enable-languages=c
Thread model: posix
gcc version 3.4.0 20040121 (prerelease)
[etienne@localhost gujin]$ ../toolchain-3.4/bin/gcc -Os -march=i386
-minline-all-stringops -S tst.c -o tst.s
[etienne@localhost gujin]$ cat tst.s
        .file   "tst.c"
        .text
.globl joystick_init
        .type   joystick_init, @function
joystick_init:
        pushl   %ebp
        movl    %esp, %ebp
        pushl   %edi
        pushl   %ebx
        subl    $32, %esp
        leal    -40(%ebp), %edi
        cld
        xorl    %eax, %eax
        movl    $5, %ecx
        movl    12(%ebp), %ebx
        movl    8(%ebp), %edx
        rep
        stosl
        pushl   $20
        leal    -40(%ebp), %eax
        pushl   %eax
        pushl   $joystick
        movw    %bx, -34(%ebp)
        movw    %bx, -32(%ebp)
        movw    %bx, -30(%ebp)
        movw    %dx, -40(%ebp)
        movw    %dx, -38(%ebp)
        movw    %dx, -36(%ebp)
        call    memcpy
        leal    -8(%ebp), %esp
        popl    %ebx
        popl    %edi
        leave
        ret
        .size   joystick_init, .-joystick_init
        .comm   joystick,20,4
        .section        .note.GNU-stack,"",@progbits
        .ident  "GCC: (GNU) 3.4.0 20040121 (prerelease)"




	

	
		
Yahoo! Mail : votre e-mail personnel et gratuit qui vous suit partout ! 
Créez votre Yahoo! Mail sur http://fr.benefits.yahoo.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]