Il giorno mer, 25/01/2006 alle 22.29 +0100, Marcel Cox ha scritto:
> >   I saw that stack instructions on Intel platform are not used that
> > much. I think this is a pity cause stack operations are small (size
> > optimization) and usually fast (from Pentium two consecutive push/pop
> > are executed together -> speed optimization). Consider this small
> > piece of code
> 
> 
> whether push(pop instructions or mov instructions are faster depends on
> the type of processor used. GCC is well aware of this. If you specify
> the desired processor with -mtune then GCC will use whatever is best
> for that processor. For example if you optimize for old Pentium
> processors, use -mtune=pentium and you will see that the compiler uses
> push/pop instructions even when not using -Os

Marcus,
  I tried many options with some gcc versions but I can confirm that gcc
do not use push in the way I suggest. Perhaps a smaller code will help

extern int foo1(int *a);

void foo2()
{
        int x = 2;
        foo1(&x);
}

should become something like

foo2:
# here is the optimization I suggested, 
# allocation and set with a single instruction
        pushl   $2
# I don't understand why gcc compile 
# movl %esp, %eax  pushl %eax   here
        pushl   %esp
        call    foo1
# this can be subl $4, %esp or similar depending on 
# options you suggested
        popl    %ecx
        ret

Is anybody working in this direction ??

freddy77


Reply via email to