Am 31.07.2013 04:46, schrieb Gerhard Scholz:
I tried it now with locals and globals, but with the same results.
Yes, currently there is only a difference if the left side is a call (e.g. a function that returns a record or something like that).
From my common sense thinking, i would have expected something like:

   a[incg ( i )] += 3 ;

translates to

   P := @ a[incg ( i )] ;
   P^ := P^ + 3 ;

Technically it would be simple to change that as the corresponding code is already available for the above mentioned situation, but it would definitely change the semantics if the left side is e.g. an array with a function as index accessor (as the function is then only called once)...

The code generated on i386 for this example:

=== code begin ===

  i := 0;
  arr[i] := arr[i] + 1;
  arr[i] += 1;
  arr[MyInc(i)] += 1;

=== code end ===

will look like this without optimizations:

=== code begin ===

# Temps allocated between ebp-28 and ebp-24
# [15] begin
    pushl    %ebp
    movl    %esp,%ebp
    leal    -28(%esp),%esp
# Var arr located at ebp-20
# Var i located at ebp-24
# [16] i := 0;
    movl    $0,-24(%ebp)
# [17] arr[i] := arr[i] + 1;
    movl    -24(%ebp),%eax
    movl    -20(%ebp,%eax,4),%edx
    addl    $1,%edx
    movl    -24(%ebp),%eax
    movl    %edx,-20(%ebp,%eax,4)
# [18] arr[i] += 1;
    movl    -24(%ebp),%eax
    leal    -20(%ebp,%eax,4),%eax
    movl    %eax,-28(%ebp)
    movl    -28(%ebp),%eax
    movl    (%eax),%edx
    addl    $1,%edx
    movl    -28(%ebp),%eax
    movl    %edx,(%eax)
# [19] arr[MyInc(i)] += 1;
    leal    -24(%ebp),%eax
    call    P$OPTEST_$$_MYINC$LONGINT$$LONGINT
    leal    -20(%ebp,%eax,4),%eax
    movl    %eax,-28(%ebp)
    movl    -28(%ebp),%eax
    movl    (%eax),%eax
    addl    $1,%eax
    movl    -28(%ebp),%edx
    movl    %eax,(%edx)

=== code end ===

and like this with O2:

=== code begin ===

# Temps allocated between esp+24 and esp+28
# [15] begin
    addl    $-28,%esp
# Var arr located at esp+0
# Var i located at esp+20
# [16] i := 0;
    movl    $0,%edx
    movl    %edx,20(%esp)
# [17] arr[i] := arr[i] + 1;
    addl    $1,(%esp,%edx,4)
# [18] arr[i] += 1;
    movl    20(%esp),%eax
    leal    (%esp,%eax,4),%eax
    movl    %eax,24(%esp)
    movl    (%eax),%edx
    addl    $1,%edx
    movl    24(%esp),%eax
    movl    %edx,(%eax)
# [19] arr[MyInc(i)] += 1;
    leal    20(%esp),%eax
    call    P$OPTEST_$$_MYINC$LONGINT$$LONGINT
    leal    (%esp,%eax,4),%eax
    movl    %eax,24(%esp)
    movl    (%eax),%eax
    addl    $1,%eax
    movl    24(%esp),%edx
    movl    %eax,(%edx)

=== code end ===

What bugs me a bit is that temporary variable at 24(%esp), but that might be a result of FPC's current temp var system...

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to