[fpc-devel] Generated code of constant parameters of double type
Luiz Americo Pereira Camara
pascalive at bol.com.br
Sun Nov 16 20:28:58 CET 2008
Florian Klaempfl escreveu:
> Luiz Americo Pereira Camara schrieb:
>> 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
>> http://lazarusroad.blogspot.com/2008/11/effect-of-using-constant-parameter-for.html
>> 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.
>
> Please check also the code in the callee ;)
I already checked: is equal.
Luiz
# Temps allocated between ebp+0 and ebp+0
# [33] begin
pushl %ebp
movl %esp,%ebp
call FPC_INITIALIZEUNITS
# [34] x.x := 1;
movl $1,U_P$ASMCONSTPARAMETERREC_X
# [35] x.y := 2;
movl $2,U_P$ASMCONSTPARAMETERREC_X+4
# [36] ByValue(X);
movl $U_P$ASMCONSTPARAMETERREC_X,%eax
call P$ASMCONSTPARAMETERREC_BYVALUE$POINT
# [37] ByReference(X);
movl $U_P$ASMCONSTPARAMETERREC_X,%eax
call P$ASMCONSTPARAMETERREC_BYREFERENCE$POINT
# [38] end.
call FPC_DO_EXIT
leave
ret
More information about the fpc-devel
mailing list