RFR: 4837946: Faster multiplication and exponentiation of large integers [v38]
Johannes Graham
duke at openjdk.org
Mon Apr 28 00:11:47 UTC 2025
On Sat, 26 Apr 2025 21:48:25 GMT, fabioromano1 <duke at openjdk.org> wrote:
>> This PR optimizes `BigInteger.pow(int)` method. The primary enhancement in `pow()` is not concerned most on execution time, but rather in memory optimization, because the PR implementation does the "shift of the exponent" squaring the result rather than the base, so the base is not squared like in the current implementation, and this permits to save about half of the memory.
>
> fabioromano1 has updated the pull request incrementally with one additional commit since the last revision:
>
> Throw away unsignedIntPow(int, int)
src/java.base/share/classes/java/math/BigInteger.java line 2746:
> 2744: if (exp <= maxExp) {
> 2745: // don't use fp arithmetic if exp <= 3
> 2746: xToExp = exp == 1 ? x :
What about pre-seeding the cache with values for 1, 2 and 3? That would allow unconditionally using fp here (and below)
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24690#discussion_r2062757211
More information about the core-libs-dev
mailing list