RFR: 8341470: BigDecimal.stripTrailingZeros() optimization [v18]
fabioromano1
duke at openjdk.org
Fri Oct 4 17:09:37 UTC 2024
On Fri, 4 Oct 2024 16:09:28 GMT, Shaojin Wen <swen at openjdk.org> wrote:
>> fabioromano1 has updated the pull request incrementally with two additional commits since the last revision:
>>
>> - Merge branch 'patchStripTrailingZeros' of https://github.com/fabioromano1/jdk into patchStripTrailingZeros
>> - Added benchmark tests
>
> Expand the length of FIVE_TO_2_TO to 32 and use `& 0x1F` when accessing the array to eliminate bounds checks.
>
> private static final BigInteger[] FIVE_TO_2_TO = new BigInteger[32]; // 30 -> 32
>
>
> private static BigInteger fiveToTwoToThe(int n) {
> if (n >= FIVE_TO_2_TO_LEN) {
> BigInteger pow = FIVE_TO_2_TO[(FIVE_TO_2_TO_LEN - 1) & 0x1F]; // & 0x1F eliminate bounds checks.
> for (int i = FIVE_TO_2_TO_LEN; i <= n; i++)
> FIVE_TO_2_TO[i & 0x1F] = pow = pow.multiply(pow); // & 0x1F eliminate bounds checks.
>
> FIVE_TO_2_TO_LEN = n + 1;
> }
>
> return FIVE_TO_2_TO[n & 0x1F]; // & 0x1F eliminate bounds checks.
> }
@wenshao The method `fiveToTwoToThe(int n)` assumes that the value of `n` is correct, so the bounds checks are left to the caller anyway.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/21323#issuecomment-2394169443
More information about the core-libs-dev
mailing list