[fpc-devel]default calling convention change for i386

Peter Vreman peter at freepascal.org
Fri Dec 26 14:24:28 CET 2003


> On Wed, 24 Dec 2003, Peter Vreman wrote:
>
> }Most important was compatibility, second is speed. In the drystone test
> }there was a performance gain of at least 10%.
>
> Okay, I think this answers the question :)
>
> }> Register convention saves opcode space in the called function, because
> }> within
> }> the instruction opcode,  registers are encoded with small bit fields,
> }> whereas
> }> offsets into a stack frame are encoded as (8-, 16-, or 32-bit) words,
> }> unless
> }> the processor supports something like short offsets. Actually, I don't
> }> know
> }> if the i386 does support such short offsets. AFAIK, the 68000 does not.
> }
> }Sorry, this is not correct. The code size is increased with register
> }calling. The reason is that in the called routines the passed registers
> }need to be saved in the local stackframe. When we have register variables
> }support (currently not working for 1.9.x) this can be reduced.
>
> This is exactly what makes me doubt in the benefits of register calling.
> Because of the small number of registers to spare, the whole process of
> calling and executing a subroutine looks like this to me:
>
> 1. Calculate values of parameters and push them into stack, one by one.
> 2. Pop the values into appropriate registers (omitted when not using
> register convention)
> 3. Call the subroutine.
> 4. Push parameters into stack (omitted when not using register convention)
> 5. Access parameters in stack as they are needed.
>
> Well, this is just an oversimplified theory. As Peter noted, the practice
> might be somewhat more pleasant :)

The push on the stack (=saving the value) is the task of the register
allocator. The compiler internally uses imaginary registers. These
registers will be assigned later on by the register allocator and when it
has too less real registers available the register will be save temporary
in the stackframe. The better the register allocator can do his job the
better code is generated. In a lot of cases with simple callings like
proc(i,j,k) the values of i,j and k will directly be loaded in the correct
register.

For more information see the technical design (=source code) :-)






More information about the fpc-devel mailing list