Skip to content

Commit

Permalink
Add population_count for scalar version
Browse files Browse the repository at this point in the history
  • Loading branch information
zifeihan committed Jun 20, 2024
1 parent cd65669 commit 4c829c8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
31 changes: 30 additions & 1 deletion src/hotspot/cpu/riscv/macroAssembler_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3611,6 +3611,35 @@ void MacroAssembler::check_klass_subtype_slow_path(Register sub_klass,
bind(L_fallthrough);
}

void MacroAssembler::population_count(Register dst, Register src,
Register tmp1, Register tmp2) {
if (UsePopCountInstruction) {
cpop(dst, src);
} else {
assert_different_registers(src, tmp1, tmp2);
assert_different_registers(dst, tmp1, tmp2);
Label loop, done;

mv(tmp1, src);
// dst = 0;
// while(tmp1 != 0) {
// dst++;
// tmp1 &= (tmp1 - 1);
// }
mv(dst, zr);
beqz(tmp1, done);
{
bind(loop);
addi(dst, dst, 1);
mv(tmp2, tmp1);
addi(tmp2, tmp2, -1);
andr(tmp1, tmp1, tmp2);
bnez(tmp1, loop);
}
bind(done);
}
}

// Ensure that the inline code and the stub are using the same registers
// as we need to call the stub from inline code when there is a collision
// in the hashed lookup in the secondary supers array.
Expand Down Expand Up @@ -3667,7 +3696,7 @@ bool MacroAssembler::lookup_secondary_supers_table(Register r_sub_klass,
// Get the first array index that can contain super_klass into r_array_index.
if (bit != 0) {
slli(r_array_index, r_bitmap, (Klass::SECONDARY_SUPERS_TABLE_MASK - bit));
cpop(r_array_index, r_array_index);
population_count(r_array_index, r_array_index, t0, tmp1);
} else {
mv(r_array_index, (u1)1);
}
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/cpu/riscv/macroAssembler_riscv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ class MacroAssembler: public Assembler {
Label* L_success,
Label* L_failure);

void population_count(Register dst, Register src, Register tmp1, Register tmp2);

// As above, but with a constant super_klass.
// The result is in Register result, not the condition codes.
bool lookup_secondary_supers_table(Register r_sub_klass,
Expand Down
9 changes: 0 additions & 9 deletions src/hotspot/cpu/riscv/vm_version_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,6 @@ void VM_Version::initialize() {
FLAG_SET_DEFAULT(UsePopCountInstruction, false);
}

if (!UsePopCountInstruction) {
if (UseSecondarySupersTable) {
if (!FLAG_IS_DEFAULT(UseSecondarySupersTable)) {
warning("UseSecondarySupersTable is not supported on this CPU");
}
FLAG_SET_DEFAULT(UseSecondarySupersTable, false);
}
}

if (UseZicboz) {
if (FLAG_IS_DEFAULT(UseBlockZeroing)) {
FLAG_SET_DEFAULT(UseBlockZeroing, true);
Expand Down

0 comments on commit 4c829c8

Please sign in to comment.