Hi,

currently Math.floorMod is implemented as: return x - floorDiv(x, y) * y;

This can be optimized as:

        int mod = x % y;
        // if the signs are different and modulo not zero, adjust result
        if ((mod ^ y) < 0 && mod != 0) {
            mod += y;
        }
        return mod;

While the JIT does a reasonably good job at the current implementation,
this ensures we only do a single integer division and no subsequent
integer multiplications, speeding up execution by ~1.3x in interpreter
(mainly from removing the floorDiv method call overhead) and ~1.1x with
C1 and C2.

Testing: tier1-2, all Math tests run locally, -prof perfasm verification
on the provided microbenchmark.

Thanks!

/Claes

Reply via email to