Skip to content

Commit 1375130

Browse files
feilongjiangRealFYang
authored andcommitted
8305728: RISC-V: Use bexti instruction to do single-bit testing
Reviewed-by: fyang, yzhu
1 parent 4485737 commit 1375130

15 files changed

+86
-74
lines changed

src/hotspot/cpu/riscv/c1_LIRAssembler_riscv.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,7 @@ void LIR_Assembler::check_conflict(ciKlass* exact_klass, intptr_t current_klass,
16331633
__ beqz(t0, next);
16341634

16351635
// already unknown. Nothing to do anymore.
1636-
__ andi(t0, tmp, TypeEntries::type_unknown);
1636+
__ test_bit(t0, tmp, exact_log2(TypeEntries::type_unknown));
16371637
__ bnez(t0, next);
16381638

16391639
if (TypeEntries::is_type_none(current_klass)) {
@@ -1655,7 +1655,7 @@ void LIR_Assembler::check_conflict(ciKlass* exact_klass, intptr_t current_klass,
16551655

16561656
__ ld(tmp, mdo_addr);
16571657
// already unknown. Nothing to do anymore.
1658-
__ andi(t0, tmp, TypeEntries::type_unknown);
1658+
__ test_bit(t0, tmp, exact_log2(TypeEntries::type_unknown));
16591659
__ bnez(t0, next);
16601660
}
16611661

@@ -1710,7 +1710,7 @@ void LIR_Assembler::check_no_conflict(ciKlass* exact_klass, intptr_t current_kla
17101710

17111711
__ ld(tmp, mdo_addr);
17121712
// already unknown. Nothing to do anymore.
1713-
__ andi(t0, tmp, TypeEntries::type_unknown);
1713+
__ test_bit(t0, tmp, exact_log2(TypeEntries::type_unknown));
17141714
__ bnez(t0, next);
17151715

17161716
__ ori(tmp, tmp, TypeEntries::type_unknown);

src/hotspot/cpu/riscv/c1_MacroAssembler_riscv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ int C1_MacroAssembler::lock_object(Register hdr, Register obj, Register disp_hdr
6666
if (DiagnoseSyncOnValueBasedClasses != 0) {
6767
load_klass(hdr, obj);
6868
lwu(hdr, Address(hdr, Klass::access_flags_offset()));
69-
andi(t0, hdr, JVM_ACC_IS_VALUE_BASED_CLASS);
69+
test_bit(t0, hdr, exact_log2(JVM_ACC_IS_VALUE_BASED_CLASS));
7070
bnez(t0, slow_case, true /* is_far */);
7171
}
7272

src/hotspot/cpu/riscv/c1_Runtime1_riscv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ OopMapSet* Runtime1::generate_code_for(StubID id, StubAssembler* sasm) {
803803
Register t = x15;
804804
__ load_klass(t, x10);
805805
__ lwu(t, Address(t, Klass::access_flags_offset()));
806-
__ andi(t0, t, JVM_ACC_HAS_FINALIZER);
806+
__ test_bit(t0, t, exact_log2(JVM_ACC_HAS_FINALIZER));
807807
__ bnez(t0, register_finalizer);
808808
__ ret();
809809

src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ void C2_MacroAssembler::string_equals(Register a1, Register a2,
11591159
Label TAIL03, TAIL01;
11601160

11611161
// 0-7 bytes left.
1162-
andi(t0, cnt1, 4);
1162+
test_bit(t0, cnt1, 2);
11631163
beqz(t0, TAIL03);
11641164
{
11651165
lwu(tmp1, Address(a1, 0));
@@ -1171,7 +1171,7 @@ void C2_MacroAssembler::string_equals(Register a1, Register a2,
11711171

11721172
bind(TAIL03);
11731173
// 0-3 bytes left.
1174-
andi(t0, cnt1, 2);
1174+
test_bit(t0, cnt1, 1);
11751175
beqz(t0, TAIL01);
11761176
{
11771177
lhu(tmp1, Address(a1, 0));
@@ -1184,7 +1184,7 @@ void C2_MacroAssembler::string_equals(Register a1, Register a2,
11841184
bind(TAIL01);
11851185
if (elem_size == 1) { // Only needed when comparing 1-byte elements
11861186
// 0-1 bytes left.
1187-
andi(t0, cnt1, 1);
1187+
test_bit(t0, cnt1, 0);
11881188
beqz(t0, SAME);
11891189
{
11901190
lbu(tmp1, Address(a1, 0));

src/hotspot/cpu/riscv/gc/shenandoah/shenandoahBarrierSetAssembler_riscv.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void ShenandoahBarrierSetAssembler::arraycopy_prologue(MacroAssembler* masm, Dec
6161

6262
__ lbu(t0, gc_state);
6363
if (ShenandoahSATBBarrier && dest_uninitialized) {
64-
__ andi(t0, t0, ShenandoahHeap::HAS_FORWARDED);
64+
__ test_bit(t0, t0, ShenandoahHeap::HAS_FORWARDED_BITPOS);
6565
__ beqz(t0, done);
6666
} else {
6767
__ andi(t0, t0, ShenandoahHeap::HAS_FORWARDED | ShenandoahHeap::MARKING);
@@ -247,13 +247,13 @@ void ShenandoahBarrierSetAssembler::load_reference_barrier(MacroAssembler* masm,
247247

248248
// Check for heap stability
249249
if (is_strong) {
250-
__ andi(t1, t1, ShenandoahHeap::HAS_FORWARDED);
250+
__ test_bit(t1, t1, ShenandoahHeap::HAS_FORWARDED_BITPOS);
251251
__ beqz(t1, heap_stable);
252252
} else {
253253
Label lrb;
254-
__ andi(t0, t1, ShenandoahHeap::WEAK_ROOTS);
254+
__ test_bit(t0, t1, ShenandoahHeap::WEAK_ROOTS_BITPOS);
255255
__ bnez(t0, lrb);
256-
__ andi(t0, t1, ShenandoahHeap::HAS_FORWARDED);
256+
__ test_bit(t0, t1, ShenandoahHeap::HAS_FORWARDED_BITPOS);
257257
__ beqz(t0, heap_stable);
258258
__ bind(lrb);
259259
}
@@ -277,7 +277,7 @@ void ShenandoahBarrierSetAssembler::load_reference_barrier(MacroAssembler* masm,
277277
__ srli(t0, x10, ShenandoahHeapRegion::region_size_bytes_shift_jint());
278278
__ add(t1, t1, t0);
279279
__ lbu(t1, Address(t1));
280-
__ andi(t0, t1, 1);
280+
__ test_bit(t0, t1, 0);
281281
__ beqz(t0, not_cset);
282282
}
283283

@@ -449,7 +449,7 @@ void ShenandoahBarrierSetAssembler::try_resolve_jobject_in_native(MacroAssembler
449449
__ lbu(t1, gc_state);
450450

451451
// Check for heap in evacuation phase
452-
__ andi(t0, t1, ShenandoahHeap::EVACUATION);
452+
__ test_bit(t0, t1, ShenandoahHeap::EVACUATION_BITPOS);
453453
__ bnez(t0, slowpath);
454454

455455
__ bind(done);
@@ -642,7 +642,7 @@ void ShenandoahBarrierSetAssembler::generate_c1_pre_barrier_runtime_stub(StubAss
642642
// Is marking still active?
643643
Address gc_state(thread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
644644
__ lb(tmp, gc_state);
645-
__ andi(tmp, tmp, ShenandoahHeap::MARKING);
645+
__ test_bit(tmp, tmp, ShenandoahHeap::MARKING_BITPOS);
646646
__ beqz(tmp, done);
647647

648648
// Can we store original value in the thread's buffer?

src/hotspot/cpu/riscv/interp_masm_riscv.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread)
9999
// This method is only called just after the call into the vm in
100100
// call_VM_base, so the arg registers are available.
101101
lwu(t1, Address(xthread, JavaThread::popframe_condition_offset()));
102-
andi(t0, t1, JavaThread::popframe_pending_bit);
102+
test_bit(t0, t1, exact_log2(JavaThread::popframe_pending_bit));
103103
beqz(t0, L);
104-
andi(t0, t1, JavaThread::popframe_processing_bit);
104+
test_bit(t0, t1, exact_log2(JavaThread::popframe_processing_bit));
105105
bnez(t0, L);
106106
// Call Interpreter::remove_activation_preserving_args_entry() to get the
107107
// address of the same-named entrypoint in the generated interpreter code.
@@ -523,7 +523,7 @@ void InterpreterMacroAssembler::dispatch_base(TosState state,
523523
if (needs_thread_local_poll) {
524524
NOT_PRODUCT(block_comment("Thread-local Safepoint poll"));
525525
ld(t1, Address(xthread, JavaThread::polling_word_offset()));
526-
andi(t1, t1, SafepointMechanism::poll_bit());
526+
test_bit(t1, t1, exact_log2(SafepointMechanism::poll_bit()));
527527
bnez(t1, safepoint);
528528
}
529529
if (table == Interpreter::dispatch_table(state)) {
@@ -620,7 +620,7 @@ void InterpreterMacroAssembler::remove_activation(
620620
// get method access flags
621621
ld(x11, Address(fp, frame::interpreter_frame_method_offset * wordSize));
622622
ld(x12, Address(x11, Method::access_flags_offset()));
623-
andi(t0, x12, JVM_ACC_SYNCHRONIZED);
623+
test_bit(t0, x12, exact_log2(JVM_ACC_SYNCHRONIZED));
624624
beqz(t0, unlocked);
625625

626626
// Don't unlock anything if the _do_not_unlock_if_synchronized flag
@@ -805,7 +805,7 @@ void InterpreterMacroAssembler::lock_object(Register lock_reg)
805805
if (DiagnoseSyncOnValueBasedClasses != 0) {
806806
load_klass(tmp, obj_reg);
807807
lwu(tmp, Address(tmp, Klass::access_flags_offset()));
808-
andi(tmp, tmp, JVM_ACC_IS_VALUE_BASED_CLASS);
808+
test_bit(tmp, tmp, exact_log2(JVM_ACC_IS_VALUE_BASED_CLASS));
809809
bnez(tmp, slow_case);
810810
}
811811

@@ -1673,7 +1673,7 @@ void InterpreterMacroAssembler::profile_obj_type(Register obj, const Address& md
16731673
// do. The unknown bit may have been
16741674
// set already but no need to check.
16751675

1676-
andi(t0, obj, TypeEntries::type_unknown);
1676+
test_bit(t0, obj, exact_log2(TypeEntries::type_unknown));
16771677
bnez(t0, next);
16781678
// already unknown. Nothing to do anymore.
16791679

@@ -1941,10 +1941,10 @@ void InterpreterMacroAssembler::get_method_counters(Register method,
19411941
}
19421942

19431943
#ifdef ASSERT
1944-
void InterpreterMacroAssembler::verify_access_flags(Register access_flags, uint32_t flag_bits,
1944+
void InterpreterMacroAssembler::verify_access_flags(Register access_flags, uint32_t flag,
19451945
const char* msg, bool stop_by_hit) {
19461946
Label L;
1947-
andi(t0, access_flags, flag_bits);
1947+
test_bit(t0, access_flags, exact_log2(flag));
19481948
if (stop_by_hit) {
19491949
beqz(t0, L);
19501950
} else {

src/hotspot/cpu/riscv/interp_masm_riscv.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ class InterpreterMacroAssembler: public MacroAssembler {
302302
void load_resolved_indy_entry(Register cache, Register index);
303303

304304
#ifdef ASSERT
305-
void verify_access_flags(Register access_flags, uint32_t flag_bits,
305+
void verify_access_flags(Register access_flags, uint32_t flag,
306306
const char* msg, bool stop_by_hit = true);
307307
void verify_frame_setup();
308308
#endif

src/hotspot/cpu/riscv/jniFastGetField_riscv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ address JNI_FastGetField::generate_fast_get_int_field0(BasicType type) {
8484
Address safepoint_counter_addr(rcounter_addr, 0);
8585
__ lwu(rcounter, safepoint_counter_addr);
8686
// An even value means there are no ongoing safepoint operations
87-
__ andi(t0, rcounter, 1);
87+
__ test_bit(t0, rcounter, 0);
8888
__ bnez(t0, slow);
8989

9090
if (JvmtiExport::can_post_field_access()) {

src/hotspot/cpu/riscv/macroAssembler_riscv.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ void MacroAssembler::resolve_jobject(Register value, Register tmp1, Register tmp
572572

573573
bind(tagged);
574574
// Test for jweak tag.
575-
andi(t0, value, JNIHandles::TypeTag::weak_global);
575+
test_bit(t0, value, exact_log2(JNIHandles::TypeTag::weak_global));
576576
bnez(t0, weak_tagged);
577577

578578
// Resolve global handle
@@ -598,7 +598,7 @@ void MacroAssembler::resolve_global_jobject(Register value, Register tmp1, Regis
598598
#ifdef ASSERT
599599
{
600600
Label valid_global_tag;
601-
andi(t0, value, JNIHandles::TypeTag::global); // Test for global tag.
601+
test_bit(t0, value, exact_log2(JNIHandles::TypeTag::global)); // Test for global tag.
602602
bnez(t0, valid_global_tag);
603603
stop("non global jobject using resolve_global_jobject");
604604
bind(valid_global_tag);
@@ -2418,7 +2418,7 @@ void MacroAssembler::safepoint_poll(Label& slow_path, bool at_return, bool acqui
24182418
if (at_return) {
24192419
bgtu(in_nmethod ? sp : fp, t0, slow_path, true /* is_far */);
24202420
} else {
2421-
andi(t0, t0, SafepointMechanism::poll_bit());
2421+
test_bit(t0, t0, exact_log2(SafepointMechanism::poll_bit()));
24222422
bnez(t0, slow_path, true /* is_far */);
24232423
}
24242424
}
@@ -3669,7 +3669,7 @@ void MacroAssembler::multiply_to_len(Register x, Register xlen, Register y, Regi
36693669
if (AvoidUnalignedAccesses) {
36703670
// Check if x and y are both 8-byte aligned.
36713671
orr(t0, xlen, ylen);
3672-
andi(t0, t0, 0x1);
3672+
test_bit(t0, t0, 0);
36733673
beqz(t0, L_multiply_64_x_64_loop);
36743674

36753675
multiply_32_x_32_loop(x, xstart, x_xstart, y, y_idx, z, carry, product, idx, kdx);
@@ -3910,7 +3910,7 @@ address MacroAssembler::zero_words(Register ptr, Register cnt) {
39103910
bind(around);
39113911
for (int i = zero_words_block_size >> 1; i > 1; i >>= 1) {
39123912
Label l;
3913-
andi(t0, cnt, i);
3913+
test_bit(t0, cnt, exact_log2(i));
39143914
beqz(t0, l);
39153915
for (int j = 0; j < i; j++) {
39163916
sd(zr, Address(ptr, j * wordSize));
@@ -3920,7 +3920,7 @@ address MacroAssembler::zero_words(Register ptr, Register cnt) {
39203920
}
39213921
{
39223922
Label l;
3923-
andi(t0, cnt, 1);
3923+
test_bit(t0, cnt, 0);
39243924
beqz(t0, l);
39253925
sd(zr, Address(ptr, 0));
39263926
bind(l);
@@ -4478,3 +4478,12 @@ void MacroAssembler::rt_call(address dest, Register tmp) {
44784478
});
44794479
}
44804480
}
4481+
4482+
void MacroAssembler::test_bit(Register Rd, Register Rs, uint32_t bit_pos, Register tmp) {
4483+
assert(bit_pos < 64, "invalid bit range");
4484+
if (UseZbs) {
4485+
bexti(Rd, Rs, bit_pos);
4486+
return;
4487+
}
4488+
andi(Rd, Rs, 1UL << bit_pos, tmp);
4489+
}

src/hotspot/cpu/riscv/macroAssembler_riscv.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,9 @@ class MacroAssembler: public Assembler {
12101210
// shift left by shamt and add
12111211
void shadd(Register Rd, Register Rs1, Register Rs2, Register tmp, int shamt);
12121212

1213+
// test single bit in Rs, result is set to Rd
1214+
void test_bit(Register Rd, Register Rs, uint32_t bit_pos, Register tmp = t0);
1215+
12131216
// Here the float instructions with safe deal with some exceptions.
12141217
// e.g. convert from NaN, +Inf, -Inf to int, float, double
12151218
// will trigger exception, we need to deal with these situations

0 commit comments

Comments
 (0)