[fpc-devel]I suggest a new FPC feature

Michael Van Canneyt michael.vancanneyt at wisa.be
Fri Oct 12 16:13:41 CEST 2001


On Fri, 12 Oct 2001, Jonas Maebe wrote:

>
> On vrijdag, oktober 12, 2001, at 10:30 , Pavel V. Ozerski wrote:
>
> > 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.
>
> That's because you didn't modify any either. Delphi expects you to save
> the necessary registers yourself when you use assembler.
>
> > 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
>
> FPC OTOH, expects that all registers are modified in an assembler
> statement, unless you specify the list of modified registers using the
> ['reg1','reg2'] notation at the end of the assembler procedure.
>
> > My yesterday's tests demonstrated that also for export procedures
> > Delphi 3.0 does not include saving registers into code.
> > Additionally, these tests demonstrate that default conventions which
> > uses FPC are not the same as wich uses FPC for
> > procedures wich have 'stdcall' keyword.
>
> This has nothing to do with differences in calling conventions, but with
> differences in assuming which registers are destroyed in an assembler
> block. Just include some real code which uses a lot of registers in your
> test procedure, and Delphi should save those registers too.
>
> >> Actually, stdcall is *the* standard calling convention for the 80x86
> [cut]
> > Then why Delphi does not save registers in stdcall procedures?
>
> See above, it assumes that you do that yourself when using assembler
> blocks.
>
> > I'm sure, it is not optimization issue : I added built-in-assember
> > instruction mov edi,eax into body
> > of stdcall procedure but Delphi 3 also did not save edi!
>
> Same reason as above.
>
> > Also if  stdcall must save these registers then default calling
> > conventions in fpc are not true stdcall
> > and they should have a name.
>
> Default FPC calling conventions = "fpc calling conventions". They don't
> need a name currently, because we don't have a global switch to change
> the default calling convention. Is there a directive to select "default
> Delphi calling conventions" in Delphi?

No. Delphi uses register calling convention, unless specifically instructed
otherwise in the declaration.

Michael.





More information about the fpc-devel mailing list