Skip to content

Commit 170152a

Browse files
DingliZhangRealFYang
authored andcommitted
8305728: RISC-V: Use bexti instruction to do single-bit testing
Reviewed-by: fjiang, fyang Backport-of: 137513025dad06fc08818fa832edb4a487298f81
1 parent cc8f3f9 commit 170152a

15 files changed

+84
-72
lines changed

src/hotspot/cpu/riscv/c1_LIRAssembler_riscv.cpp

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

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

16401640
if (TypeEntries::is_type_none(current_klass)) {
@@ -1656,7 +1656,7 @@ void LIR_Assembler::check_conflict(ciKlass* exact_klass, intptr_t current_klass,
16561656

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

@@ -1711,7 +1711,7 @@ void LIR_Assembler::check_no_conflict(ciKlass* exact_klass, intptr_t current_kla
17111711

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

17171717
__ 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
@@ -910,7 +910,7 @@ OopMapSet* Runtime1::generate_code_for(StubID id, StubAssembler* sasm) {
910910
Register t = x15;
911911
__ load_klass(t, x10);
912912
__ lwu(t, Address(t, Klass::access_flags_offset()));
913-
__ andi(t0, t, JVM_ACC_HAS_FINALIZER);
913+
__ test_bit(t0, t, exact_log2(JVM_ACC_HAS_FINALIZER));
914914
__ bnez(t0, register_finalizer);
915915
__ ret();
916916

src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp

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

11491149
// 0-7 bytes left.
1150-
andi(t0, cnt1, 4);
1150+
test_bit(t0, cnt1, 2);
11511151
beqz(t0, TAIL03);
11521152
{
11531153
lwu(tmp1, Address(a1, 0));
@@ -1159,7 +1159,7 @@ void C2_MacroAssembler::string_equals(Register a1, Register a2,
11591159

11601160
bind(TAIL03);
11611161
// 0-3 bytes left.
1162-
andi(t0, cnt1, 2);
1162+
test_bit(t0, cnt1, 1);
11631163
beqz(t0, TAIL01);
11641164
{
11651165
lhu(tmp1, Address(a1, 0));
@@ -1172,7 +1172,7 @@ void C2_MacroAssembler::string_equals(Register a1, Register a2,
11721172
bind(TAIL01);
11731173
if (elem_size == 1) { // Only needed when comparing 1-byte elements
11741174
// 0-1 bytes left.
1175-
andi(t0, cnt1, 1);
1175+
test_bit(t0, cnt1, 0);
11761176
beqz(t0, SAME);
11771177
{
11781178
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);
@@ -246,13 +246,13 @@ void ShenandoahBarrierSetAssembler::load_reference_barrier(MacroAssembler* masm,
246246

247247
// Check for heap stability
248248
if (is_strong) {
249-
__ andi(t1, t1, ShenandoahHeap::HAS_FORWARDED);
249+
__ test_bit(t1, t1, ShenandoahHeap::HAS_FORWARDED_BITPOS);
250250
__ beqz(t1, heap_stable);
251251
} else {
252252
Label lrb;
253-
__ andi(t0, t1, ShenandoahHeap::WEAK_ROOTS);
253+
__ test_bit(t0, t1, ShenandoahHeap::WEAK_ROOTS_BITPOS);
254254
__ bnez(t0, lrb);
255-
__ andi(t0, t1, ShenandoahHeap::HAS_FORWARDED);
255+
__ test_bit(t0, t1, ShenandoahHeap::HAS_FORWARDED_BITPOS);
256256
__ beqz(t0, heap_stable);
257257
__ bind(lrb);
258258
}
@@ -276,7 +276,7 @@ void ShenandoahBarrierSetAssembler::load_reference_barrier(MacroAssembler* masm,
276276
__ srli(t0, x10, ShenandoahHeapRegion::region_size_bytes_shift_jint());
277277
__ add(t1, t1, t0);
278278
__ lbu(t1, Address(t1));
279-
__ andi(t0, t1, 1);
279+
__ test_bit(t0, t1, 0);
280280
__ beqz(t0, not_cset);
281281
}
282282

@@ -447,7 +447,7 @@ void ShenandoahBarrierSetAssembler::try_resolve_jobject_in_native(MacroAssembler
447447
__ lbu(t1, gc_state);
448448

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

453453
__ bind(done);
@@ -640,7 +640,7 @@ void ShenandoahBarrierSetAssembler::generate_c1_pre_barrier_runtime_stub(StubAss
640640
// Is marking still active?
641641
Address gc_state(thread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
642642
__ lb(tmp, gc_state);
643-
__ andi(tmp, tmp, ShenandoahHeap::MARKING);
643+
__ test_bit(tmp, tmp, ShenandoahHeap::MARKING_BITPOS);
644644
__ beqz(tmp, done);
645645

646646
// 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

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

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

@@ -1927,10 +1927,10 @@ void InterpreterMacroAssembler::get_method_counters(Register method,
19271927
}
19281928

19291929
#ifdef ASSERT
1930-
void InterpreterMacroAssembler::verify_access_flags(Register access_flags, uint32_t flag_bits,
1930+
void InterpreterMacroAssembler::verify_access_flags(Register access_flags, uint32_t flag,
19311931
const char* msg, bool stop_by_hit) {
19321932
Label L;
1933-
andi(t0, access_flags, flag_bits);
1933+
test_bit(t0, access_flags, exact_log2(flag));
19341934
if (stop_by_hit) {
19351935
beqz(t0, L);
19361936
} else {

src/hotspot/cpu/riscv/interp_masm_riscv.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ class InterpreterMacroAssembler: public MacroAssembler {
276276
}
277277

278278
#ifdef ASSERT
279-
void verify_access_flags(Register access_flags, uint32_t flag_bits,
279+
void verify_access_flags(Register access_flags, uint32_t flag,
280280
const char* msg, bool stop_by_hit = true);
281281
void verify_frame_setup();
282282
#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: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ void MacroAssembler::resolve_jobject(Register value, Register thread, Register t
531531
beqz(value, done); // Use NULL as-is.
532532

533533
// Test for jweak tag.
534-
andi(t0, value, JNIHandles::weak_tag_mask);
534+
test_bit(t0, value, exact_log2(JNIHandles::weak_tag_mask));
535535
beqz(t0, not_weak);
536536

537537
// Resolve jweak.
@@ -2351,7 +2351,7 @@ void MacroAssembler::safepoint_poll(Label& slow_path, bool at_return, bool acqui
23512351
if (at_return) {
23522352
bgtu(in_nmethod ? sp : fp, t0, slow_path, true /* is_far */);
23532353
} else {
2354-
andi(t0, t0, SafepointMechanism::poll_bit());
2354+
test_bit(t0, t0, exact_log2(SafepointMechanism::poll_bit()));
23552355
bnez(t0, slow_path, true /* is_far */);
23562356
}
23572357
}
@@ -3823,7 +3823,7 @@ void MacroAssembler::multiply_to_len(Register x, Register xlen, Register y, Regi
38233823
if (AvoidUnalignedAccesses) {
38243824
// Check if x and y are both 8-byte aligned.
38253825
orr(t0, xlen, ylen);
3826-
andi(t0, t0, 0x1);
3826+
test_bit(t0, t0, 0);
38273827
beqz(t0, L_multiply_64_x_64_loop);
38283828

38293829
multiply_32_x_32_loop(x, xstart, x_xstart, y, y_idx, z, carry, product, idx, kdx);
@@ -4064,7 +4064,7 @@ address MacroAssembler::zero_words(Register ptr, Register cnt) {
40644064
bind(around);
40654065
for (int i = zero_words_block_size >> 1; i > 1; i >>= 1) {
40664066
Label l;
4067-
andi(t0, cnt, i);
4067+
test_bit(t0, cnt, exact_log2(i));
40684068
beqz(t0, l);
40694069
for (int j = 0; j < i; j++) {
40704070
sd(zr, Address(ptr, 0));
@@ -4074,7 +4074,7 @@ address MacroAssembler::zero_words(Register ptr, Register cnt) {
40744074
}
40754075
{
40764076
Label l;
4077-
andi(t0, cnt, 1);
4077+
test_bit(t0, cnt, 0);
40784078
beqz(t0, l);
40794079
sd(zr, Address(ptr, 0));
40804080
bind(l);
@@ -4387,3 +4387,12 @@ void MacroAssembler::cmp_l2i(Register dst, Register src1, Register src2, Registe
43874387
neg(dst, dst);
43884388
bind(done);
43894389
}
4390+
4391+
void MacroAssembler::test_bit(Register Rd, Register Rs, uint32_t bit_pos, Register tmp) {
4392+
assert(bit_pos < 64, "invalid bit range");
4393+
if (UseZbs) {
4394+
bexti(Rd, Rs, bit_pos);
4395+
return;
4396+
}
4397+
andi(Rd, Rs, 1UL << bit_pos, tmp);
4398+
}

src/hotspot/cpu/riscv/macroAssembler_riscv.hpp

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

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

0 commit comments

Comments
 (0)