changeset 6e6557085eb7 in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=6e6557085eb7
description:
        cpu: Modernise the branch predictor (STL and C++11)

        This patch does some minor house keeping of the branch predictor by
        adopting STL containers, and shifting some iterator to use range-based
        for loops.

        The predictor history is also changed from a list to a deque as we
        never to insertion/deletion other than at the front and back.

diffstat:

 src/cpu/pred/bpred_unit.hh      |  11 +++++------
 src/cpu/pred/bpred_unit_impl.hh |  35 ++++++++++++++++-------------------
 2 files changed, 21 insertions(+), 25 deletions(-)

diffs (121 lines):

diff -r 336c7d36ac00 -r 6e6557085eb7 src/cpu/pred/bpred_unit.hh
--- a/src/cpu/pred/bpred_unit.hh        Tue Mar 11 09:50:02 2014 -0500
+++ b/src/cpu/pred/bpred_unit.hh        Wed Aug 13 06:57:21 2014 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011-2012 ARM Limited
+ * Copyright (c) 2011-2012, 2014 ARM Limited
  * Copyright (c) 2010 The University of Edinburgh
  * All rights reserved
  *
@@ -47,7 +47,7 @@
 #ifndef __CPU_PRED_BPRED_UNIT_HH__
 #define __CPU_PRED_BPRED_UNIT_HH__
 
-#include <list>
+#include <deque>
 
 #include "base/statistics.hh"
 #include "base/types.hh"
@@ -244,8 +244,7 @@
         bool wasReturn;
     };
 
-    typedef std::list<PredictorHistory> History;
-    typedef History::iterator HistoryIt;
+    typedef std::deque<PredictorHistory> History;
 
     /** Number of the threads for which the branch history is maintained. */
     uint32_t numThreads;
@@ -255,13 +254,13 @@
      * as instructions are committed, or restore it to the proper state after
      * a squash.
      */
-    History *predHist;
+    std::vector<History> predHist;
 
     /** The BTB. */
     DefaultBTB BTB;
 
     /** The per-thread return address stack. */
-    ReturnAddrStack *RAS;
+    std::vector<ReturnAddrStack> RAS;
 
     /** Stat for number of BP lookups. */
     Stats::Scalar lookups;
diff -r 336c7d36ac00 -r 6e6557085eb7 src/cpu/pred/bpred_unit_impl.hh
--- a/src/cpu/pred/bpred_unit_impl.hh   Tue Mar 11 09:50:02 2014 -0500
+++ b/src/cpu/pred/bpred_unit_impl.hh   Wed Aug 13 06:57:21 2014 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011-2012 ARM Limited
+ * Copyright (c) 2011-2012, 2014 ARM Limited
  * Copyright (c) 2010 The University of Edinburgh
  * Copyright (c) 2012 Mark D. Hill and David A. Wood
  * All rights reserved
@@ -57,17 +57,15 @@
 
 BPredUnit::BPredUnit(const Params *params)
     : SimObject(params),
+      numThreads(params->numThreads),
+      predHist(numThreads),
       BTB(params->BTBEntries,
           params->BTBTagSize,
-          params->instShiftAmt)
+          params->instShiftAmt),
+      RAS(numThreads)
 {
-    numThreads = params->numThreads;
-
-    predHist = new History[numThreads];
-
-    RAS = new ReturnAddrStack[numThreads];
-    for (int i=0; i < numThreads; i++)
-        RAS[i].init(params->RASSize);
+    for (auto& r : RAS)
+        r.init(params->RASSize);
 }
 
 void
@@ -126,8 +124,8 @@
 {
     // We shouldn't have any outstanding requests when we resume from
     // a drained system.
-    for (int i = 0; i < numThreads; ++i)
-        assert(predHist[i].empty());
+    for (const auto& ph M5_VAR_USED : predHist)
+        assert(ph.empty());
 }
 
 bool
@@ -448,7 +446,7 @@
     // fix up the entry.
     if (!pred_hist.empty()) {
 
-        HistoryIt hist_it = pred_hist.begin();
+        auto hist_it = pred_hist.begin();
         //HistoryIt hist_it = find(pred_hist.begin(), pred_hist.end(),
         //                       squashed_sn);
 
@@ -516,15 +514,14 @@
 void
 BPredUnit::dump()
 {
-    HistoryIt pred_hist_it;
+    int i = 0;
+    for (const auto& ph : predHist) {
+        if (!ph.empty()) {
+            auto pred_hist_it = ph.begin();
 
-    for (int i = 0; i < numThreads; ++i) {
-        if (!predHist[i].empty()) {
-            pred_hist_it = predHist[i].begin();
+            cprintf("predHist[%i].size(): %i\n", i++, ph.size());
 
-            cprintf("predHist[%i].size(): %i\n", i, predHist[i].size());
-
-            while (pred_hist_it != predHist[i].end()) {
+            while (pred_hist_it != ph.end()) {
                 cprintf("[sn:%lli], PC:%#x, tid:%i, predTaken:%i, "
                         "bpHistory:%#x\n",
                         pred_hist_it->seqNum, pred_hist_it->pc,
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to