[fpc-devel] Generated code of constant parameters of double type

Luiz Americo Pereira Camara pascalive at bol.com.br
Sun Nov 16 19:52:06 CET 2008

Florian Klaempfl escreveu:
> Luiz Americo Pereira Camara schrieb:
>> Florian Klaempfl escreveu:
>>> Luiz Americo Pereira Camara schrieb:
>>>> My point was that this could be a missing optimization opportunity: 
>>>> pass by reference a 8 bytes parameter when the pointer size is 4. 
>>> Don't forget that this makes an extra memory access.
>> I will do my question in a simpler way:
>> Using constant parameters (add const keyword in front of an argument) 
>> is beneficial for record types with size > pointer size and for 
>> string types but not for integer and pointer types.
> No, this is not necessarily true. The extra indirect can be also slower.

For string types it will avoid incrementing and decrementing the ref 
count. See the test i did at 
and the code diff at http://www.geocities.com/camara_luiz/coddiff.htm

For record (TPoint) the constant version generate less code. See the 
attached diff.

>> Currently is not beneficial for double types and there's no way to 
>> improve that. So when developing an interface that uses double types 
>> does not matter using const or not. Now and in the future. Right?
> It might matter for the optimizer in other situations.

I am developing an component that heavily uses double types. So for read 
only arguments is better to use constant parameters?

For the record: Int64 has the same behavior as double regarding this issue.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20081116/1daffa26/attachment.htm>

More information about the fpc-devel mailing list