Skip to content

Commit 3db7c08

Browse files
Hamlin Lipull[bot]
Hamlin Li
authored andcommitted
8334554: RISC-V: verify & fix perf of string comparison
Reviewed-by: rehn, luhenry, fyang
1 parent 7ccfb66 commit 3db7c08

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp

+16-5
Original file line numberDiff line numberDiff line change
@@ -2326,12 +2326,13 @@ void C2_MacroAssembler::expand_bits_l_v(Register dst, Register src, Register mas
23262326
}
23272327

23282328
void C2_MacroAssembler::element_compare(Register a1, Register a2, Register result, Register cnt, Register tmp1, Register tmp2,
2329-
VectorRegister vr1, VectorRegister vr2, VectorRegister vrs, bool islatin, Label &DONE) {
2329+
VectorRegister vr1, VectorRegister vr2, VectorRegister vrs, bool islatin, Label &DONE,
2330+
Assembler::LMUL lmul) {
23302331
Label loop;
23312332
Assembler::SEW sew = islatin ? Assembler::e8 : Assembler::e16;
23322333

23332334
bind(loop);
2334-
vsetvli(tmp1, cnt, sew, Assembler::m2);
2335+
vsetvli(tmp1, cnt, sew, lmul);
23352336
vlex_v(vr1, a1, sew);
23362337
vlex_v(vr2, a2, sew);
23372338
vmsne_vv(vrs, vr1, vr2);
@@ -2357,7 +2358,7 @@ void C2_MacroAssembler::string_equals_v(Register a1, Register a2, Register resul
23572358

23582359
mv(result, false);
23592360

2360-
element_compare(a1, a2, result, cnt, tmp1, tmp2, v2, v4, v2, true, DONE);
2361+
element_compare(a1, a2, result, cnt, tmp1, tmp2, v2, v4, v2, true, DONE, Assembler::m2);
23612362

23622363
bind(DONE);
23632364
BLOCK_COMMENT("} string_equals_v");
@@ -2410,7 +2411,7 @@ void C2_MacroAssembler::arrays_equals_v(Register a1, Register a2, Register resul
24102411
la(a1, Address(a1, base_offset));
24112412
la(a2, Address(a2, base_offset));
24122413

2413-
element_compare(a1, a2, result, cnt1, tmp1, tmp2, v2, v4, v2, elem_size == 1, DONE);
2414+
element_compare(a1, a2, result, cnt1, tmp1, tmp2, v2, v4, v2, elem_size == 1, DONE, Assembler::m2);
24142415

24152416
bind(DONE);
24162417

@@ -2445,8 +2446,18 @@ void C2_MacroAssembler::string_compare_v(Register str1, Register str2, Register
24452446
mv(cnt2, cnt1);
24462447
bind(L);
24472448

2449+
// We focus on the optimization of small sized string.
2450+
// Please check below document for string size distribution statistics.
2451+
// https://cr.openjdk.org/~shade/density/string-density-report.pdf
24482452
if (str1_isL == str2_isL) { // LL or UU
2449-
element_compare(str1, str2, zr, cnt2, tmp1, tmp2, v2, v4, v2, encLL, DIFFERENCE);
2453+
// Below construction of v regs and lmul is based on test on 2 different boards,
2454+
// vlen == 128 and vlen == 256 respectively.
2455+
if (!encLL && MaxVectorSize == 16) { // UU
2456+
element_compare(str1, str2, zr, cnt2, tmp1, tmp2, v4, v8, v4, encLL, DIFFERENCE, Assembler::m4);
2457+
} else { // UU + MaxVectorSize or LL
2458+
element_compare(str1, str2, zr, cnt2, tmp1, tmp2, v2, v4, v2, encLL, DIFFERENCE, Assembler::m2);
2459+
}
2460+
24502461
j(DONE);
24512462
} else { // LU or UL
24522463
Register strL = encLU ? str1 : str2;

src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
Register tmp1, Register tmp2,
3838
VectorRegister vr1, VectorRegister vr2,
3939
VectorRegister vrs,
40-
bool is_latin, Label& DONE);
40+
bool is_latin, Label& DONE, Assembler::LMUL lmul);
4141

4242
void compress_bits_v(Register dst, Register src, Register mask, bool is_long);
4343
void expand_bits_v(Register dst, Register src, Register mask, bool is_long);

src/hotspot/cpu/riscv/riscv_v.ad

+27-3
Original file line numberDiff line numberDiff line change
@@ -3605,14 +3605,37 @@ instruct varray_equalsC(iRegP_R11 ary1, iRegP_R12 ary2, iRegI_R10 result,
36053605
ins_pipe(pipe_class_memory);
36063606
%}
36073607

3608+
instruct vstring_compareU_128b(iRegP_R11 str1, iRegI_R12 cnt1, iRegP_R13 str2, iRegI_R14 cnt2,
3609+
iRegI_R10 result, vReg_V4 v4, vReg_V5 v5, vReg_V6 v6, vReg_V7 v7,
3610+
vReg_V8 v8, vReg_V9 v9, vReg_V10 v10, vReg_V11 v11,
3611+
iRegP_R28 tmp1, iRegL_R29 tmp2)
3612+
%{
3613+
predicate(UseRVV && ((StrCompNode *)n)->encoding() == StrIntrinsicNode::UU &&
3614+
MaxVectorSize == 16);
3615+
match(Set result (StrComp (Binary str1 cnt1) (Binary str2 cnt2)));
3616+
effect(KILL tmp1, KILL tmp2, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2,
3617+
TEMP v4, TEMP v5, TEMP v6, TEMP v7, TEMP v8, TEMP v9, TEMP v10, TEMP v11);
3618+
3619+
format %{ "String Compare $str1, $cnt1, $str2, $cnt2 -> $result\t#@string_compareU" %}
3620+
ins_encode %{
3621+
// Count is in 8-bit bytes; non-Compact chars are 16 bits.
3622+
__ string_compare_v($str1$$Register, $str2$$Register,
3623+
$cnt1$$Register, $cnt2$$Register, $result$$Register,
3624+
$tmp1$$Register, $tmp2$$Register,
3625+
StrIntrinsicNode::UU);
3626+
%}
3627+
ins_pipe(pipe_class_memory);
3628+
%}
3629+
36083630
instruct vstring_compareU(iRegP_R11 str1, iRegI_R12 cnt1, iRegP_R13 str2, iRegI_R14 cnt2,
36093631
iRegI_R10 result, vReg_V2 v2, vReg_V3 v3, vReg_V4 v4, vReg_V5 v5,
36103632
iRegP_R28 tmp1, iRegL_R29 tmp2)
36113633
%{
3612-
predicate(UseRVV && ((StrCompNode *)n)->encoding() == StrIntrinsicNode::UU);
3634+
predicate(UseRVV && ((StrCompNode *)n)->encoding() == StrIntrinsicNode::UU &&
3635+
MaxVectorSize > 16);
36133636
match(Set result (StrComp (Binary str1 cnt1) (Binary str2 cnt2)));
36143637
effect(KILL tmp1, KILL tmp2, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2,
3615-
TEMP v2, TEMP v3, TEMP v4, TEMP v5);
3638+
TEMP v2, TEMP v3, TEMP v4, TEMP v5);
36163639

36173640
format %{ "String Compare $str1, $cnt1, $str2, $cnt2 -> $result\t#@string_compareU" %}
36183641
ins_encode %{
@@ -3624,14 +3647,15 @@ instruct vstring_compareU(iRegP_R11 str1, iRegI_R12 cnt1, iRegP_R13 str2, iRegI_
36243647
%}
36253648
ins_pipe(pipe_class_memory);
36263649
%}
3650+
36273651
instruct vstring_compareL(iRegP_R11 str1, iRegI_R12 cnt1, iRegP_R13 str2, iRegI_R14 cnt2,
36283652
iRegI_R10 result, vReg_V2 v2, vReg_V3 v3, vReg_V4 v4, vReg_V5 v5,
36293653
iRegP_R28 tmp1, iRegL_R29 tmp2)
36303654
%{
36313655
predicate(UseRVV && ((StrCompNode *)n)->encoding() == StrIntrinsicNode::LL);
36323656
match(Set result (StrComp (Binary str1 cnt1) (Binary str2 cnt2)));
36333657
effect(KILL tmp1, KILL tmp2, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2,
3634-
TEMP v2, TEMP v3, TEMP v4, TEMP v5);
3658+
TEMP v2, TEMP v3, TEMP v4, TEMP v5);
36353659

36363660
format %{ "String Compare $str1, $cnt1, $str2, $cnt2 -> $result\t#@string_compareL" %}
36373661
ins_encode %{

0 commit comments

Comments
 (0)