Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
15 changes: 2 additions & 13 deletions src/hotspot/cpu/riscv/stubGenerator_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Member

@RealFYang RealFYang Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find that a similar check is in C2_MacroAssembler::string_compare for the UU/LL cases [1].
Seems more consistent if we move it into the counterpart generate_compare_long_string_same_encoding.

[1] https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp#L1443

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, we should refactor the code a bit to make it more readable.
As it seems just a refactor, so I can do it in another pr, how do you think about it?
At the same time I can also clean the invocation of compare_string_16_bytes_same from generate_compare_long_string_same_encoding, I don't like the implicit registers passing between them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Seems the LL/UU cases are kind of different as they already emit direct 8-byte loads before the stub. So not sure if it's doable to move the check.

// 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);
Expand Down