BPred: Fix RAS to handle predicated call/return instructions.
Change RAS to fix issues with predicated call/return instructions. Handled all cases in the life of a predicated call and return instruction.
This commit is contained in:
parent
fd90c3676d
commit
9b05e96b9e
|
@ -1,4 +1,16 @@
|
||||||
/*
|
/*
|
||||||
|
* Copyright (c) 2011 ARM Limited
|
||||||
|
* All rights reserved
|
||||||
|
*
|
||||||
|
* The license below extends only to copyright in the software and shall
|
||||||
|
* not be construed as granting a license to any other intellectual
|
||||||
|
* property including but not limited to intellectual property relating
|
||||||
|
* to a hardware implementation of the functionality of the software
|
||||||
|
* licensed hereunder. You may use the software subject to the license
|
||||||
|
* terms below provided that you ensure that this notice is replicated
|
||||||
|
* unmodified and in its entirety in all distributions of the software,
|
||||||
|
* modified or unmodified, in source code or in binary form.
|
||||||
|
*
|
||||||
* Copyright (c) 2004-2005 The Regents of The University of Michigan
|
* Copyright (c) 2004-2005 The Regents of The University of Michigan
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
|
@ -196,7 +208,7 @@ class BPredUnit
|
||||||
ThreadID _tid)
|
ThreadID _tid)
|
||||||
: seqNum(seq_num), pc(instPC), RASTarget(0), RASIndex(0),
|
: seqNum(seq_num), pc(instPC), RASTarget(0), RASIndex(0),
|
||||||
tid(_tid), predTaken(pred_taken), usedRAS(0),
|
tid(_tid), predTaken(pred_taken), usedRAS(0),
|
||||||
wasCall(0), bpHistory(bp_history)
|
wasCall(0), wasReturn(0), validBTB(0), bpHistory(bp_history)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool operator==(const PredictorHistory &entry) const {
|
bool operator==(const PredictorHistory &entry) const {
|
||||||
|
@ -227,6 +239,10 @@ class BPredUnit
|
||||||
/** Whether or not the instruction was a call. */
|
/** Whether or not the instruction was a call. */
|
||||||
bool wasCall;
|
bool wasCall;
|
||||||
|
|
||||||
|
/** Whether or not the instruction was a return. */
|
||||||
|
bool wasReturn;
|
||||||
|
/** Whether or not the instruction had a valid BTB entry. */
|
||||||
|
bool validBTB;
|
||||||
/** Pointer to the history object passed back from the branch
|
/** Pointer to the history object passed back from the branch
|
||||||
* predictor. It is used to update or restore state of the
|
* predictor. It is used to update or restore state of the
|
||||||
* branch predictor.
|
* branch predictor.
|
||||||
|
|
|
@ -196,7 +196,7 @@ BPredUnit<Impl>::predict(DynInstPtr &inst, TheISA::PCState &pc, ThreadID tid)
|
||||||
if (pred_taken) {
|
if (pred_taken) {
|
||||||
if (inst->isReturn()) {
|
if (inst->isReturn()) {
|
||||||
++usedRAS;
|
++usedRAS;
|
||||||
|
predict_record.wasReturn = true;
|
||||||
// If it's a function return call, then look up the address
|
// If it's a function return call, then look up the address
|
||||||
// in the RAS.
|
// in the RAS.
|
||||||
TheISA::PCState rasTop = RAS[tid].top();
|
TheISA::PCState rasTop = RAS[tid].top();
|
||||||
|
@ -231,6 +231,7 @@ BPredUnit<Impl>::predict(DynInstPtr &inst, TheISA::PCState &pc, ThreadID tid)
|
||||||
|
|
||||||
if (BTB.valid(pc.instAddr(), tid)) {
|
if (BTB.valid(pc.instAddr(), tid)) {
|
||||||
++BTBHits;
|
++BTBHits;
|
||||||
|
predict_record.validBTB = true;
|
||||||
|
|
||||||
// If it's not a return, use the BTB to get the target addr.
|
// If it's not a return, use the BTB to get the target addr.
|
||||||
target = BTB.lookup(pc.instAddr(), tid);
|
target = BTB.lookup(pc.instAddr(), tid);
|
||||||
|
@ -250,12 +251,17 @@ BPredUnit<Impl>::predict(DynInstPtr &inst, TheISA::PCState &pc, ThreadID tid)
|
||||||
DPRINTF(Fetch, "BranchPred: [tid:%i]:[sn:%i] BPBTBUpdate"
|
DPRINTF(Fetch, "BranchPred: [tid:%i]:[sn:%i] BPBTBUpdate"
|
||||||
" called for %s\n",
|
" called for %s\n",
|
||||||
tid, inst->seqNum, inst->pcState());
|
tid, inst->seqNum, inst->pcState());
|
||||||
|
} else if (inst->isCall() && !inst->isUncondCtrl()) {
|
||||||
|
RAS[tid].pop();
|
||||||
}
|
}
|
||||||
TheISA::advancePC(target, inst->staticInst);
|
TheISA::advancePC(target, inst->staticInst);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (inst->isReturn()) {
|
||||||
|
predict_record.wasReturn = true;
|
||||||
|
}
|
||||||
TheISA::advancePC(target, inst->staticInst);
|
TheISA::advancePC(target, inst->staticInst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,10 +308,11 @@ BPredUnit<Impl>::squash(const InstSeqNum &squashed_sn, ThreadID tid)
|
||||||
|
|
||||||
RAS[tid].restore(pred_hist.front().RASIndex,
|
RAS[tid].restore(pred_hist.front().RASIndex,
|
||||||
pred_hist.front().RASTarget);
|
pred_hist.front().RASTarget);
|
||||||
} else if (pred_hist.front().wasCall) {
|
} else if(pred_hist.front().wasCall && pred_hist.front().validBTB) {
|
||||||
DPRINTF(Fetch, "BranchPred: [tid:%i]: Removing speculative entry "
|
// Was a call but predicated false. Pop RAS here
|
||||||
"added to the RAS.\n",tid);
|
DPRINTF(Fetch, "BranchPred: [tid: %i] Squashing"
|
||||||
|
" Call [sn:%i] PC: %s Popping RAS\n", tid,
|
||||||
|
pred_hist.front().seqNum, pred_hist.front().pc);
|
||||||
RAS[tid].pop();
|
RAS[tid].pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,18 +384,46 @@ BPredUnit<Impl>::squash(const InstSeqNum &squashed_sn,
|
||||||
|
|
||||||
BPUpdate((*hist_it).pc, actually_taken,
|
BPUpdate((*hist_it).pc, actually_taken,
|
||||||
pred_hist.front().bpHistory, true);
|
pred_hist.front().bpHistory, true);
|
||||||
if (actually_taken){
|
if (actually_taken) {
|
||||||
|
if (hist_it->wasReturn && !hist_it->usedRAS) {
|
||||||
|
DPRINTF(Fetch, "BranchPred: [tid: %i] Incorrectly predicted"
|
||||||
|
" return [sn:%i] PC: %s\n", tid, hist_it->seqNum,
|
||||||
|
hist_it->pc);
|
||||||
|
RAS[tid].pop();
|
||||||
|
}
|
||||||
DPRINTF(Fetch,"BranchPred: [tid: %i] BTB Update called for [sn:%i]"
|
DPRINTF(Fetch,"BranchPred: [tid: %i] BTB Update called for [sn:%i]"
|
||||||
" PC: %s\n", tid,(*hist_it).seqNum, (*hist_it).pc);
|
" PC: %s\n", tid,hist_it->seqNum, hist_it->pc);
|
||||||
|
|
||||||
|
|
||||||
BTB.update((*hist_it).pc, corrTarget, tid);
|
BTB.update((*hist_it).pc, corrTarget, tid);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
//Actually not Taken
|
||||||
|
if (hist_it->usedRAS) {
|
||||||
|
DPRINTF(Fetch,"BranchPred: [tid: %i] Incorrectly predicted"
|
||||||
|
" return [sn:%i] PC: %s Restoring RAS\n", tid,
|
||||||
|
hist_it->seqNum, hist_it->pc);
|
||||||
|
DPRINTF(Fetch, "BranchPred: [tid:%i]: Restoring top of RAS"
|
||||||
|
" to: %i, target: %s.\n", tid,
|
||||||
|
hist_it->RASIndex, hist_it->RASTarget);
|
||||||
|
RAS[tid].restore(hist_it->RASIndex, hist_it->RASTarget);
|
||||||
|
|
||||||
|
} else if (hist_it->wasCall && hist_it->validBTB) {
|
||||||
|
//Was a Call but predicated false. Pop RAS here
|
||||||
|
DPRINTF(Fetch, "BranchPred: [tid: %i] Incorrectly predicted"
|
||||||
|
" Call [sn:%i] PC: %s Popping RAS\n", tid,
|
||||||
|
hist_it->seqNum, hist_it->pc);
|
||||||
|
RAS[tid].pop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
DPRINTF(Fetch, "BranchPred: [tid:%i]: Removing history for [sn:%i]"
|
DPRINTF(Fetch, "BranchPred: [tid:%i]: Removing history for [sn:%i]"
|
||||||
" PC %s Actually Taken: %i\n", tid, (*hist_it).seqNum,
|
" PC %s Actually Taken: %i\n", tid, hist_it->seqNum,
|
||||||
(*hist_it).pc, actually_taken);
|
hist_it->pc, actually_taken);
|
||||||
|
|
||||||
pred_hist.erase(hist_it);
|
pred_hist.erase(hist_it);
|
||||||
|
|
||||||
DPRINTF(Fetch, "[tid:%i]: predHist.size(): %i\n", tid, predHist[tid].size());
|
DPRINTF(Fetch, "[tid:%i]: predHist.size(): %i\n", tid,
|
||||||
|
predHist[tid].size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1232,6 +1232,10 @@ DefaultCommit<Impl>::commitHead(DynInstPtr &head_inst, unsigned inst_num)
|
||||||
delete head_inst->traceData;
|
delete head_inst->traceData;
|
||||||
head_inst->traceData = NULL;
|
head_inst->traceData = NULL;
|
||||||
}
|
}
|
||||||
|
if (head_inst->isReturn()) {
|
||||||
|
DPRINTF(Commit,"Return Instruction Committed [sn:%lli] PC %s \n",
|
||||||
|
head_inst->seqNum, head_inst->pcState());
|
||||||
|
}
|
||||||
|
|
||||||
// Update the commit rename map
|
// Update the commit rename map
|
||||||
for (int i = 0; i < head_inst->numDestRegs(); i++) {
|
for (int i = 0; i < head_inst->numDestRegs(); i++) {
|
||||||
|
|
|
@ -258,17 +258,28 @@ TournamentBP::update(Addr &branch_addr, bool taken, void *bp_history,
|
||||||
local_predictor_hist = localHistoryTable[local_history_idx];
|
local_predictor_hist = localHistoryTable[local_history_idx];
|
||||||
local_predictor_idx = local_predictor_hist & localPredictorMask;
|
local_predictor_idx = local_predictor_hist & localPredictorMask;
|
||||||
|
|
||||||
// Update the choice predictor to tell it which one was correct if
|
|
||||||
// there was a prediction.
|
|
||||||
if (bp_history) {
|
if (bp_history) {
|
||||||
BPHistory *history = static_cast<BPHistory *>(bp_history);
|
BPHistory *history = static_cast<BPHistory *>(bp_history);
|
||||||
|
// Update may also be called if the Branch target is incorrect even if
|
||||||
|
// the prediction is correct. In that case do not update the counters.
|
||||||
|
bool historyPred = false;
|
||||||
|
unsigned old_local_pred_index = history->localHistory
|
||||||
|
& localPredictorMask;
|
||||||
|
if (history->globalUsed) {
|
||||||
|
historyPred = history->globalPredTaken;
|
||||||
|
} else {
|
||||||
|
historyPred = history->localPredTaken;
|
||||||
|
}
|
||||||
|
if (historyPred != taken || !squashed) {
|
||||||
|
// Update the choice predictor to tell it which one was correct if
|
||||||
|
// there was a prediction.
|
||||||
if (history->localPredTaken != history->globalPredTaken) {
|
if (history->localPredTaken != history->globalPredTaken) {
|
||||||
// If the local prediction matches the actual outcome,
|
// If the local prediction matches the actual outcome,
|
||||||
// decerement the counter. Otherwise increment the
|
// decerement the counter. Otherwise increment the
|
||||||
// counter.
|
// counter.
|
||||||
if (history->localPredTaken == taken) {
|
if (history->localPredTaken == taken) {
|
||||||
choiceCtrs[history->globalHistory].decrement();
|
choiceCtrs[history->globalHistory].decrement();
|
||||||
} else if (history->globalPredTaken == taken){
|
} else if (history->globalPredTaken == taken) {
|
||||||
choiceCtrs[history->globalHistory].increment();
|
choiceCtrs[history->globalHistory].increment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,8 +289,6 @@ TournamentBP::update(Addr &branch_addr, bool taken, void *bp_history,
|
||||||
// resolution of the branch. Global history is updated
|
// resolution of the branch. Global history is updated
|
||||||
// speculatively and restored upon squash() calls, so it does not
|
// speculatively and restored upon squash() calls, so it does not
|
||||||
// need to be updated.
|
// need to be updated.
|
||||||
unsigned old_local_pred_index = history->localHistory
|
|
||||||
& localPredictorMask;
|
|
||||||
if (taken) {
|
if (taken) {
|
||||||
globalCtrs[history->globalHistory].increment();
|
globalCtrs[history->globalHistory].increment();
|
||||||
if (old_local_pred_index != invalidPredictorIndex) {
|
if (old_local_pred_index != invalidPredictorIndex) {
|
||||||
|
@ -291,19 +300,20 @@ TournamentBP::update(Addr &branch_addr, bool taken, void *bp_history,
|
||||||
localCtrs[old_local_pred_index].decrement();
|
localCtrs[old_local_pred_index].decrement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (squashed) {
|
if (squashed) {
|
||||||
if (taken) {
|
if (taken) {
|
||||||
globalHistory = (history->globalHistory << 1) | 1;
|
globalHistory = (history->globalHistory << 1) | 1;
|
||||||
globalHistory = globalHistory & globalHistoryMask;
|
globalHistory = globalHistory & globalHistoryMask;
|
||||||
if (history->localHistory != invalidPredictorIndex)
|
if (old_local_pred_index != invalidPredictorIndex) {
|
||||||
localHistoryTable[local_history_idx] =
|
localHistoryTable[old_local_pred_index] =
|
||||||
(history->localHistory << 1) | 1;
|
(history->localHistory << 1) | 1;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
globalHistory = (history->globalHistory << 1);
|
globalHistory = (history->globalHistory << 1);
|
||||||
globalHistory = globalHistory & globalHistoryMask;
|
globalHistory = globalHistory & globalHistoryMask;
|
||||||
if (history->localHistory != invalidPredictorIndex) {
|
if (old_local_pred_index != invalidPredictorIndex) {
|
||||||
localHistoryTable[local_history_idx] =
|
localHistoryTable[old_local_pred_index] =
|
||||||
history->localHistory << 1;
|
history->localHistory << 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -311,6 +321,7 @@ TournamentBP::update(Addr &branch_addr, bool taken, void *bp_history,
|
||||||
}
|
}
|
||||||
// We're done with this history, now delete it.
|
// We're done with this history, now delete it.
|
||||||
delete history;
|
delete history;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(globalHistory < globalPredictorSize &&
|
assert(globalHistory < globalPredictorSize &&
|
||||||
|
|
Loading…
Reference in a new issue