Hi
in this program test function has a known return value , and should be
calculated in compile time , but fpc make it in real time !!!
---------------------
program test;
var c : int32;
function test( p: int32): int32; inline;
var i : int32;
begin
  i := p;
  test := i+2+c+2+c+2+c;
end;
begin
  c:= test(128);
end.

---------------------
fpc (3.1.1 i386 ) generate this asm
---------------------
_main:
        call    FPC_INITIALIZEUNITS
        movl    $128,%eax
        movl    U_$P$TEST_$$_C,%eax
        addl    $130,%eax
        addl    $2,%eax
        addl    U_$P$TEST_$$_C,%eax
        addl    $2,%eax
        addl    U_$P$TEST_$$_C,%eax
        movl    %eax,U_$P$TEST_$$_C
        call    FPC_DO_EXIT
        ret
----------------------

while the same program in c compiled with old version of gcc generate this asm
which is optimal
------------------------
_main:
        pushl   %ebp
        movl    %esp, %ebp
        andl    $-16, %esp
        call    ___main
        movl    _c, %eax
        leal    134(%eax,%eax,2), %eax
        movl    %eax, _c
        leave
        ret
-----------------------
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to