Re:AS3 Bitwise gems - fast integer math
by pmjordan on Sunday May 24, 2009 @12:06PM
(#624431)
I don't do flash, but I was under the impression that there's some kind of compilation going on and ActionScript isn't just interpreted. How on earth does a modern compiler not optimise
to
? I could understand it in a dynamically typed language, where a, and therefore the result, could be non-integer, but ActionScript seems to have static type declarations for variables.
[ Parent
| on HN ]
This isn't even "modern" in compiler terms, it's a simple peephole optimization. (grep through the IR, check for "X / 2^n", replace by "X >> n") To get it right when you have
int a;
int b = 64;
a / b
requires dataflow analysis so you can do constant propagation, copy propagation, and dead code elimination. This is more work to get right, but that's not a very good excuse for not at least doing the peephole optimization.