On Wed, 23 Feb 2022 05:43:10 GMT, Jatin Bhateja <jbhat...@openjdk.org> 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. Sure, will move it to a 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. Sure, will move it to a 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. Sure, will move it to 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. Sure, will move it to 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 ? This is following the existing approach being used for signed DivMod > 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. Will remove it. > 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 Will remove it. ------------- PR: https://git.openjdk.java.net/jdk/pull/7572