Commit 900d6b93 authored by Lu Yahan's avatar Lu Yahan Committed by V8 LUCI CQ

[riscv64] Optimize Branch with near label

If a label was binded after Branch in 4096 offst, we should use Branchshort.

Change-Id: I2197e2a18a43627370ed9b67b7ef7d678a2a62a8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2944795
Auto-Submit: Yahan Lu <yahan@iscas.ac.cn>
Commit-Queue: Brice Dobry <brice.dobry@futurewei.com>
Reviewed-by: 's avatarBrice Dobry <brice.dobry@futurewei.com>
Cr-Commit-Position: refs/heads/master@{#75073}
parent 998370fd
This diff is collapsed.
......@@ -130,7 +130,7 @@ void TurboAssembler::LoadRoot(Register destination, RootIndex index,
Condition cond, Register src1,
const Operand& src2) {
Label skip;
Branch(&skip, NegateCondition(cond), src1, src2);
BranchShort(&skip, NegateCondition(cond), src1, src2);
Ld(destination,
MemOperand(kRootRegister, RootRegisterOffsetForRootIndex(index)));
bind(&skip);
......@@ -194,7 +194,7 @@ void MacroAssembler::RecordWriteField(Register object, int offset,
Label ok;
DCHECK(!AreAliased(value, dst, scratch, object));
And(scratch, dst, Operand(kTaggedSize - 1));
Branch(&ok, eq, scratch, Operand(zero_reg));
BranchShort(&ok, eq, scratch, Operand(zero_reg));
ebreak();
bind(&ok);
}
......@@ -2300,28 +2300,28 @@ void TurboAssembler::Clz32(Register rd, Register xx) {
Move(x, xx);
li(n, Operand(32));
srliw(y, x, 16);
Branch(&L0, eq, y, Operand(zero_reg));
BranchShort(&L0, eq, y, Operand(zero_reg));
Move(x, y);
addiw(n, n, -16);
bind(&L0);
srliw(y, x, 8);
Branch(&L1, eq, y, Operand(zero_reg));
BranchShort(&L1, eq, y, Operand(zero_reg));
addiw(n, n, -8);
Move(x, y);
bind(&L1);
srliw(y, x, 4);
Branch(&L2, eq, y, Operand(zero_reg));
BranchShort(&L2, eq, y, Operand(zero_reg));
addiw(n, n, -4);
Move(x, y);
bind(&L2);
srliw(y, x, 2);
Branch(&L3, eq, y, Operand(zero_reg));
BranchShort(&L3, eq, y, Operand(zero_reg));
addiw(n, n, -2);
Move(x, y);
bind(&L3);
srliw(y, x, 1);
subw(rd, n, x);
Branch(&L4, eq, y, Operand(zero_reg));
BranchShort(&L4, eq, y, Operand(zero_reg));
addiw(rd, n, -2);
bind(&L4);
}
......@@ -2349,33 +2349,33 @@ void TurboAssembler::Clz64(Register rd, Register xx) {
Move(x, xx);
li(n, Operand(64));
srli(y, x, 32);
Branch(&L0, eq, y, Operand(zero_reg));
BranchShort(&L0, eq, y, Operand(zero_reg));
addiw(n, n, -32);
Move(x, y);
bind(&L0);
srli(y, x, 16);
Branch(&L1, eq, y, Operand(zero_reg));
BranchShort(&L1, eq, y, Operand(zero_reg));
addiw(n, n, -16);
Move(x, y);
bind(&L1);
srli(y, x, 8);
Branch(&L2, eq, y, Operand(zero_reg));
BranchShort(&L2, eq, y, Operand(zero_reg));
addiw(n, n, -8);
Move(x, y);
bind(&L2);
srli(y, x, 4);
Branch(&L3, eq, y, Operand(zero_reg));
BranchShort(&L3, eq, y, Operand(zero_reg));
addiw(n, n, -4);
Move(x, y);
bind(&L3);
srli(y, x, 2);
Branch(&L4, eq, y, Operand(zero_reg));
BranchShort(&L4, eq, y, Operand(zero_reg));
addiw(n, n, -2);
Move(x, y);
bind(&L4);
srli(y, x, 1);
subw(rd, n, x);
Branch(&L5, eq, y, Operand(zero_reg));
BranchShort(&L5, eq, y, Operand(zero_reg));
addiw(rd, n, -2);
bind(&L5);
}
......
......@@ -1457,7 +1457,7 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
// output (i.e., kScratchReg < output)
if (set_overflow_to_min_i32) {
__ Add32(kScratchReg, i.OutputRegister(), 1);
__ Branch(&done, lt, i.OutputRegister(), Operand(kScratchReg));
__ BranchShort(&done, lt, i.OutputRegister(), Operand(kScratchReg));
__ Move(i.OutputRegister(), kScratchReg);
__ bind(&done);
}
......@@ -1475,7 +1475,7 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
__ Trunc_l_d(i.OutputRegister(), i.InputDoubleRegister(0), result);
if (set_overflow_to_min_i64) {
__ Add64(kScratchReg, i.OutputRegister(), 1);
__ Branch(&done, lt, i.OutputRegister(), Operand(kScratchReg));
__ BranchShort(&done, lt, i.OutputRegister(), Operand(kScratchReg));
__ Move(i.OutputRegister(), kScratchReg);
__ bind(&done);
}
......@@ -2516,7 +2516,7 @@ void CodeGenerator::AssembleConstructFrame() {
__ Ld(kScratchReg, MemOperand(kScratchReg));
__ Add64(kScratchReg, kScratchReg,
Operand(required_slots * kSystemPointerSize));
__ Branch(&done, uge, sp, Operand(kScratchReg));
__ BranchShort(&done, uge, sp, Operand(kScratchReg));
}
__ Call(wasm::WasmCode::kWasmStackOverflow, RelocInfo::WASM_STUB_CALL);
......@@ -2631,7 +2631,7 @@ void CodeGenerator::AssembleReturn(InstructionOperand* additional_pop_count) {
if (parameter_slots > 1) {
Label done;
__ li(kScratchReg, parameter_slots);
__ Branch(&done, ge, t0, Operand(kScratchReg));
__ BranchShort(&done, ge, t0, Operand(kScratchReg));
__ Move(t0, kScratchReg);
__ bind(&done);
}
......
......@@ -161,7 +161,7 @@ void RegExpMacroAssemblerRISCV::Backtrack() {
__ Ld(a0, MemOperand(frame_pointer(), kBacktrackCount));
__ Add64(a0, a0, Operand(1));
__ Sd(a0, MemOperand(frame_pointer(), kBacktrackCount));
__ Branch(&next, ne, a0, Operand(backtrack_limit()));
__ BranchShort(&next, ne, a0, Operand(backtrack_limit()));
// Backtrack limit exceeded.
if (can_fallback()) {
......@@ -213,7 +213,7 @@ void RegExpMacroAssemblerRISCV::CheckCharacterLT(uc16 limit, Label* on_less) {
void RegExpMacroAssemblerRISCV::CheckGreedyLoop(Label* on_equal) {
Label backtrack_non_equal;
__ Lw(a0, MemOperand(backtrack_stackpointer(), 0));
__ Branch(&backtrack_non_equal, ne, current_input_offset(), Operand(a0));
__ BranchShort(&backtrack_non_equal, ne, current_input_offset(), Operand(a0));
__ Add64(backtrack_stackpointer(), backtrack_stackpointer(),
Operand(kIntSize));
__ bind(&backtrack_non_equal);
......@@ -230,7 +230,7 @@ void RegExpMacroAssemblerRISCV::CheckNotBackReferenceIgnoreCase(
// At this point, the capture registers are either both set or both cleared.
// If the capture length is zero, then the capture is either empty or cleared.
// Fall through in both cases.
__ Branch(&fallthrough, eq, a1, Operand(zero_reg));
__ BranchShort(&fallthrough, eq, a1, Operand(zero_reg));
if (read_backward) {
__ Ld(t1, MemOperand(frame_pointer(), kStringStartMinusOne));
......@@ -267,20 +267,20 @@ void RegExpMacroAssemblerRISCV::CheckNotBackReferenceIgnoreCase(
__ Lbu(a4, MemOperand(a2, 0));
__ addi(a2, a2, char_size());
__ Branch(&loop_check, eq, a4, Operand(a3));
__ BranchShort(&loop_check, eq, a4, Operand(a3));
// Mismatch, try case-insensitive match (converting letters to lower-case).
__ Or(a3, a3, Operand(0x20)); // Convert capture character to lower-case.
__ Or(a4, a4, Operand(0x20)); // Also convert input character.
__ Branch(&fail, ne, a4, Operand(a3));
__ BranchShort(&fail, ne, a4, Operand(a3));
__ Sub64(a3, a3, Operand('a'));
__ Branch(&loop_check, Uless_equal, a3, Operand('z' - 'a'));
__ BranchShort(&loop_check, Uless_equal, a3, Operand('z' - 'a'));
// Latin-1: Check for values in range [224,254] but not 247.
__ Sub64(a3, a3, Operand(224 - 'a'));
// Weren't Latin-1 letters.
__ Branch(&fail, Ugreater, a3, Operand(254 - 224));
__ BranchShort(&fail, Ugreater, a3, Operand(254 - 224));
// Check for 247.
__ Branch(&fail, eq, a3, Operand(247 - 224));
__ BranchShort(&fail, eq, a3, Operand(247 - 224));
__ bind(&loop_check);
__ Branch(&loop, lt, a0, Operand(a1));
......@@ -374,7 +374,7 @@ void RegExpMacroAssemblerRISCV::CheckNotBackReference(int start_reg,
// At this point, the capture registers are either both set or both cleared.
// If the capture length is zero, then the capture is either empty or cleared.
// Fall through in both cases.
__ Branch(&fallthrough, eq, a1, Operand(zero_reg));
__ BranchShort(&fallthrough, eq, a1, Operand(zero_reg));
if (read_backward) {
__ Ld(t1, MemOperand(frame_pointer(), kStringStartMinusOne));
......@@ -489,10 +489,10 @@ bool RegExpMacroAssemblerRISCV::CheckSpecialCharacterClass(uc16 type,
if (mode_ == LATIN1) {
// One byte space characters are '\t'..'\r', ' ' and \u00a0.
Label success;
__ Branch(&success, eq, current_character(), Operand(' '));
__ BranchShort(&success, eq, current_character(), Operand(' '));
// Check range 0x09..0x0D.
__ Sub64(a0, current_character(), Operand('\t'));
__ Branch(&success, Uless_equal, a0, Operand('\r' - '\t'));
__ BranchShort(&success, Uless_equal, a0, Operand('\r' - '\t'));
// \u00a0 (NBSP).
BranchOrBacktrack(on_no_match, ne, a0, Operand(0x00A0 - '\t'));
__ bind(&success);
......@@ -564,7 +564,7 @@ bool RegExpMacroAssemblerRISCV::CheckSpecialCharacterClass(uc16 type,
Label done;
if (mode_ != LATIN1) {
// Table is 256 entries, so all Latin1 characters can be tested.
__ Branch(&done, Ugreater, current_character(), Operand('z'));
__ BranchShort(&done, Ugreater, current_character(), Operand('z'));
}
ExternalReference map =
ExternalReference::re_word_character_map(isolate());
......@@ -665,10 +665,10 @@ Handle<HeapObject> RegExpMacroAssemblerRISCV::GetCode(Handle<String> source) {
__ Ld(a0, MemOperand(a0));
__ Sub64(a0, sp, a0);
// Handle it if the stack pointer is already below the stack limit.
__ Branch(&stack_limit_hit, le, a0, Operand(zero_reg));
__ BranchShort(&stack_limit_hit, le, a0, Operand(zero_reg));
// Check if there is room for the variable number of registers above
// the stack limit.
__ Branch(&stack_ok, Ugreater_equal, a0,
__ BranchShort(&stack_ok, Ugreater_equal, a0,
Operand(num_registers_ * kSystemPointerSize));
// Exit with OutOfMemory exception. There is not enough space on the stack
// for our working registers.
......@@ -704,7 +704,7 @@ Handle<HeapObject> RegExpMacroAssemblerRISCV::GetCode(Handle<String> source) {
Label load_char_start_regexp, start_regexp;
// Load newline if index is at start, previous character otherwise.
__ Branch(&load_char_start_regexp, ne, a1, Operand(zero_reg));
__ BranchShort(&load_char_start_regexp, ne, a1, Operand(zero_reg));
__ li(current_character(), Operand('\n'));
__ jmp(&start_regexp);
......@@ -797,7 +797,7 @@ Handle<HeapObject> RegExpMacroAssemblerRISCV::GetCode(Handle<String> source) {
// output registers is reduced by the number of stored captures.
__ Sub64(a1, a1, num_saved_registers_);
// Check whether we have enough room for another set of capture results.
__ Branch(&return_a0, lt, a1, Operand(num_saved_registers_));
__ BranchShort(&return_a0, lt, a1, Operand(num_saved_registers_));
__ Sd(a1, MemOperand(frame_pointer(), kNumOutputRegisters));
// Advance the location for output.
......@@ -814,7 +814,7 @@ Handle<HeapObject> RegExpMacroAssemblerRISCV::GetCode(Handle<String> source) {
__ Branch(&load_char_start_regexp, ne, current_input_offset(),
Operand(s3));
// Offset from the end is zero if we already reached the end.
__ Branch(&exit_label_, eq, current_input_offset(),
__ BranchShort(&exit_label_, eq, current_input_offset(),
Operand(zero_reg));
// Advance current position after a zero-length match.
Label advance;
......@@ -894,7 +894,7 @@ Handle<HeapObject> RegExpMacroAssemblerRISCV::GetCode(Handle<String> source) {
__ MultiPop(regexp_registers);
// If return nullptr, we have failed to grow the stack, and
// must exit with a stack-overflow exception.
__ Branch(&exit_with_exception, eq, a0, Operand(zero_reg));
__ BranchShort(&exit_with_exception, eq, a0, Operand(zero_reg));
// Otherwise use return value as new stack pointer.
__ mv(backtrack_stackpointer(), a0);
// Restore saved registers and continue.
......@@ -976,7 +976,7 @@ void RegExpMacroAssemblerRISCV::PushBacktrack(Label* label) {
} else {
Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_);
Label after_constant;
__ Branch(&after_constant);
__ BranchShort(&after_constant);
int offset = masm_->pc_offset();
int cp_offset = offset + Code::kHeaderSize - kHeapObjectTag;
__ emit(0);
......@@ -1016,7 +1016,7 @@ void RegExpMacroAssemblerRISCV::ReadStackPointerFromRegister(int reg) {
void RegExpMacroAssemblerRISCV::SetCurrentPositionFromEnd(int by) {
Label after_position;
__ Branch(&after_position, ge, current_input_offset(),
__ BranchShort(&after_position, ge, current_input_offset(),
Operand(-by * char_size()));
__ li(current_input_offset(), -by * char_size());
// On RegExp code entry (where this operation is used), the character before
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment