As it turns out, the answer is yes for left shift, but no for right
shift, at least if y is signed.
For example,
(-100 << 3) == (-100 * 8)
(-100 >> 3) != (-100 / 8)
So in this case the compiler should always be able to work its magic.
If the expression was a /8 though the compiler can't just replace it
because the results are different if y is negative.
Geoff
Vishal Rao wrote:
and the compiler should make it "<<3" anyways, shouldnt it?
On 8/6/05, Arash Partow <[EMAIL PROTECTED]> wrote:
Hi all,
I was wondering if the getbyte macro found in misc.h is as
optimal as it can be...
I propose using a shift-left by 3 instead of an integer
multiply by 8.
original macro:
GETBYTE(x, y) (unsigned int)byte((x)>>(8*(y)))
updated macro:
GETBYTE(x, y) (unsigned int)byte((x)>>(y<<3))
Is there anything wrong with this idea?
Arash Partow
__________________________________________________
Be one who knows what they don't know,
Instead of being one who knows not what they don't know,
Thinking they know everything about all things.
http://www.partow.net