misc: Updated the RELEASE-NOTES and version number
[gem5.git] / src / cpu / pred / bpred_unit.hh
index 851cdbb78f40a5024a633c06ee27bc7db79a3066..c90d450bc064590beab359888b4e740da32e6b06 100644 (file)
  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Kevin Lim
- *          Korey Sewell
- *          Timothy M. Jones
- *          Nilay Vaish
  */
 
 #ifndef __CPU_PRED_BPRED_UNIT_HH__
@@ -52,6 +47,7 @@
 #include "base/statistics.hh"
 #include "base/types.hh"
 #include "cpu/pred/btb.hh"
+#include "cpu/pred/indirect.hh"
 #include "cpu/pred/ras.hh"
 #include "cpu/inst_seq.hh"
 #include "cpu/static_inst.hh"
@@ -72,12 +68,7 @@ class BPredUnit : public SimObject
      */
     BPredUnit(const Params *p);
 
-    /**
-     * Registers statistics.
-     */
-    void regStats();
-
-    void regProbePoints() M5_ATTR_OVERRIDE;
+    void regProbePoints() override;
 
     /** Perform sanity checks after a drain. */
     void drainSanityCheck() const;
@@ -92,12 +83,9 @@ class BPredUnit : public SimObject
      */
     bool predict(const StaticInstPtr &inst, const InstSeqNum &seqNum,
                  TheISA::PCState &pc, ThreadID tid);
-    bool predictInOrder(const StaticInstPtr &inst, const InstSeqNum &seqNum,
-                        int asid, TheISA::PCState &instPC,
-                        TheISA::PCState &predPC, ThreadID tid);
 
     // @todo: Rename this function.
-    virtual void uncondBranch(void * &bp_history) = 0;
+    virtual void uncondBranch(ThreadID tid, Addr pc, void * &bp_history) = 0;
 
     /**
      * Tells the branch predictor to commit any updates until the given
@@ -132,7 +120,7 @@ class BPredUnit : public SimObject
      * @param bp_history Pointer to the history object.  The predictor
      * will need to update any state and delete the object.
      */
-    virtual void squash(void *bp_history) = 0;
+    virtual void squash(ThreadID tid, void *bp_history) = 0;
 
     /**
      * Looks up a given PC in the BP to see if it is taken or not taken.
@@ -141,7 +129,7 @@ class BPredUnit : public SimObject
      * has the branch predictor state associated with the lookup.
      * @return Whether the branch is taken or not taken.
      */
-    virtual bool lookup(Addr instPC, void * &bp_history) = 0;
+    virtual bool lookup(ThreadID tid, Addr instPC, void * &bp_history) = 0;
 
      /**
      * If a branch is not taken, because the BTB address is invalid or missing,
@@ -151,7 +139,7 @@ class BPredUnit : public SimObject
      * @param bp_history Pointer that will be set to an object that
      * has the branch predictor state associated with the lookup.
      */
-    virtual void btbUpdate(Addr instPC, void * &bp_history) = 0;
+    virtual void btbUpdate(ThreadID tid, Addr instPC, void * &bp_history) = 0;
 
     /**
      * Looks up a given PC in the BTB to see if a matching entry exists.
@@ -177,18 +165,14 @@ class BPredUnit : public SimObject
      * associated with the branch lookup that is being updated.
      * @param squashed Set to true when this function is called during a
      * squash operation.
+     * @param inst Static instruction information
+     * @param corrTarget The resolved target of the branch (only needed
+     * for squashed branches)
      * @todo Make this update flexible enough to handle a global predictor.
      */
-    virtual void update(Addr instPC, bool taken, void *bp_history,
-                        bool squashed) = 0;
-     /**
-     * Deletes the associated history with a branch, performs no predictor
-     * updates.  Used for branches that mispredict and update tables but
-     * are still speculative and later retire.
-     * @param bp_history History to delete associated with this predictor
-     */
-    virtual void retireSquashed(void *bp_history) = 0;
-
+    virtual void update(ThreadID tid, Addr instPC, bool taken,
+                   void *bp_history, bool squashed,
+                   const StaticInstPtr &inst, Addr corrTarget) = 0;
     /**
      * Updates the BTB with the target of a branch.
      * @param inst_PC The branch's PC that will be updated.
@@ -197,6 +181,7 @@ class BPredUnit : public SimObject
     void BTBUpdate(Addr instPC, const TheISA::PCState &target)
     { BTB.update(instPC, target, 0); }
 
+
     void dump();
 
   private:
@@ -207,10 +192,13 @@ class BPredUnit : public SimObject
          */
         PredictorHistory(const InstSeqNum &seq_num, Addr instPC,
                          bool pred_taken, void *bp_history,
-                         ThreadID _tid)
-            : seqNum(seq_num), pc(instPC), bpHistory(bp_history), RASTarget(0),
-              RASIndex(0), tid(_tid), predTaken(pred_taken), usedRAS(0), pushedRAS(0),
-              wasCall(0), wasReturn(0), wasSquashed(0)
+                         void *indirect_history, ThreadID _tid,
+                         const StaticInstPtr & inst)
+            : seqNum(seq_num), pc(instPC), bpHistory(bp_history),
+              indirectHistory(indirect_history), RASTarget(0), RASIndex(0),
+              tid(_tid), predTaken(pred_taken), usedRAS(0), pushedRAS(0),
+              wasCall(0), wasReturn(0), wasIndirect(0), target(MaxAddr),
+              inst(inst)
         {}
 
         bool operator==(const PredictorHistory &entry) const {
@@ -229,6 +217,8 @@ class BPredUnit : public SimObject
          */
         void *bpHistory;
 
+        void *indirectHistory;
+
         /** The RAS target (only valid if a return). */
         TheISA::PCState RASTarget;
 
@@ -253,14 +243,23 @@ class BPredUnit : public SimObject
         /** Whether or not the instruction was a return. */
         bool wasReturn;
 
-        /** Whether this instruction has already mispredicted/updated bp */
-        bool wasSquashed;
+        /** Wether this instruction was an indirect branch */
+        bool wasIndirect;
+
+        /** Target of the branch. First it is predicted, and fixed later
+         *  if necessary
+         */
+        Addr target;
+
+        /** The branch instrction */
+        const StaticInstPtr inst;
     };
 
     typedef std::deque<PredictorHistory> History;
 
     /** Number of the threads for which the branch history is maintained. */
-    uint32_t numThreads;
+    const unsigned numThreads;
+
 
     /**
      * The per-thread predictor history. This is used to update the predictor
@@ -275,26 +274,43 @@ class BPredUnit : public SimObject
     /** The per-thread return address stack. */
     std::vector<ReturnAddrStack> RAS;
 
-    /** Stat for number of BP lookups. */
-    Stats::Scalar lookups;
-    /** Stat for number of conditional branches predicted. */
-    Stats::Scalar condPredicted;
-    /** Stat for number of conditional branches predicted incorrectly. */
-    Stats::Scalar condIncorrect;
-    /** Stat for number of BTB lookups. */
-    Stats::Scalar BTBLookups;
-    /** Stat for number of BTB hits. */
-    Stats::Scalar BTBHits;
-    /** Stat for number of times the BTB is correct. */
-    Stats::Scalar BTBCorrect;
-    /** Stat for percent times an entry in BTB found. */
-    Stats::Formula BTBHitPct;
-    /** Stat for number of times the RAS is used to get a target. */
-    Stats::Scalar usedRAS;
-    /** Stat for number of times the RAS is incorrect. */
-    Stats::Scalar RASIncorrect;
+    /** The indirect target predictor. */
+    IndirectPredictor * iPred;
+
+    struct BPredUnitStats : public Stats::Group {
+        BPredUnitStats(Stats::Group *parent);
+
+        /** Stat for number of BP lookups. */
+        Stats::Scalar lookups;
+        /** Stat for number of conditional branches predicted. */
+        Stats::Scalar condPredicted;
+        /** Stat for number of conditional branches predicted incorrectly. */
+        Stats::Scalar condIncorrect;
+        /** Stat for number of BTB lookups. */
+        Stats::Scalar BTBLookups;
+        /** Stat for number of BTB hits. */
+        Stats::Scalar BTBHits;
+        /** Stat for percent times an entry in BTB found. */
+        Stats::Formula BTBHitPct;
+        /** Stat for number of times the RAS is used to get a target. */
+        Stats::Scalar RASUsed;
+        /** Stat for number of times the RAS is incorrect. */
+        Stats::Scalar RASIncorrect;
+
+        /** Stat for the number of indirect target lookups.*/
+        Stats::Scalar indirectLookups;
+        /** Stat for the number of indirect target hits.*/
+        Stats::Scalar indirectHits;
+        /** Stat for the number of indirect target misses.*/
+        Stats::Scalar indirectMisses;
+        /** Stat for the number of indirect target mispredictions.*/
+        Stats::Scalar indirectMispredicted;
+    } stats;
 
   protected:
+    /** Number of bits to shift instructions by for predictor addresses. */
+    const unsigned instShiftAmt;
+
     /**
      * @{
      * @name PMU Probe points.