As your examples suggests, this could happen frequently in Canvas
pixel manipulation. Please do file a bug so we can track it.

Danno


On Tue, Jul 24, 2012 at 9:06 PM, Vyacheslav Egorov <[email protected]>wrote:

> Once type-feedback told hydrogen that division happened to produce
> double value it does not try to revert it to integer division.
>
> The only exception is (quite fragile) MathFloorOfDiv optimization
> performed by HUnaryMathOperation::Canonicalize.
>
> Consider contributing your patch :-)
>
> --
> Vyacheslav Egorov
>
>
> On Tue, Jul 24, 2012 at 8:18 PM, Evan Wallace <[email protected]> wrote:
> > I've been trying to optimize image manipulation and I couldn't get V8 to
> > emit integer division instructions. Does V8 currently emit any integer
> > division instructions? It seems odd that it wouldn't because it does have
> > the capability to emit them (see LDivI). I was going to submit a bug but
> > wanted to check first that this really is the case.
> >
> > 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.
> >
> > 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-users mailing list
> > [email protected]
> > http://groups.google.com/group/v8-users
>
> --
> v8-users mailing list
> [email protected]
> http://groups.google.com/group/v8-users
>

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to