[fpc-pascal] generated assembler

Florian Klaempfl florian at freepascal.org
Fri Sep 22 08:40:44 CEST 2006


Vincent Snijders wrote:
> Hi,
> 
> I am looking at some shootout benchmarks and I have the following
> question. Look at the following program:
> 
> program loop;
> 
> {$mode objfpc}
> 
> var
>   d: array[0..$FFF] of double;
>   di: PDouble;
>   i: integer;
>   c: double;
> 
> begin
>   c := 125;
>   i := low(d);
>   repeat
>     d[i] := c*c;
>     inc(i);
>   until i>high(d);
>   di := @d[low(d)];
>   repeat
>     di^ := c*c;
>     inc(di);
>   until  di>@d[high(d)]
> end.
> 
> I am interested at the way the until clause is generated.
> 
> The compiler creates this assembler file:
> # [15] d[i] := c*c;
>     fldl    U_P$LOOP_C
>     fmul    %st,%st
>     fstpl    U_P$LOOP_D(,%edx,8)
>     fwait
> # [16] inc(i);
>     incl    %edx
> # [17] until i>high(d);
>     cmpl    $4095,%edx
>     jng    .L9
> # [18] di := @d[low(d)];
>     movl    $U_P$LOOP_D,%ecx
>     .balign 4
> .L16:
> # [20] di^ := c*c;
>     fldl    U_P$LOOP_C
>     fmul    %st,%st
>     fstpl    (%ecx)
>     fwait
> # [21] inc(di);
>     addl    $8,%ecx
> # [22] until  di>@d[high(d)]
>     movl    $U_P$LOOP_D+32760,%eax
>     cmpl    %ecx,%eax
>     jnb    .L16
> 
> 
> Line 17 generates two assembler instructions. Line 22 generates three
> assembler instructions. As far as I can see both high(d) and @d[high(d)]
> are constants, because d is a global variable.
> 
> Is it possible that line 22 will generate 2 assembler instructions in
> the future? Or is this a limitation of the i386 assembler? Or do I make
> a mistake in my reasoning?

No, you aren't, however, the problem of this benchmark are the inserted fwaits
which are necessary to get fpu exceptions at correct lines. The best would be to
introduce a switch which prevents the fwaits.

> 
> Vincent
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal




More information about the fpc-pascal mailing list