Skip to content

Commit ed81a47

Browse files
Yudi ZhengTheRealMDoerr
Yudi Zheng
authored andcommittedMay 27, 2024
8327964: Simplify BigInteger.implMultiplyToLen intrinsic
Reviewed-by: mdoerr, amitkumar, kvn, fyang
1 parent 08face8 commit ed81a47

17 files changed

+64
-135
lines changed
 

‎src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -3879,7 +3879,7 @@ void MacroAssembler::multiply_128_x_128_loop(Register y, Register z,
38793879
* r2: y
38803880
* r3: ylen
38813881
* r4: z
3882-
* r5: zlen
3882+
* r5: tmp0
38833883
* r10: tmp1
38843884
* r11: tmp2
38853885
* r12: tmp3
@@ -3890,11 +3890,11 @@ void MacroAssembler::multiply_128_x_128_loop(Register y, Register z,
38903890
*
38913891
*/
38923892
void MacroAssembler::multiply_to_len(Register x, Register xlen, Register y, Register ylen,
3893-
Register z, Register zlen,
3893+
Register z, Register tmp0,
38943894
Register tmp1, Register tmp2, Register tmp3, Register tmp4,
38953895
Register tmp5, Register tmp6, Register product_hi) {
38963896

3897-
assert_different_registers(x, xlen, y, ylen, z, zlen, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6);
3897+
assert_different_registers(x, xlen, y, ylen, z, tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, product_hi);
38983898

38993899
const Register idx = tmp1;
39003900
const Register kdx = tmp2;
@@ -3903,7 +3903,7 @@ void MacroAssembler::multiply_to_len(Register x, Register xlen, Register y, Regi
39033903
const Register y_idx = tmp4;
39043904
const Register carry = tmp5;
39053905
const Register product = xlen;
3906-
const Register x_xstart = zlen; // reuse register
3906+
const Register x_xstart = tmp0;
39073907

39083908
// First Loop.
39093909
//
@@ -3919,9 +3919,9 @@ void MacroAssembler::multiply_to_len(Register x, Register xlen, Register y, Regi
39193919
// z[xstart] = (int)carry;
39203920
//
39213921

3922-
movw(idx, ylen); // idx = ylen;
3923-
movw(kdx, zlen); // kdx = xlen+ylen;
3924-
mov(carry, zr); // carry = 0;
3922+
movw(idx, ylen); // idx = ylen;
3923+
addw(kdx, xlen, ylen); // kdx = xlen+ylen;
3924+
mov(carry, zr); // carry = 0;
39253925

39263926
Label L_done;
39273927

‎src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ class MacroAssembler: public Assembler {
15101510
void ghash_load_wide(int index, Register data, FloatRegister result, FloatRegister state);
15111511
public:
15121512
void multiply_to_len(Register x, Register xlen, Register y, Register ylen, Register z,
1513-
Register zlen, Register tmp1, Register tmp2, Register tmp3,
1513+
Register tmp0, Register tmp1, Register tmp2, Register tmp3,
15141514
Register tmp4, Register tmp5, Register tmp6, Register tmp7);
15151515
void mul_add(Register out, Register in, Register offs, Register len, Register k);
15161516
void ghash_multiply(FloatRegister result_lo, FloatRegister result_hi,

‎src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -4645,7 +4645,6 @@ class StubGenerator: public StubCodeGenerator {
46454645
* c_rarg2 - y address
46464646
* c_rarg3 - y length
46474647
* c_rarg4 - z address
4648-
* c_rarg5 - z length
46494648
*/
46504649
address generate_multiplyToLen() {
46514650
__ align(CodeEntryAlignment);
@@ -4657,8 +4656,8 @@ class StubGenerator: public StubCodeGenerator {
46574656
const Register y = r2;
46584657
const Register ylen = r3;
46594658
const Register z = r4;
4660-
const Register zlen = r5;
46614659

4660+
const Register tmp0 = r5;
46624661
const Register tmp1 = r10;
46634662
const Register tmp2 = r11;
46644663
const Register tmp3 = r12;
@@ -4669,7 +4668,7 @@ class StubGenerator: public StubCodeGenerator {
46694668

46704669
BLOCK_COMMENT("Entry:");
46714670
__ enter(); // required for proper stackwalking of RuntimeStub frame
4672-
__ multiply_to_len(x, xlen, y, ylen, z, zlen, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7);
4671+
__ multiply_to_len(x, xlen, y, ylen, z, tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7);
46734672
__ leave(); // required for proper stackwalking of RuntimeStub frame
46744673
__ ret(lr);
46754674

@@ -4687,10 +4686,10 @@ class StubGenerator: public StubCodeGenerator {
46874686
const Register x = r0;
46884687
const Register xlen = r1;
46894688
const Register z = r2;
4690-
const Register zlen = r3;
46914689
const Register y = r4; // == x
46924690
const Register ylen = r5; // == xlen
46934691

4692+
const Register tmp0 = r3;
46944693
const Register tmp1 = r10;
46954694
const Register tmp2 = r11;
46964695
const Register tmp3 = r12;
@@ -4705,7 +4704,7 @@ class StubGenerator: public StubCodeGenerator {
47054704
__ push(spilled_regs, sp);
47064705
__ mov(y, x);
47074706
__ mov(ylen, xlen);
4708-
__ multiply_to_len(x, xlen, y, ylen, z, zlen, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7);
4707+
__ multiply_to_len(x, xlen, y, ylen, z, tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7);
47094708
__ pop(spilled_regs, sp);
47104709
__ leave();
47114710
__ ret(lr);

‎src/hotspot/cpu/ppc/macroAssembler_ppc.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2012, 2023 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -3898,7 +3898,7 @@ void MacroAssembler::muladd(Register out, Register in,
38983898

38993899
void MacroAssembler::multiply_to_len(Register x, Register xlen,
39003900
Register y, Register ylen,
3901-
Register z, Register zlen,
3901+
Register z,
39023902
Register tmp1, Register tmp2,
39033903
Register tmp3, Register tmp4,
39043904
Register tmp5, Register tmp6,
@@ -3909,11 +3909,11 @@ void MacroAssembler::multiply_to_len(Register x, Register xlen,
39093909

39103910
ShortBranchVerifier sbv(this);
39113911

3912-
assert_different_registers(x, xlen, y, ylen, z, zlen,
3912+
assert_different_registers(x, xlen, y, ylen, z,
39133913
tmp1, tmp2, tmp3, tmp4, tmp5, tmp6);
3914-
assert_different_registers(x, xlen, y, ylen, z, zlen,
3914+
assert_different_registers(x, xlen, y, ylen, z,
39153915
tmp1, tmp2, tmp3, tmp4, tmp5, tmp7);
3916-
assert_different_registers(x, xlen, y, ylen, z, zlen,
3916+
assert_different_registers(x, xlen, y, ylen, z,
39173917
tmp1, tmp2, tmp3, tmp4, tmp5, tmp8);
39183918

39193919
const Register idx = tmp1;
@@ -3941,7 +3941,7 @@ void MacroAssembler::multiply_to_len(Register x, Register xlen,
39413941
// z[xstart] = (int)carry;
39423942

39433943
mr_if_needed(idx, ylen); // idx = ylen
3944-
mr_if_needed(kdx, zlen); // kdx = xlen + ylen
3944+
add(kdx, xlen, ylen); // kdx = xlen + ylen
39453945
li(carry, 0); // carry = 0
39463946

39473947
Label L_done;

‎src/hotspot/cpu/ppc/macroAssembler_ppc.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2012, 2023 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -784,7 +784,7 @@ class MacroAssembler: public Assembler {
784784
Register tmp1, Register tmp2, Register carry);
785785
void multiply_to_len(Register x, Register xlen,
786786
Register y, Register ylen,
787-
Register z, Register zlen,
787+
Register z,
788788
Register tmp1, Register tmp2, Register tmp3, Register tmp4, Register tmp5,
789789
Register tmp6, Register tmp7, Register tmp8, Register tmp9, Register tmp10,
790790
Register tmp11, Register tmp12, Register tmp13);

‎src/hotspot/cpu/ppc/stubGenerator_ppc.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -3204,7 +3204,6 @@ class StubGenerator: public StubCodeGenerator {
32043204
// R5 - y address
32053205
// R6 - y length
32063206
// R7 - z address
3207-
// R8 - z length
32083207
//
32093208
address generate_multiplyToLen() {
32103209

@@ -3217,7 +3216,6 @@ class StubGenerator: public StubCodeGenerator {
32173216
const Register y = R5;
32183217
const Register ylen = R6;
32193218
const Register z = R7;
3220-
const Register zlen = R8;
32213219

32223220
const Register tmp1 = R2; // TOC not used.
32233221
const Register tmp2 = R9;
@@ -3240,7 +3238,6 @@ class StubGenerator: public StubCodeGenerator {
32403238
// C2 does not respect int to long conversion for stub calls.
32413239
__ clrldi(xlen, xlen, 32);
32423240
__ clrldi(ylen, ylen, 32);
3243-
__ clrldi(zlen, zlen, 32);
32443241

32453242
// Save non-volatile regs (frameless).
32463243
int current_offs = 8;
@@ -3253,7 +3250,7 @@ class StubGenerator: public StubCodeGenerator {
32533250
__ std(R30, -current_offs, R1_SP); current_offs += 8;
32543251
__ std(R31, -current_offs, R1_SP);
32553252

3256-
__ multiply_to_len(x, xlen, y, ylen, z, zlen, tmp1, tmp2, tmp3, tmp4, tmp5,
3253+
__ multiply_to_len(x, xlen, y, ylen, z, tmp1, tmp2, tmp3, tmp4, tmp5,
32573254
tmp6, tmp7, tmp8, tmp9, tmp10, tmp11, tmp12, tmp13);
32583255

32593256
// Restore non-volatile regs.

‎src/hotspot/cpu/riscv/macroAssembler_riscv.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -4120,7 +4120,7 @@ void MacroAssembler::multiply_128_x_128_loop(Register y, Register z,
41204120
* x12: y
41214121
* x13: ylen
41224122
* x14: z
4123-
* x15: zlen
4123+
* x15: tmp0
41244124
* x16: tmp1
41254125
* x17: tmp2
41264126
* x7: tmp3
@@ -4130,10 +4130,10 @@ void MacroAssembler::multiply_128_x_128_loop(Register y, Register z,
41304130
* x31: tmp7
41314131
*/
41324132
void MacroAssembler::multiply_to_len(Register x, Register xlen, Register y, Register ylen,
4133-
Register z, Register zlen,
4133+
Register z, Register tmp0,
41344134
Register tmp1, Register tmp2, Register tmp3, Register tmp4,
41354135
Register tmp5, Register tmp6, Register product_hi) {
4136-
assert_different_registers(x, xlen, y, ylen, z, zlen, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6);
4136+
assert_different_registers(x, xlen, y, ylen, z, tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6);
41374137

41384138
const Register idx = tmp1;
41394139
const Register kdx = tmp2;
@@ -4142,11 +4142,11 @@ void MacroAssembler::multiply_to_len(Register x, Register xlen, Register y, Regi
41424142
const Register y_idx = tmp4;
41434143
const Register carry = tmp5;
41444144
const Register product = xlen;
4145-
const Register x_xstart = zlen; // reuse register
4145+
const Register x_xstart = tmp0;
41464146

4147-
mv(idx, ylen); // idx = ylen;
4148-
mv(kdx, zlen); // kdx = xlen+ylen;
4149-
mv(carry, zr); // carry = 0;
4147+
mv(idx, ylen); // idx = ylen;
4148+
addw(kdx, xlen, ylen); // kdx = xlen+ylen;
4149+
mv(carry, zr); // carry = 0;
41504150

41514151
Label L_multiply_64_x_64_loop, L_done;
41524152

‎src/hotspot/cpu/riscv/macroAssembler_riscv.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2014, 2020, Red Hat Inc. All rights reserved.
44
* Copyright (c) 2020, 2023, Huawei Technologies Co., Ltd. All rights reserved.
55
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -1287,7 +1287,7 @@ class MacroAssembler: public Assembler {
12871287
Register tmp, Register tmp3, Register tmp4,
12881288
Register tmp6, Register product_hi);
12891289
void multiply_to_len(Register x, Register xlen, Register y, Register ylen,
1290-
Register z, Register zlen,
1290+
Register z, Register tmp0,
12911291
Register tmp1, Register tmp2, Register tmp3, Register tmp4,
12921292
Register tmp5, Register tmp6, Register product_hi);
12931293
#endif

‎src/hotspot/cpu/riscv/stubGenerator_riscv.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -2840,7 +2840,6 @@ class StubGenerator: public StubCodeGenerator {
28402840
* c_rarg2 - y address
28412841
* c_rarg3 - y length
28422842
* c_rarg4 - z address
2843-
* c_rarg5 - z length
28442843
*/
28452844
address generate_multiplyToLen()
28462845
{
@@ -2853,8 +2852,8 @@ class StubGenerator: public StubCodeGenerator {
28532852
const Register y = x12;
28542853
const Register ylen = x13;
28552854
const Register z = x14;
2856-
const Register zlen = x15;
28572855

2856+
const Register tmp0 = x15;
28582857
const Register tmp1 = x16;
28592858
const Register tmp2 = x17;
28602859
const Register tmp3 = x7;
@@ -2865,7 +2864,7 @@ class StubGenerator: public StubCodeGenerator {
28652864

28662865
BLOCK_COMMENT("Entry:");
28672866
__ enter(); // required for proper stackwalking of RuntimeStub frame
2868-
__ multiply_to_len(x, xlen, y, ylen, z, zlen, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7);
2867+
__ multiply_to_len(x, xlen, y, ylen, z, tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7);
28692868
__ leave(); // required for proper stackwalking of RuntimeStub frame
28702869
__ ret();
28712870

@@ -2881,10 +2880,10 @@ class StubGenerator: public StubCodeGenerator {
28812880
const Register x = x10;
28822881
const Register xlen = x11;
28832882
const Register z = x12;
2884-
const Register zlen = x13;
28852883
const Register y = x14; // == x
28862884
const Register ylen = x15; // == xlen
28872885

2886+
const Register tmp0 = x13; // zlen, unused
28882887
const Register tmp1 = x16;
28892888
const Register tmp2 = x17;
28902889
const Register tmp3 = x7;
@@ -2897,7 +2896,7 @@ class StubGenerator: public StubCodeGenerator {
28972896
__ enter();
28982897
__ mv(y, x);
28992898
__ mv(ylen, xlen);
2900-
__ multiply_to_len(x, xlen, y, ylen, z, zlen, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7);
2899+
__ multiply_to_len(x, xlen, y, ylen, z, tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7);
29012900
__ leave();
29022901
__ ret();
29032902

‎src/hotspot/cpu/s390/macroAssembler_s390.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -5281,9 +5281,6 @@ void MacroAssembler::multiply_to_len(Register x, Register xlen,
52815281

52825282
z_stmg(Z_R7, Z_R13, _z_abi(gpr7), Z_SP);
52835283

5284-
// In openJdk, we store the argument as 32-bit value to slot.
5285-
Address zlen(Z_SP, _z_abi(remaining_cargs)); // Int in long on big endian.
5286-
52875284
const Register idx = tmp1;
52885285
const Register kdx = tmp2;
52895286
const Register xstart = tmp3;
@@ -5308,7 +5305,7 @@ void MacroAssembler::multiply_to_len(Register x, Register xlen,
53085305
//
53095306

53105307
lgr_if_needed(idx, ylen); // idx = ylen
5311-
z_llgf(kdx, zlen); // C2 does not respect int to long conversion for stub calls, thus load zero-extended.
5308+
z_agrk(kdx, xlen, ylen); // kdx = xlen + ylen
53125309
clear_reg(carry); // carry = 0
53135310

53145311
Label L_done;

‎src/hotspot/cpu/s390/stubGenerator_s390.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2016, 2023 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -2981,7 +2981,6 @@ class StubGenerator: public StubCodeGenerator {
29812981
// Z_ARG3 - y address
29822982
// Z_ARG4 - y length
29832983
// Z_ARG5 - z address
2984-
// 160[Z_SP] - z length
29852984
address generate_multiplyToLen() {
29862985
__ align(CodeEntryAlignment);
29872986
StubCodeMark mark(this, "StubRoutines", "multiplyToLen");
@@ -2993,8 +2992,6 @@ class StubGenerator: public StubCodeGenerator {
29932992
const Register y = Z_ARG3;
29942993
const Register ylen = Z_ARG4;
29952994
const Register z = Z_ARG5;
2996-
// zlen is passed on the stack:
2997-
// Address zlen(Z_SP, _z_abi(remaining_cargs));
29982995

29992996
// Next registers will be saved on stack in multiply_to_len().
30002997
const Register tmp1 = Z_tmp_1;

0 commit comments

Comments
 (0)
Please sign in to comment.