RFR: 8282221: x86 intrinsics for divideUnsigned and remainderUnsigned methods in java.lang.Integer and java.lang.Long
Jatin Bhateja
jbhateja at openjdk.java.net
Wed Feb 23 05:56:52 UTC 2022
On Tue, 22 Feb 2022 09:24:47 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.
src/hotspot/cpu/x86/x86_64.ad line 8602:
> 8600: __ jmp(done);
> 8601: __ bind(neg_divisor_fastpath);
> 8602: // Fastpath for divisor < 0:
Move in macro assembly routine.
src/hotspot/cpu/x86/x86_64.ad line 8633:
> 8631: __ jmp(done);
> 8632: __ bind(neg_divisor_fastpath);
> 8633: // Fastpath for divisor < 0:
Move in macro assembly rountine.
src/hotspot/cpu/x86/x86_64.ad line 8722:
> 8720: __ shrl(rax, 31); // quotient
> 8721: __ sarl(tmp, 31);
> 8722: __ andl(tmp, divisor);
Move in macro assembly routine.
src/hotspot/cpu/x86/x86_64.ad line 8763:
> 8761: __ andnq(rax, rax, rdx);
> 8762: __ movq(tmp, rax);
> 8763: __ shrq(rax, 63); // quotient
Move in macro assembly routine.
src/hotspot/cpu/x86/x86_64.ad line 8902:
> 8900: __ subl(tmp_rax, divisor);
> 8901: __ andnl(tmp_rax, tmp_rax, rdx);
> 8902: __ sarl(tmp_rax, 31);
Please move this into a macro assembly routine.
src/hotspot/cpu/x86/x86_64.ad line 8932:
> 8930: // Fastpath when divisor < 0:
> 8931: // remainder = dividend - (((dividend & ~(dividend - divisor)) >> (Long.SIZE - 1)) & divisor)
> 8932: // See Hacker's Delight (2nd ed), section 9.3 which is implemented in java.lang.Long.remainderUnsigned()
Please move it into a macro assembly routine.
src/hotspot/share/opto/compile.cpp line 3499:
> 3497: Node* d = n->find_similar(Op_UDivI);
> 3498: if (d) {
> 3499: // Replace them with a fused unsigned divmod if supported
Can you explain a bit here, why can't this transformation be handled earlier ?
src/hotspot/share/opto/divnode.cpp line 1350:
> 1348: return NULL;
> 1349: }
> 1350:
Please remove Value and Ideal routines if no explicit transforms are being done.
src/hotspot/share/opto/divnode.cpp line 1362:
> 1360: }
> 1361:
> 1362: //=============================================================================
You can remove Ideal routine is not transformation is being done.
test/micro/org/openjdk/bench/java/lang/IntegerDivMod.java line 76:
> 74: return quotients;
> 75: }
> 76:
Return seems redundant here.
test/micro/org/openjdk/bench/java/lang/IntegerDivMod.java line 83:
> 81: }
> 82: return remainders;
> 83: }
Return seems redundant here.
test/micro/org/openjdk/bench/java/lang/LongDivMod.java line 75:
> 73: }
> 74: return quotients;
> 75: }
Do we need to return quotients, since it's a field being explicitly modified.
test/micro/org/openjdk/bench/java/lang/LongDivMod.java line 82:
> 80: remainders[i] = Long.remainderUnsigned(dividends[i], divisors[i]);
> 81: }
> 82: return remainders;
Same as above
-------------
PR: https://git.openjdk.java.net/jdk/pull/7572
More information about the core-libs-dev
mailing list