8349556: RISC-V: improve the performance when -COH and -AvoidUnalignedAccesses for UL and LU string comparison

Reviewed-by: fyang, vkempik
This commit is contained in:
Hamlin Li 2025-02-10 11:47:57 +00:00
parent 4a83ca1202
commit d104debe51
2 changed files with 6 additions and 17 deletions

View File

@ -1485,10 +1485,10 @@ void C2_MacroAssembler::string_compare(Register str1, Register str2,
add(str1, str1, cnt2);
sub(cnt2, zr, cnt2);
} else if (isLU) { // LU case
lwu(tmp1, Address(str1));
load_long_misaligned(tmp2, Address(str2), tmp3, (base_offset2 % 8) != 0 ? 4 : 8);
mv(t0, STUB_THRESHOLD);
bge(cnt2, t0, STUB);
lwu(tmp1, Address(str1));
load_long_misaligned(tmp2, Address(str2), tmp3, (base_offset2 % 8) != 0 ? 4 : 8);
subi(cnt2, cnt2, 4);
add(str1, str1, cnt2);
sub(cnt1, zr, cnt2);
@ -1499,10 +1499,10 @@ void C2_MacroAssembler::string_compare(Register str1, Register str2,
sub(cnt2, zr, cnt2);
addi(cnt1, cnt1, 4);
} else { // UL case
load_long_misaligned(tmp1, Address(str1), tmp3, (base_offset2 % 8) != 0 ? 4 : 8);
lwu(tmp2, Address(str2));
mv(t0, STUB_THRESHOLD);
bge(cnt2, t0, STUB);
load_long_misaligned(tmp1, Address(str1), tmp3, (base_offset2 % 8) != 0 ? 4 : 8);
lwu(tmp2, Address(str2));
subi(cnt2, cnt2, 4);
slli(t0, cnt2, 1);
sub(cnt1, zr, t0);

View File

@ -2520,24 +2520,13 @@ class StubGenerator: public StubCodeGenerator {
assert((base_offset2 % (UseCompactObjectHeaders ? 4 :
(UseCompressedClassPointers ? 8 : 4))) == 0, "Must be");
// cnt2 == amount of characters left to compare
// Check already loaded first 4 symbols
__ inflate_lo32(tmp3, isLU ? tmp1 : tmp2);
__ mv(isLU ? tmp1 : tmp2, tmp3);
__ addi(str1, str1, isLU ? wordSize / 2 : wordSize);
__ addi(str2, str2, isLU ? wordSize : wordSize / 2);
__ subi(cnt2, cnt2, wordSize / 2); // Already loaded 4 symbols
__ xorr(tmp3, tmp1, tmp2);
__ bnez(tmp3, CALCULATE_DIFFERENCE);
Register strU = isLU ? str2 : str1,
strL = isLU ? str1 : str2,
tmpU = isLU ? tmp2 : tmp1, // where to keep U for comparison
tmpL = isLU ? tmp1 : tmp2; // where to keep L for comparison
if (AvoidUnalignedAccesses && (base_offset1 % 8) == 0) {
// Load another 4 bytes from strL to make sure main loop is 8-byte aligned
if (AvoidUnalignedAccesses && (base_offset1 % 8) != 0) {
// Load 4 bytes from strL to make sure main loop is 8-byte aligned
// cnt2 is >= 68 here, no need to check it for >= 0
__ lwu(tmpL, Address(strL));
__ addi(strL, strL, wordSize / 2);