O3: Fix mispredicts from non control instructions.
authorMatt Horsnell <Matt.Horsnell@arm.com>
Tue, 18 Jan 2011 22:30:05 +0000 (16:30 -0600)
committerMatt Horsnell <Matt.Horsnell@arm.com>
Tue, 18 Jan 2011 22:30:05 +0000 (16:30 -0600)
The squash inside the fetch unit should not attempt to remove them from the
branch predictor as non-control instructions are not pushed into the predictor.

src/cpu/o3/comm.hh
src/cpu/o3/commit_impl.hh
src/cpu/o3/fetch_impl.hh
src/cpu/o3/iew_impl.hh

index c9fb3319bf1228d02883f24660e48ab08f94ed8e..897807fdb6077ef0980f4b69d953615a666745c9 100644 (file)
@@ -87,6 +87,7 @@ struct DefaultIEWDefaultCommit {
 
     bool squash[Impl::MaxThreads];
     bool branchMispredict[Impl::MaxThreads];
+    DynInstPtr mispredictInst[Impl::MaxThreads];
     bool branchTaken[Impl::MaxThreads];
     Addr mispredPC[Impl::MaxThreads];
     TheISA::PCState pc[Impl::MaxThreads];
@@ -107,6 +108,7 @@ struct IssueStruct {
 /** Struct that defines all backwards communication. */
 template<class Impl>
 struct TimeBufStruct {
+    typedef typename Impl::DynInstPtr DynInstPtr;
     struct decodeComm {
         bool squash;
         bool predIncorrect;
@@ -117,6 +119,7 @@ struct TimeBufStruct {
         // @todo: Might want to package this kind of branch stuff into a single
         // struct as it is used pretty frequently.
         bool branchMispredict;
+        DynInstPtr mispredictInst;
         bool branchTaken;
         Addr mispredPC;
         TheISA::PCState nextPC;
@@ -156,6 +159,7 @@ struct TimeBufStruct {
         bool robSquashing;
 
         bool branchMispredict;
+        DynInstPtr mispredictInst;
         bool branchTaken;
         Addr mispredPC;
         TheISA::PCState pc;
@@ -175,7 +179,6 @@ struct TimeBufStruct {
         InstSeqNum nonSpecSeqNum;
 
         // Hack for now to send back an uncached access to the IEW stage.
-        typedef typename Impl::DynInstPtr DynInstPtr;
         bool uncached;
         DynInstPtr uncachedLoad;
 
index 7f37b5f09e9928cfdabcbdc43b598d1a6a1d18f8..78e9a88481537a4063fdace6ccd15e9edd7806db 100644 (file)
@@ -520,6 +520,7 @@ DefaultCommit<Impl>::squashAll(ThreadID tid)
     toIEW->commitInfo[tid].robSquashing = true;
 
     toIEW->commitInfo[tid].branchMispredict = false;
+    toIEW->commitInfo[tid].mispredictInst = NULL;
 
     toIEW->commitInfo[tid].pc = pc[tid];
 }
@@ -814,7 +815,8 @@ DefaultCommit<Impl>::commit()
 
             toIEW->commitInfo[tid].branchMispredict =
                 fromIEW->branchMispredict[tid];
-
+            toIEW->commitInfo[tid].mispredictInst =
+                fromIEW->mispredictInst[tid];
             toIEW->commitInfo[tid].branchTaken =
                 fromIEW->branchTaken[tid];
 
index 880158dfc6406c7c470aac850091f502c4b18a2c..736a66c64839fa1e445d0acf159198c863bf01fb 100644 (file)
@@ -902,8 +902,14 @@ DefaultFetch<Impl>::checkSignalsAndUpdate(ThreadID tid)
                fromCommit->commitInfo[tid].doneSeqNum,
                tid);
 
-        // Also check if there's a mispredict that happened.
-        if (fromCommit->commitInfo[tid].branchMispredict) {
+        // If it was a branch mispredict on a control instruction, update the
+        // branch predictor with that instruction, otherwise just kill the
+        // invalid state we generated in after sequence number
+        assert(!fromCommit->commitInfo[tid].branchMispredict ||
+                fromCommit->commitInfo[tid].mispredictInst);
+
+        if (fromCommit->commitInfo[tid].branchMispredict &&
+            fromCommit->commitInfo[tid].mispredictInst->isControl()) {
             branchPred.squash(fromCommit->commitInfo[tid].doneSeqNum,
                               fromCommit->commitInfo[tid].pc,
                               fromCommit->commitInfo[tid].branchTaken,
index 3f53b4197068a0d59d912a0cee0454258d9daf08..0d58357fdbc1eadb4a8ab69ddc218c2833d74699 100644 (file)
@@ -456,6 +456,7 @@ DefaultIEW<Impl>::squashDueToBranch(DynInstPtr &inst, ThreadID tid)
     toCommit->squashedSeqNum[tid] = inst->seqNum;
     toCommit->mispredPC[tid] = inst->instAddr();
     toCommit->branchMispredict[tid] = true;
+    toCommit->mispredictInst[tid] = inst;
 
     toCommit->branchTaken[tid] = inst->pcState().branching();
     TheISA::PCState pc = inst->pcState();