[fpc-pascal] Optimisation : X+X or 2*X or X*2 ?

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Mon Jan 20 11:05:19 CET 2014


Sven Barth wrote:

>> Can the compiler optimise this operation choosing the fastest one -
>> probably depending on the architecture x86, arm, aso.
> 
> It can if someone codes support for it (maybe some code generators 
> already have such simplifications). I thought I've at least seen such 
> code for integers (that exactly converts *2 to a shl), but I can't find 
> it currently...

With the caveat that at least some Pentiums have a limited amount of 
shifting hardware (specifically, of the 2x ALUs in a processor only one 
has a barrel shifter on the output). That might have the effect that 
converting a long run of *2 to <<1 would have the effect of preventing 
work being routed to half of the ALUs.

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]



More information about the fpc-pascal mailing list