[fpc-pascal] Optimisation : X+X or 2*X or X*2 ?
Sven Barth
pascaldragon at googlemail.com
Sun Jan 19 21:45:00 CET 2014
On 19.01.2014 20:47, Ched wrote:
> Dear Freepascalers,
>
> The multiplication in floating arthmetic units is usualy know as being
> slower than the addition. So, have I interest to code X+X, 2*X or X*2
> when using reals (mainly double and extended) ?And with integers ?
Can't really comment on floats, but for integers the fasted to multiply
by 2 should be a shift left.
> 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...
Regards,
Sven
More information about the fpc-pascal
mailing list