multiplies by powers of two

Stephen Weeks MLton@sourcelight.com
Wed, 11 Jul 2001 16:17:18 -0700


> Note  imul  will set the overflow flag correctly.  If it weren't for that, we
> should definitely handle multiply-by-constants using all the  tricks.   Note,
> shift  is  NOT  always  the best way.  You can do a multiply by lots of small
> numbers using the lea instruction.  Gcc goes insane doing this, but it really
> can make a large difference.

I believe I saw this even with code compiled -detect-overflow false.  In any
case, I am in the process of rewriting the basis library code to use integer
arithmetic without overflow detection when possible, so that we will be able to
use these tricks even when compiling -detect-overflow true.  Given that shift is
not always the best way, it seems that this optimization belongs in the codegen.