[fpc-devel] Bit manipulation as optimization in FPC

Daniël Mantione daniel.mantione at freepascal.org
Wed Sep 6 21:57:47 CEST 2006

Op Wed, 6 Sep 2006, schreef ik:

> Hello,
> I wonder if FPC optimize a code such as:
> if a < b then
>  c := d
> else
> c := b;
> as :
> r := b + ((d - b) and -(a < b));
> If so, do you check the type of CPU (because as I understand, some CPU
> will not execute as fast as other CPU's.
> If not, then why, and how would you optimize such code ?

The construction above would be fastest with conditional moves; in the 
above construction the optimal code generation would be:

mov   c,d
cmp   a,b
movge c,b

This would be much faster than any code generated for the construction you 

Free Pascal won't generate the optimal code, but it can already use 
conditional moves and I would expect that the compiler would use it in 
this situation.


More information about the fpc-devel mailing list