Status: New
Owner: ----
New issue 2258 by [email protected]: Integer division when operands and
target are integers
http://code.google.com/p/v8/issues/detail?id=2258
I've been trying to optimize image manipulation and I couldn't get V8 to
emit integer division instructions. When using typed arrays, division
causes lots of conversions to and from doubles. Since V8 does range
analysis, it should be possible to emit integer division for at least the
case with non-negative dividends and positive divisors when the target
location is an integer.
I hacked up a quick proof of concept yesterday and got an easy 2x speedup
(for converting a premultiplied alpha image to non-premultiplied alpha).
This puts V8 at the speed of optimized C code and seems like too good an
optimization to pass up. This optimization would also be useful for tools
like emscripten.
Example code that benefits from this optimization:
function undoPremultiplication(image, w, h) {
for (var y = 0, i = 0; y < h; y++) {
for (var x = 0; x < w; x++, i += 4) {
var alpha = image[i + 3];
if (alpha > 0) {
image[i + 0] = image[i + 0] * 0xFF / alpha;
image[i + 1] = image[i + 1] * 0xFF / alpha;
image[i + 2] = image[i + 2] * 0xFF / alpha;
}
}
}
}
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev