RFR: 8282221: x86 intrinsics for divideUnsigned and remainderUnsigned methods in java.lang.Integer and java.lang.Long [v8]

Vladimir Kozlov kvn at openjdk.java.net
Wed Apr 6 00:49:43 UTC 2022


On Tue, 5 Apr 2022 20:26:18 GMT, Vamsi Parasa <duke at openjdk.java.net> wrote:

>> Optimizes the divideUnsigned() and remainderUnsigned() methods in java.lang.Integer and java.lang.Long classes using x86 intrinsics. This change shows 3x improvement for Integer methods and upto 25% improvement for Long. This change also implements the DivMod optimization which fuses division and modulus operations if needed. The DivMod optimization shows 3x improvement for Integer and ~65% improvement for Long.
>
> Vamsi Parasa has updated the pull request incrementally with one additional commit since the last revision:
> 
>   add error msg for jtreg test

I have few comments.

src/hotspot/cpu/x86/assembler_x86.cpp line 12375:

> 12373: }
> 12374: #endif
> 12375: 

Please, place it near `idivq()` so you would not need `#ifdef`.

src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp line 4568:

> 4566:   subl(rdx, divisor);
> 4567:   if (VM_Version::supports_bmi1()) andnl(rax, rdx, rax);
> 4568:   else {

Please, follow our coding stile here and in following methods:

if (VM_Version::supports_bmi1()) {
  andnl(rax, rdx, rax);
} else {

src/hotspot/cpu/x86/x86_64.ad line 8701:

> 8699: %}
> 8700: 
> 8701: instruct udivI_rReg(rax_RegI rax, no_rax_rdx_RegI div, rFlagsReg cr, rdx_RegI rdx)

I suggest to follow the pattern in other `div/mod` instructions: `(rax_RegI rax, rdx_RegI rdx, no_rax_rdx_RegI div, rFlagsReg cr)`

Similar in following new instructions.

test/hotspot/jtreg/compiler/intrinsics/TestIntegerDivMod.java line 55:

> 53:             dividends[i] = rng.nextInt();
> 54:             divisors[i] = rng.nextInt();
> 55:         }

I don't trust RND to generate corner cases.
Please, add cases here and in TestLongDivMod.java for MAX, MIN, 0.

-------------

Changes requested by kvn (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/7572


More information about the core-libs-dev mailing list