Lines Matching refs:branch
105 // existing instructions (branch placeholders) in the buffer.
107 for (auto& branch : branches_) {
108 EmitBranch(&branch);
775 LOG(FATAL) << "Unexpected branch condition " << cond;
839 LOG(FATAL) << "Unexpected branch condition " << cond;
1468 void MipsAssembler::Branch::InitShortOrLong(MipsAssembler::Branch::OffsetBits offset_size,
1469 MipsAssembler::Branch::Type short_type,
1470 MipsAssembler::Branch::Type long_type) {
1474 void MipsAssembler::Branch::InitializeType(bool is_call, bool is_r6) {
1503 bool MipsAssembler::Branch::IsNop(BranchCondition condition, Register lhs, Register rhs) {
1515 bool MipsAssembler::Branch::IsUncond(BranchCondition condition, Register lhs, Register rhs) {
1529 MipsAssembler::Branch::Branch(bool is_r6, uint32_t location, uint32_t target)
1539 MipsAssembler::Branch::Branch(bool is_r6,
1590 // Branch condition is always true, make the branch unconditional.
1596 MipsAssembler::Branch::Branch(bool is_r6, uint32_t location, uint32_t target, Register indirect_reg)
1608 MipsAssembler::BranchCondition MipsAssembler::Branch::OppositeCondition(
1644 LOG(FATAL) << "Unexpected branch condition " << cond;
1649 MipsAssembler::Branch::Type MipsAssembler::Branch::GetType() const {
1653 MipsAssembler::BranchCondition MipsAssembler::Branch::GetCondition() const {
1657 Register MipsAssembler::Branch::GetLeftRegister() const {
1661 Register MipsAssembler::Branch::GetRightRegister() const {
1665 uint32_t MipsAssembler::Branch::GetTarget() const {
1669 uint32_t MipsAssembler::Branch::GetLocation() const {
1673 uint32_t MipsAssembler::Branch::GetOldLocation() const {
1677 uint32_t MipsAssembler::Branch::GetLength() const {
1681 uint32_t MipsAssembler::Branch::GetOldLength() const {
1685 uint32_t MipsAssembler::Branch::GetSize() const {
1689 uint32_t MipsAssembler::Branch::GetOldSize() const {
1693 uint32_t MipsAssembler::Branch::GetEndLocation() const {
1697 uint32_t MipsAssembler::Branch::GetOldEndLocation() const {
1701 bool MipsAssembler::Branch::IsLong() const {
1725 bool MipsAssembler::Branch::IsResolved() const {
1729 MipsAssembler::Branch::OffsetBits MipsAssembler::Branch::GetOffsetSize() const {
1737 MipsAssembler::Branch::OffsetBits MipsAssembler::Branch::GetOffsetSizeNeeded(uint32_t location,
1745 // bump up the distance by a value larger than the max byte size of a composite branch.
1760 void MipsAssembler::Branch::Resolve(uint32_t target) {
1764 void MipsAssembler::Branch::Relocate(uint32_t expand_location, uint32_t delta) {
1776 void MipsAssembler::Branch::PromoteToLong() {
1805 uint32_t MipsAssembler::Branch::PromoteIfNeeded(uint32_t max_short_distance) {
1806 // If the branch is still unresolved or already long, nothing to do.
1810 // Promote the short branch to long if the offset size is too small
1835 uint32_t MipsAssembler::Branch::GetOffsetLocation() const {
1839 uint32_t MipsAssembler::Branch::GetOffset() const {
1850 MipsAssembler::Branch* MipsAssembler::GetBranch(uint32_t branch_id) {
1855 const MipsAssembler::Branch* MipsAssembler::GetBranch(uint32_t branch_id) const {
1868 Branch* branch = GetBranch(branch_id);
1869 branch->Resolve(bound_pc);
1871 uint32_t branch_location = branch->GetLocation();
1872 // Extract the location of the previous branch in the list (walking the list backwards;
1873 // the previous branch ID was stored in the space reserved for this branch).
1876 // On to the previous branch in the list...
1881 // branch, if any; it will be used by the branches referring to and following this label).
1885 const Branch* branch = GetBranch(branch_id);
1886 bound_pc -= branch->GetEndLocation();
1895 // Get label location based on the branch preceding it.
1897 const Branch* branch = GetBranch(branch_id);
1898 target += branch->GetEndLocation();
1915 const Branch* branch = GetBranch(last_branch_id_);
1916 if (branch->GetLocation() >= old_position + last_position_adjustment_) {
1919 last_position_adjustment_ += branch->GetSize() - branch->GetOldSize();
1929 // Branch forward (to a following label), distance is unknown.
1930 // The first branch forward will contain 0, serving as the terminator of
1934 // Now make the label object point to this branch
1939 // Reserve space for the branch.
1946 uint32_t target = label->IsBound() ? GetLabelLocation(label) : Branch::kUnresolved;
1953 if (Branch::IsNop(condition, lhs, rhs)) {
1956 uint32_t target = label->IsBound() ? GetLabelLocation(label) : Branch::kUnresolved;
1962 uint32_t target = label->IsBound() ? GetLabelLocation(label) : Branch::kUnresolved;
1972 for (auto& branch : branches_) {
1973 CHECK(branch.IsResolved());
1974 uint32_t delta = branch.PromoteIfNeeded();
1975 // If this branch has been promoted and needs to expand in size,
1979 uint32_t expand_location = branch.GetLocation();
1987 // Account for branch expansion by resizing the code buffer
1992 Branch& last_branch = branches_[branch_count - 1];
1996 // Move the code residing between branch placeholders.
1999 Branch& branch = branches_[--i];
2000 uint32_t size = end - branch.GetOldEndLocation();
2001 buffer_.Move(branch.GetEndLocation(), branch.GetOldEndLocation(), size);
2002 end = branch.GetOldLocation();
2008 const MipsAssembler::Branch::BranchInfo MipsAssembler::Branch::branch_info_[] = {
2010 { 2, 0, 1, MipsAssembler::Branch::kOffset18, 2 }, // kUncondBranch
2011 { 2, 0, 1, MipsAssembler::Branch::kOffset18, 2 }, // kCondBranch
2012 { 5, 2, 0, MipsAssembler::Branch::kOffset16, 0 }, // kCall
2014 { 9, 3, 1, MipsAssembler::Branch::kOffset32, 0 }, // kLongUncondBranch
2015 { 10, 4, 1, MipsAssembler::Branch::kOffset32, 0 }, // kLongCondBranch
2016 { 6, 1, 1, MipsAssembler::Branch::kOffset32, 0 }, // kLongCall
2018 { 1, 0, 1, MipsAssembler::Branch::kOffset28, 2 }, // kR6UncondBranch
2019 { 2, 0, 1, MipsAssembler::Branch::kOffset18, 2 }, // kR6CondBranch
2021 { 2, 0, 0, MipsAssembler::Branch::kOffset21, 2 }, // kR6Call
2023 { 2, 0, 0, MipsAssembler::Branch::kOffset32, 0 }, // kR6LongUncondBranch
2024 { 3, 1, 0, MipsAssembler::Branch::kOffset32, 0 }, // kR6LongCondBranch
2025 { 3, 0, 0, MipsAssembler::Branch::kOffset32, 0 }, // kR6LongCall
2029 void MipsAssembler::EmitBranch(MipsAssembler::Branch* branch) {
2031 overwrite_location_ = branch->GetLocation();
2032 uint32_t offset = branch->GetOffset();
2033 BranchCondition condition = branch->GetCondition();
2034 Register lhs = branch->GetLeftRegister();
2035 Register rhs = branch->GetRightRegister();
2036 switch (branch->GetType()) {
2038 case Branch::kUncondBranch:
2039 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2043 case Branch::kCondBranch:
2044 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2048 case Branch::kCall:
2051 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2058 case Branch::kLongUncondBranch:
2075 // vast majority of code a short PC-relative branch is sufficient.
2079 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2087 case Branch::kLongCondBranch:
2088 // The comment on case 'Branch::kLongUncondBranch' applies here as well.
2089 // Note: the opposite condition branch encodes 8 as the distance, which is equal to the
2092 EmitBcondR2(Branch::OppositeCondition(condition), lhs, rhs, 8);
2095 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2103 case Branch::kLongCall:
2105 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2114 case Branch::kR6UncondBranch:
2115 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2118 case Branch::kR6CondBranch:
2119 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2123 case Branch::kR6Call:
2124 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2130 case Branch::kR6LongUncondBranch:
2132 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2136 case Branch::kR6LongCondBranch:
2137 EmitBcondR6(Branch::OppositeCondition(condition), lhs, rhs, 2);
2139 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2143 case Branch::kR6LongCall:
2145 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2151 CHECK_EQ(overwrite_location_, branch->GetEndLocation());
2152 CHECK_LT(branch->GetSize(), static_cast<uint32_t>(Branch::kMaxBranchSize));
2198 } else if (!Branch::IsNop(kCondLT, rs, rt)) {
2208 } else if (Branch::IsUncond(kCondGE, rs, rt)) {
2220 } else if (!Branch::IsNop(kCondLTU, rs, rt)) {
2230 } else if (Branch::IsUncond(kCondGEU, rs, rt)) {