[fpc-pascal] generated assembler

Vincent Snijders vsnijders at quicknet.nl
Fri Sep 22 09:12:08 CEST 2006


Florian Klaempfl schreef:
>>
>>
>> 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.

Aha, that explains why explicit subexpression elimination fails too.

using comon expression, less calculations:
	distance:=sqrt(sqr(dx)+sqr(dy)+sqr(dz));
       	mag := dt / (distance*distance*distance);
but this is faster:
	distance:=sqrt(sqr(dx)+sqr(dy)+sqr(dz));
       	mag := dt / (sqrt(sqr(dx)+sqr(dy)+sqr(dz))*(sqr(dx)+sqr(dy)+sqr(dz)));

using comon expression, less calculations:
       b1mag := b1^.mass * mag;
       b2^.vx := b2^.vx + dx * b1mag;
       b2^.vy := b2^.vy + dy * b1mag;
       b2^.vz := b2^.vz + dz * b1mag;
but this is faster:
       b2^.vx := b2^.vx + dx * b1^.mass * mag;
       b2^.vy := b2^.vy + dy * b1^.mass * mag;
       b2^.vz := b2^.vz + dz * b1^.mass * mag;

Vincent



More information about the fpc-pascal mailing list