Skip to content

Commit

Permalink
8328138: Optimize ArrayEquals on AArch64
Browse files Browse the repository at this point in the history
  • Loading branch information
weixlu committed Mar 14, 2024
1 parent 357c912 commit 20d3e74
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5296,6 +5296,98 @@ address MacroAssembler::arrays_equals(Register a1, Register a2, Register tmp3,
cbnzw(tmp5, DONE);
}
}
} else if (UseNewCode) {
Label NEXT_64BYTE, NEXT_16BYTE, TAIL_1BYTE, TAIL_2BYTE, TAIL_4BYTE, TAIL_8BYTE;
mov(result, false);
// if (a1 == null || a2 == null)
// return false;
cbz(a1, DONE);
cbz(a2, DONE);
// if (a1.length != a2.length)
// return false;
ldrw(cnt1, Address(a1, length_offset));
ldrw(cnt2, Address(a2, length_offset));
cmpw(cnt2, cnt1);
br(NE, DONE);
// if (a1.length == 0)
// return true;
cbz(cnt1, SAME);
lea(a1, Address(a1, base_offset));
lea(a2, Address(a2, base_offset));

cmpw(cnt1, elem_per_word * 8 * 1); // 1x vector width
br(LT, NEXT_16BYTE);

// 64 byte comparison loop(vector)
bind(NEXT_64BYTE);
cmpw(cnt1, elem_per_word * 8);
br(LT, NEXT_16BYTE);
ld1(v0, v1, v2, v3, T16B, Address(post(a1, wordSize * 8)));
ld1(v4, v5, v6, v7, T16B, Address(post(a2, wordSize * 8)));
sub(cnt1, cnt1, 8 * elem_per_word);
eor(v0, T16B, v0, v4);
eor(v1, T16B, v1, v5);
eor(v2, T16B, v2, v6);
eor(v3, T16B, v3, v7);
orr(v0, T16B, v0, v1);
orr(v0, T16B, v0, v2);
orr(v0, T16B, v0, v3);
umov(tmp1, v0, D, 0);
cbnz(tmp1, DONE);
umov(tmp1, v0, D, 1);
cbnz(tmp1, DONE);
b(NEXT_64BYTE);

// 16 byte comparison loop
bind(NEXT_16BYTE);
cmpw(cnt1, elem_per_word * 2);
br(LT, TAIL_8BYTE);
ldp(tmp1, tmp2, Address(post(a1, wordSize * 2)));
ldp(tmp3, tmp4, Address(post(a2, wordSize * 2)));
sub(cnt1, cnt1, 2 * elem_per_word);
eor(tmp1, tmp1, tmp3);
cbnz(tmp1, DONE);
eor(tmp2, tmp2, tmp4);
cbnz(tmp2, DONE);
b(NEXT_16BYTE);

bind(TAIL_8BYTE);
tbz(cnt1, 3 - log_elem_size, TAIL_4BYTE);
{
ldr(tmp1, Address(post(a1, 8)));
ldr(tmp2, Address(post(a2, 8)));
eor(tmp5, tmp1, tmp2);
cbnz(tmp5, DONE);
}

bind(TAIL_4BYTE);
tbz(cnt1, 2 - log_elem_size, TAIL_2BYTE);
{
ldrw(tmp1, Address(post(a1, 4)));
ldrw(tmp2, Address(post(a2, 4)));
eorw(tmp5, tmp1, tmp2);
cbnzw(tmp5, DONE);
}

bind(TAIL_2BYTE);
tbz(cnt1, 1 - log_elem_size, TAIL_1BYTE);
{
ldrh(tmp3, Address(post(a1, 2)));
ldrh(tmp4, Address(post(a2, 2)));
eorw(tmp5, tmp3, tmp4);
cbnzw(tmp5, DONE);
}

bind(TAIL_1BYTE);
if (elem_size == 1) { // Only needed when comparing byte arrays.
tbz(cnt1, 0, SAME);
{
ldrb(tmp1, a1);
ldrb(tmp2, a2);
eorw(tmp5, tmp1, tmp2);
cbnzw(tmp5, DONE);
}
}
} else {
Label NEXT_DWORD, SHORT, TAIL, TAIL2, STUB,
CSET_EQ, LAST_CHECK;
Expand Down

0 comments on commit 20d3e74

Please sign in to comment.