Eric Yale wrote in a message to nobody:
EY> It is almost always faster to do a shift because of the
EY> fact that that given a n-binary number shifting to the left by
EY> one bit is the same as multiplying by 2.
Not really a convincing argument, I could also say:
``It is almost always faster to do a multiplication because of the fact that
that given a n-binary number multiplying by 2 is the same as shifting to the
left by one bit.'', which is also false.
It depends on the speed of a multiplication vs. the speed of a shift. Your
compiler will know more about the speed of the computer you're compiling to,
give the poor thing a chance to produce fast code by writing obvious and
clear code. It is easy for a compiler to replace ``x*320'' by
``(x<<6)+(x<<8)'' or ``(x+(x<<2))<<6'' -- if the number of shifts is
important. It is much harder to see that ``(x<<6)+(x<<8)'' can be replaced by
``x*320'', even the latter would be faster.
Bye,
Erik
---
---------------
* Origin: WarmelinkE@vertis.nl (2:282/608.60)
|