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.



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.

Luiz
Title: WinMerge File Compare Report
C:\temp\byvaluerec.txt C:\temp\byrefrec.txt
.section .text.n_p$asmconstparameterrec_byvalue$point  .section .text.n_p$asmconstparameterrec_byreference$point 
   .balign 16,0x90    .balign 16,0x90
.globl  P$ASMCONSTPARAMETERREC_BYVALUE$POINT  .globl  P$ASMCONSTPARAMETERREC_BYREFERENCE$POINT 
P$ASMCONSTPARAMETERREC_BYVALUE$POINT:  P$ASMCONSTPARAMETERREC_BYREFERENCE$POINT: 
# Temps allocated between ebp-20 and ebp-12 # Temps allocated between ebp-12 and ebp-12
# [17] begin # [25] begin
   pushl   %ebp    pushl   %ebp
   movl    %esp,%ebp    movl    %esp,%ebp
   subl    $20,%esp     subl    $12,%esp 
# Var V located at ebp-4 # Var V located at ebp-4
# Var i located at ebp-12 # Var i located at ebp-12
   movl    %eax,-4(%ebp)    movl    %eax,-4(%ebp)
  # [26] i := V;
   movl    -4(%ebp),%edx    movl    -4(%ebp),%edx
   movl    (%edx),%eax    movl    (%edx),%eax
   movl    %eax,-20(%ebp)  
   movl    4(%edx),%eax  
   movl    %eax,-16(%ebp)  
# [18] i := V;  
   movl    -20(%ebp),%eax  
   movl    %eax,-12(%ebp)    movl    %eax,-12(%ebp)
   movl    -16(%ebp),%eax     movl    4(%edx),%eax 
   movl    %eax,-8(%ebp)    movl    %eax,-8(%ebp)
# [19] DoIt(i); # [27] DoIt(i);
   leal    -12(%ebp),%eax    leal    -12(%ebp),%eax
   call    P$ASMCONSTPARAMETERREC_DOIT$POINT    call    P$ASMCONSTPARAMETERREC_DOIT$POINT
# [20] end; # [28] end;
   leave    leave
   ret    ret
_______________________________________________
fpc-devel maillist  -  [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to