RFR: 8331907: BigInteger and BigDecimal should use optimized division [v2]
Raffaello Giulietti
rgiulietti at openjdk.org
Fri May 10 13:17:49 UTC 2024
On Fri, 10 May 2024 08:45:32 GMT, Daniel Jeliński <djelinski at openjdk.org> wrote:
>> Replace the custom unsigned divide / remainder functions with the compiler-optimized Long.divideUnsigned / remainderUnsigned.
>>
>> No new tests. Existing tier1-3 tests continue to pass.
>>
>> I added a new set of divide benchmarks. Results in thread.
>>
>> I also removed the BigDecimal.toString benchmarks. They no longer serve their purpose - toString caches the returned value, so we were only benchmarking the cache access time.
>
> Daniel Jeliński has updated the pull request incrementally with one additional commit since the last revision:
>
> Inline variable declaration
src/java.base/share/classes/java/math/MutableBigInteger.java line 1117:
> 1115: rem = (int) Long.remainderUnsigned(dividendEstimate, divisorLong);
> 1116: quotient.value[intLen - xlen] = q;
> 1117: remLong = rem & LONG_MASK;
What about removing one of the `int rem`, renaming `remLong` to `rem` and using it as follows?
long rem = 0;
for (int xlen = intLen; xlen > 0; xlen--) {
long dividendEstimate = (rem << 32) |
(value[offset + intLen - xlen] & LONG_MASK);
int q = (int) Long.divideUnsigned(dividendEstimate, divisorLong);
rem = Long.remainderUnsigned(dividendEstimate, divisorLong);
quotient.value[intLen - xlen] = q;
}
quotient.normalize();
return (int) rem;
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/19134#discussion_r1596734060
More information about the core-libs-dev
mailing list