Skip to content

Commit 0a151c6

Browse files
committed
8358179: Performance regression in Math.cbrt
Reviewed-by: epeter Backport-of: 38f59f8
1 parent 554e38d commit 0a151c6

File tree

1 file changed

+14
-39
lines changed

1 file changed

+14
-39
lines changed

src/hotspot/cpu/x86/stubGenerator_x86_64_cbrt.cpp

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
//
4747
/******************************************************************************/
4848

49+
/* Represents 0x7FFFFFFFFFFFFFFF double precision in lower 64 bits*/
50+
ATTRIBUTE_ALIGNED(16) static const juint _ABS_MASK[] =
51+
{
52+
4294967295, 2147483647, 0, 0
53+
};
54+
4955
ATTRIBUTE_ALIGNED(4) static const juint _SIG_MASK[] =
5056
{
5157
0, 1032192
@@ -188,10 +194,10 @@ address StubGenerator::generate_libmCbrt() {
188194
StubCodeMark mark(this, stub_id);
189195
address start = __ pc();
190196

191-
Label L_2TAG_PACKET_0_0_1, L_2TAG_PACKET_1_0_1, L_2TAG_PACKET_2_0_1, L_2TAG_PACKET_3_0_1;
192-
Label L_2TAG_PACKET_4_0_1, L_2TAG_PACKET_5_0_1, L_2TAG_PACKET_6_0_1;
197+
Label L_2TAG_PACKET_0_0_1, L_2TAG_PACKET_1_0_1, L_2TAG_PACKET_2_0_1;
193198
Label B1_1, B1_2, B1_4;
194199

200+
address ABS_MASK = (address)_ABS_MASK;
195201
address SIG_MASK = (address)_SIG_MASK;
196202
address EXP_MASK = (address)_EXP_MASK;
197203
address EXP_MSK2 = (address)_EXP_MSK2;
@@ -208,8 +214,12 @@ address StubGenerator::generate_libmCbrt() {
208214
__ enter(); // required for proper stackwalking of RuntimeStub frame
209215

210216
__ bind(B1_1);
211-
__ subq(rsp, 24);
212-
__ movsd(Address(rsp), xmm0);
217+
__ ucomisd(xmm0, ExternalAddress(ZERON), r11 /*rscratch*/);
218+
__ jcc(Assembler::equal, L_2TAG_PACKET_1_0_1); // Branch only if x is +/- zero or NaN
219+
__ movq(xmm1, xmm0);
220+
__ andpd(xmm1, ExternalAddress(ABS_MASK), r11 /*rscratch*/);
221+
__ ucomisd(xmm1, ExternalAddress(INF), r11 /*rscratch*/);
222+
__ jcc(Assembler::equal, B1_4); // Branch only if x is +/- INF
213223

214224
__ bind(B1_2);
215225
__ movq(xmm7, xmm0);
@@ -228,8 +238,6 @@ address StubGenerator::generate_libmCbrt() {
228238
__ andl(rdx, rax);
229239
__ cmpl(rdx, 0);
230240
__ jcc(Assembler::equal, L_2TAG_PACKET_0_0_1); // Branch only if |x| is denormalized
231-
__ cmpl(rdx, 524032);
232-
__ jcc(Assembler::equal, L_2TAG_PACKET_1_0_1); // Branch only if |x| is INF or NaN
233241
__ shrl(rdx, 8);
234242
__ shrq(r9, 8);
235243
__ andpd(xmm2, xmm0);
@@ -297,8 +305,6 @@ address StubGenerator::generate_libmCbrt() {
297305
__ andl(rdx, rax);
298306
__ shrl(rdx, 8);
299307
__ shrq(r9, 8);
300-
__ cmpl(rdx, 0);
301-
__ jcc(Assembler::equal, L_2TAG_PACKET_3_0_1); // Branch only if |x| is zero
302308
__ andpd(xmm2, xmm0);
303309
__ andpd(xmm0, xmm5);
304310
__ orpd(xmm3, xmm2);
@@ -322,41 +328,10 @@ address StubGenerator::generate_libmCbrt() {
322328
__ psllq(xmm7, 52);
323329
__ jmp(L_2TAG_PACKET_2_0_1);
324330

325-
__ bind(L_2TAG_PACKET_3_0_1);
326-
__ cmpq(r9, 0);
327-
__ jcc(Assembler::notEqual, L_2TAG_PACKET_4_0_1); // Branch only if x is negative zero
328-
__ xorpd(xmm0, xmm0);
329-
__ jmp(B1_4);
330-
331-
__ bind(L_2TAG_PACKET_4_0_1);
332-
__ movsd(xmm0, ExternalAddress(ZERON), r11 /*rscratch*/);
333-
__ jmp(B1_4);
334-
335331
__ bind(L_2TAG_PACKET_1_0_1);
336-
__ movl(rax, Address(rsp, 4));
337-
__ movl(rdx, Address(rsp));
338-
__ movl(rcx, rax);
339-
__ andl(rcx, 2147483647);
340-
__ cmpl(rcx, 2146435072);
341-
__ jcc(Assembler::above, L_2TAG_PACKET_5_0_1); // Branch only if |x| is NaN
342-
__ cmpl(rdx, 0);
343-
__ jcc(Assembler::notEqual, L_2TAG_PACKET_5_0_1); // Branch only if |x| is NaN
344-
__ cmpl(rax, 2146435072);
345-
__ jcc(Assembler::notEqual, L_2TAG_PACKET_6_0_1); // Branch only if x is negative INF
346-
__ movsd(xmm0, ExternalAddress(INF), r11 /*rscratch*/);
347-
__ jmp(B1_4);
348-
349-
__ bind(L_2TAG_PACKET_6_0_1);
350-
__ movsd(xmm0, ExternalAddress(NEG_INF), r11 /*rscratch*/);
351-
__ jmp(B1_4);
352-
353-
__ bind(L_2TAG_PACKET_5_0_1);
354-
__ movsd(xmm0, Address(rsp));
355332
__ addsd(xmm0, xmm0);
356-
__ movq(Address(rsp, 8), xmm0);
357333

358334
__ bind(B1_4);
359-
__ addq(rsp, 24);
360335
__ leave(); // required for proper stackwalking of RuntimeStub frame
361336
__ ret(0);
362337

0 commit comments

Comments
 (0)