[fpc-devel]I suggest a new FPC feature

Peter Vreman peter at freepascal.org
Fri Oct 12 10:22:38 CEST 2001


> >Delphi always saves ebx,esi,edi and therefor doesn't need to insert extra pushes. FPC
uses
> >all available registers and for stdcall it has to insert the pushes to save the
original
> >value.
> 
> I wrote a small test unit:
> 
> unit dtest2;
> interface
> procedure TestProc(x1,x2:longint);stdcall;
> implementation
> procedure TestProc(x1,x2:longint);stdcall;
>  begin
>   asm
>    nop
>   end;
>  end;
> begin
> end.
> 
> Firstly I compiled it with Delphi 3.0 (dcc -J -$O- dtest), then disassembled OBJ-file
with
Watcom disassembler
> (wdisasm -au -p dtest.OBJ). Here is procedure TestProc assembler code:
> 
> TestProc:       pushl   %ebp
>                 movl    %esp,%ebp
>                 nop
>                 popl    %ebp
>                 ret     $0x0008
> 
> I see no saving ebx,esi,edi here. Btw, this obj file could be linked not only to Delphi
or
CPPBuilder projects.
> 
> The same code I get if I cut out 'stdcall' keywords form dtest2 source and compile it
with
FPC 1.1:
> _DTEST2$$_TESTPROC$LONGINT$LONGINT:
> 	pushl	%ebp
> 	movl	%esp,%ebp
> 	nop
> 	leave
> 	ret	$8
> 
> But if I restore  'stdcall'  keywords and compile unit with FPC 1.1, saving registers
will
be added:
> _DTEST2$$_TESTPROC$LONGINT$LONGINT:
> 	pushl	%ebp
> 	movl	%esp,%ebp
> 	pushl	%edi
> 	pushl	%esi
> 	pushl	%ebx
> 	nop
> 	popl	%ebx
> 	popl	%esi
> 	popl	%edi
> 	leave
> 	ret	$8
> 
> My yesterday's tests demonstrated that also for export procedures Delphi 3.0 does not
include saving registers into code.

The assembler parsers doesn't keep track of used registers and simply says that it uses
all registers. 


> Additionally, these tests demonstrate that default conventions which uses FPC are not
the
same as wich uses FPC for
> procedures wich have 'stdcall' keyword.

The default calling convention of FPC is that it thinks that all registers can be changed.
We never said that FPC uses stdcall or is Delphi compatible with it's default calling
convention.







More information about the fpc-devel mailing list