memcpy (&eax, &eax, 4) generated on gcc-2.96,i386

Etienne Lorrain etienne_lorrain@yahoo.fr
Thu Jun 22 02:25:00 GMT 2000


  Hello,

  The subject of my message could also have been:
 "what is the difference between using:
struct a_type { unsigned a_number; };
 and:
typedef struct { unsigned a_number; } a_type;
 "

  In short, using http://www.codesourcery.com/gcc-compile.shtml
 and also gcc-2.95.2, if I compile that (with -O2) everything if fine:
---------------------------------
typedef struct { unsigned a_number; } a_type;

extern inline a_type a_fct (void)
  {
  unsigned returned;

  asm volatile (" " : "=a" (returned));
  return *(a_type *)&returned;
  }

int fct (void)
  {
  return a_fct().a_number;
  }

---------------------------------
        .file   "@21503.1"
        .version        "01.01"
gcc2_compiled.:
.text
        .align 4
.globl fct
        .type    fct,@function
fct:
        pushl   %ebp
        movl    %esp, %ebp
#APP
         
#NO_APP
        popl    %ebp
        ret
.Lfe1:
        .size    fct,.Lfe1-fct
        .ident  "GCC: (GNU) 2.96 20000621 (experimental)"
---------------------------------
  All is nicely optimised.


  But if I replace the typedef by a struct:
---------------------------------
struct a_type { unsigned a_number; };

extern inline struct a_type a_fct (void)
  {
  unsigned returned;

  asm volatile (" " : "=a" (returned));
  return *(struct a_type *)&returned;
  }

int fct (void)
  {
  return a_fct().a_number;
  }
---------------------------------
        .file   "@21535.1"
        .version        "01.01"
gcc2_compiled.:
.globl memcpy
.text
        .align 4
.globl fct
        .type    fct,@function
fct:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $12, %esp
#APP
         
#NO_APP
        pushl   $4
        movl    %eax, -4(%ebp)
        leal    -4(%ebp), %eax
        pushl   %eax
        leal    -8(%ebp), %eax
        pushl   %eax
        call    memcpy
        addl    $16, %esp
        movl    -8(%ebp), %eax
        leave
        ret
.Lfe1:
        .size    fct,.Lfe1-fct
        .ident  "GCC: (GNU) 2.96 20000621 (experimental)"
---------------------------------
  To copy %eax in %eax, two temporary variables are generated
 and a memcpy is called...

  It is still working, but not as fast as the "typedef" version.

  Have a nice day,
  Etienne.

___________________________________________________________
Do You Yahoo!?
Achetez, vendez! À votre prix! Sur http://encheres.yahoo.fr


More information about the Gcc-bugs mailing list