Re: [fpc-pascal] Optimisation : X+X or 2*X or X*2 ?
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] ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Optimisation : X+X or 2*X or X*2 ?
On 01/19/2014 09:45 PM, Sven Barth wrote: Can't really comment on floats, but for integers the fasted to multiply by 2 should be a shift left. GCC automatically optimizes this. With the small "embedded" CPUs I usually use, it even converts more most multiplications and divisions with constants to a series of adds and shiftts. -Michael ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Optimisation : X+X or 2*X or X*2 ?
Am 19.01.2014 22:50 schrieb "Nikolay Nikolov" : > > On 01/19/2014 10:45 PM, 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... > > Integer multiplication by a power of 2 constant is converted to a SHL in pass 1, see nadd.pas:2869. Ah, there it is. Thanks. I must have been too tired already when I looked through the code ^^ Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal