Skip to content

Commit

Permalink
[vm, compiler] Generate smaller far branches on RISC-V.
Browse files Browse the repository at this point in the history
TEST=ci
Change-Id: I860596aafd8b11a36f0c1090759fe22e0beb81ea
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392462
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
  • Loading branch information
rmacnak-google authored and Commit Queue committed Nov 6, 2024
1 parent e66a8a4 commit f972499
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions runtime/vm/compiler/assembler/assembler_riscv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2044,16 +2044,34 @@ void MicroAssembler::EmitBranch(Register rs1,
EmitBType(offset, rs2, rs1, func, BRANCH);
} else if (far_branch_level() == 1) {
intptr_t start = Position();
const intptr_t kFarBranchLength = 8;
EmitBType(kFarBranchLength, rs2, rs1, InvertFunct3(func), BRANCH);
intptr_t kFarBranchLength;
if (Supports(RV_C) && (func == BEQ || func == BNE) &&
((rs1 == ZR && IsCRs1p(rs2)) || (rs2 == ZR && IsCRs1p(rs1)))) {
kFarBranchLength = 6;
Emit16((func == BEQ ? C_BNEZ : C_BEQZ) |
EncodeCRs1p(rs1 == ZR ? rs2 : rs1) |
EncodeCBImm(kFarBranchLength));
} else {
kFarBranchLength = 8;
EmitBType(kFarBranchLength, rs2, rs1, InvertFunct3(func), BRANCH);
}
offset = label->link_j(Position());
EmitJType(offset, ZR, JAL);
intptr_t end = Position();
ASSERT_EQUAL(end - start, kFarBranchLength);
} else {
intptr_t start = Position();
const intptr_t kFarBranchLength = 12;
EmitBType(kFarBranchLength, rs2, rs1, InvertFunct3(func), BRANCH);
intptr_t kFarBranchLength;
if (Supports(RV_C) && (func == BEQ || func == BNE) &&
((rs1 == ZR && IsCRs1p(rs2)) || (rs2 == ZR && IsCRs1p(rs1)))) {
kFarBranchLength = 10;
Emit16((func == BEQ ? C_BNEZ : C_BEQZ) |
EncodeCRs1p(rs1 == ZR ? rs2 : rs1) |
EncodeCBImm(kFarBranchLength));
} else {
kFarBranchLength = 12;
EmitBType(kFarBranchLength, rs2, rs1, InvertFunct3(func), BRANCH);
}
offset = label->link_far(Position());
intx_t lo = ImmLo(offset);
intx_t hi = ImmHi(offset);
Expand Down

0 comments on commit f972499

Please sign in to comment.