Skip to content

Commit

Permalink
fix: instruction considered as a branch when it should not
Browse files Browse the repository at this point in the history
The problem araise form commit da4e67b that create a BPState object
within a BranchFeedBack on initialization. This led to the former
condition to be true way more often than needed.

Co-authored-by: Bryan Perdrizat <[email protected]>
  • Loading branch information
BugraEryilmaz and branylagaffe committed Aug 5, 2024
1 parent 6ac9e56 commit a712e88
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions components/Decoder/Instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,22 @@ ArchInstruction::setWillRaise(eExceptionType aSetting)
void
ArchInstruction::doDispatchEffects()
{
if (bpState() && !isBranch()) {
// Branch predictor identified an instruction that is not a branch as a
// branch.
DBG_(VVerb, (<< *this << " predicted as a branch, but is a non-branch. Fixing"));

boost::intrusive_ptr<BranchFeedback> feedback(new BranchFeedback());
feedback->thePC = pc();
feedback->theActualType = kNonBranch;
feedback->theActualDirection = kNotTaken;
feedback->theActualTarget = VirtualMemoryAddress(0);
feedback->theBPState = bpState();
core()->branchFeedback(feedback);
}
auto bp_state = bpState();

DBG_Assert(bp_state, (<< "No branch predictor state exists, but it must"));
if (bp_state->theActualType == kNonBranch) return;
if (isBranch()) return;

// Branch predictor identified an instruction that is not a branch as a branch.
DBG_(VVerb, (<< *this << " predicted as a branch, but is a non-branch. Fixing"));

boost::intrusive_ptr<BranchFeedback> feedback(new BranchFeedback());
feedback->thePC = pc();
feedback->theActualType = kNonBranch;
feedback->theActualDirection = kNotTaken;
feedback->theActualTarget = VirtualMemoryAddress(0);
feedback->theBPState = bpState();
core()->branchFeedback(feedback);
}

bool
Expand Down Expand Up @@ -204,4 +207,4 @@ decode(Flexus::SharedTypes::FetchedOpcode const& aFetchedOpcode, uint32_t aCPU,
return std::make_pair(ret_val, last_uop);
}

} // namespace nDecoder
} // namespace nDecoder

0 comments on commit a712e88

Please sign in to comment.