[fpc-devel]default calling convention change for i386

Peter Vreman peter at freepascal.org
Wed Dec 24 21:09:28 CET 2003


>> Anyway, has someone actually analyzed how benefitial register calling
>> convention is? Sure it provides huge speed boost in case of a function
>> which adds two arguments together and returns the result - or is it so
>> sure? In fact, I imagine that in most cases, register convention will
>> eventually be detrimental to both speed and code size.
>>
>> Again, no complain intended, just curiousity.
>>
>
> I'm not a developper of free-pascal, so the following statements are just
> general considerations.
>
> To me, register convention is a great step forward, concerning the
> economic
> usage of available resources.

Most important was compatibility, second is speed. In the drystone test
there was a performance gain of at least 10%.


> 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.

> Every register parameter also saves at least two memory (stack) accesses,
> which are considerably slower compared to register accesses and increase
> bus
> use.

This is true. For the Athlon the optimized parameter passing on the stack
uses already mov <x>,[esp] instead of push.


> When writing low-level functions in 680x0 assembler, I always pass
> parameters
> in registers (there are 15 of them, which is quite a lot). In an embedded
> system, I sometimes even use "global" register variables, e. g. register
> D7
> contains, throughout the whole program, the current user ID.

For the other processors like powerpc,sparc and x86_64 the standard ABI is
like register calling. Don't know for the m68k abi.

<snip>

> A further benefit would result from optimization between the registers
> passing
> parameters to my_function, and the registers used within function main for
> variables a and b, by allocating identical registers, thus removing
> instructions of the form "move d5, d5". That's an optimization technique
> easy
> in assembler, but difficult for a compiler, especially when maintaining
> register allocation through serveral levels of function calls.
>
> If anyone does some performance testing, comparing the two conventions,
> please
> post it to the list.

At least the performance of compiler itself can't be compared easily.
Because register calling increases the number of used registers so the
register allocator has more work todo.






More information about the fpc-devel mailing list