Comment #4 on issue 2294 by [email protected]: Apparently incorrect rounding in Uint8ClampedArray implementation in V8
http://code.google.com/p/v8/issues/detail?id=2294

V8 does rounding as floor(x + 0.5) both in run-time code and generated code:

http://code.google.com/codesearch#OAMlx_jo-ck/src/v8/src/objects.cc&l=11597

http://code.google.com/codesearch#OAMlx_jo-ck/src/v8/src/ia32/macro-assembler-ia32.cc&l=128

We could fix the run-time code the same way as JSC did:

inline long int lrint(double flt)
{
    int intgr;
#if CPU(X86)
    __asm {
        fld flt
        fistp intgr
    };
#else
#pragma message("Falling back to casting for lrint(), causes rounding inaccuracy in halfway case.")
    intgr = static_cast<int>flt;
#endif
    return intgr;
}

But the generated code uses fast SSE instructions and replacing them by FPU instructions there would degrade performance. I'll look for an SSE instruction that does the correct rounding.

If I don't find it, I am not sure if it is optimal to fix this issue: we would sacrifice performance in all cases to fix one corner case.

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

Reply via email to