multiplies by powers of two

Matthew Fluet mfluet@intertrust.com
Wed, 11 Jul 2001 16:24:00 -0700 (PDT)


> > More  importantly,  and  this is probably only doable if overflow checking is
> > off, the conversion of multiplies to fancy lea instructions is a big big  win
> > on Intel chips.
>
> This reminds me -- I saw in some assembly code that x * 4 was really implemented
> with imul instead of a shift (or lea).  I can do the transformation to a shift
> as a CPS optimization if that would help.  Let me know if you think that's worth
> adding.

There is a peephole optimization to rewrite multiplications and divisions
by powers of two to shifts; but, the essential problem is overflow
detection.  The overflow flag is only set on shifts of one, and then it is
set to 1 iff the msb of the result is different than the bit shifted out.
On shifts of more than one, the overflow bit is undefined.

Henry will probably be able to answer this: will it be faster to mask and
test the to-be-shifted-out bits and then do a shift?