Jairo Balart has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/15319

Change subject: cpu: move indirect predictor interface to a base class inheriting from SimObject.
......................................................................

cpu: move indirect predictor interface to a base class inheriting from
SimObject.

This will enable selecting different indirect predictors from command line and
define a public common interface.

Change-Id: Ice6549773def7d3e944fae450d4a079bc351e2ba
---
M src/cpu/pred/BranchPredictor.py
M src/cpu/pred/SConscript
M src/cpu/pred/bpred_unit.cc
M src/cpu/pred/bpred_unit.hh
M src/cpu/pred/indirect.cc
M src/cpu/pred/indirect.hh
A src/cpu/pred/indirect_base.cc
A src/cpu/pred/indirect_base.hh
8 files changed, 155 insertions(+), 38 deletions(-)



diff --git a/src/cpu/pred/BranchPredictor.py b/src/cpu/pred/BranchPredictor.py
index 9cc1bab..1e37ab3 100644
--- a/src/cpu/pred/BranchPredictor.py
+++ b/src/cpu/pred/BranchPredictor.py
@@ -31,6 +31,28 @@
 from m5.params import *
 from m5.proxy import *

+class IndirectPredictorBase(SimObject):
+    type = 'IndirectPredictorBase'
+    cxx_class = 'IndirectPredictorBase'
+    cxx_header = "cpu/pred/indirect_base.hh"
+    abstract = True
+
+    numThreads = Param.Unsigned(Parent.numThreads, "Number of threads")
+
+class IndirectPredictor(IndirectPredictorBase):
+    type = 'IndirectPredictor'
+    cxx_class = 'IndirectPredictor'
+    cxx_header = "cpu/pred/indirect.hh"
+
+    indirectHashGHR = Param.Bool(True, "Hash branch predictor GHR")
+    indirectHashTargets = Param.Bool(True, "Hash path history targets")
+    indirectSets = Param.Unsigned(256, "Cache sets for indirect predictor")
+    indirectWays = Param.Unsigned(2, "Ways for indirect predictor")
+    indirectTagSize = Param.Unsigned(16, "Indirect target cache tag bits")
+    indirectPathLength = Param.Unsigned(3,
+        "Previous indirect targets to use for path history")
+ instShiftAmt = Param.Unsigned(2, "Number of bits to shift instructions by")
+
 class BranchPredictor(SimObject):
     type = 'BranchPredictor'
     cxx_class = 'BPredUnit'
@@ -44,14 +66,8 @@
instShiftAmt = Param.Unsigned(2, "Number of bits to shift instructions by")

     useIndirect = Param.Bool(True, "Use indirect branch predictor")
-    indirectHashGHR = Param.Bool(True, "Hash branch predictor GHR")
-    indirectHashTargets = Param.Bool(True, "Hash path history targets")
-    indirectSets = Param.Unsigned(256, "Cache sets for indirect predictor")
-    indirectWays = Param.Unsigned(2, "Ways for indirect predictor")
-    indirectTagSize = Param.Unsigned(16, "Indirect target cache tag bits")
-    indirectPathLength = Param.Unsigned(3,
-        "Previous indirect targets to use for path history")

+    indirectBranchPred = Param.IndirectPredictorBase(IndirectPredictor())

 class LocalBP(BranchPredictor):
     type = 'LocalBP'
diff --git a/src/cpu/pred/SConscript b/src/cpu/pred/SConscript
index 0028445..a30ad02 100644
--- a/src/cpu/pred/SConscript
+++ b/src/cpu/pred/SConscript
@@ -40,6 +40,7 @@
 Source('2bit_local.cc')
 Source('btb.cc')
 Source('indirect.cc')
+Source('indirect_base.cc')
 Source('ras.cc')
 Source('tournament.cc')
 Source ('bi_mode.cc')
diff --git a/src/cpu/pred/bpred_unit.cc b/src/cpu/pred/bpred_unit.cc
index 94305d7..d8a268a 100644
--- a/src/cpu/pred/bpred_unit.cc
+++ b/src/cpu/pred/bpred_unit.cc
@@ -63,14 +63,7 @@
           params->numThreads),
       RAS(numThreads),
       useIndirect(params->useIndirect),
-      iPred(params->indirectHashGHR,
-            params->indirectHashTargets,
-            params->indirectSets,
-            params->indirectWays,
-            params->indirectTagSize,
-            params->indirectPathLength,
-            params->instShiftAmt,
-            params->numThreads),
+      iPred(params->indirectBranchPred),
       instShiftAmt(params->instShiftAmt)
 {
     for (auto& r : RAS)
@@ -208,7 +201,7 @@
     }

     if (useIndirect) {
-        iPred.updateDirectionInfo(tid, pred_taken, indirect_history);
+        iPred->updateDirectionInfo(tid, pred_taken, indirect_history);
     }

     DPRINTF(Branch, "[tid:%i]: [sn:%i] Creating prediction history "
@@ -284,7 +277,7 @@
                 predict_record.wasIndirect = true;
                 ++indirectLookups;
                 //Consult indirect predictor on indirect control
-                if (iPred.lookup(pc.instAddr(), target, tid)) {
+                if (iPred->lookup(pc.instAddr(), target, tid)) {
                     // Indirect predictor hit
                     ++indirectHits;
                     DPRINTF(Branch, "[tid:%i]: Instruction %s predicted "
@@ -302,7 +295,7 @@
                     }
                     TheISA::advancePC(target, inst);
                 }
- iPred.recordIndirect(pc.instAddr(), target.instAddr(), seqNum, + iPred->recordIndirect(pc.instAddr(), target.instAddr(), seqNum,
                         tid);
             }
         }
@@ -340,7 +333,7 @@
                     predHist[tid].back().inst,
                     predHist[tid].back().target);

-        iPred.commit(done_sn, tid, predHist[tid].back().indirectHistory);
+        iPred->commit(done_sn, tid, predHist[tid].back().indirectHistory);

         predHist[tid].pop_back();
     }
@@ -351,7 +344,7 @@
 {
     History &pred_hist = predHist[tid];

-    iPred.squash(squashed_sn, tid);
+    iPred->squash(squashed_sn, tid);
     while (!pred_hist.empty() &&
            pred_hist.front().seqNum > squashed_sn) {
         if (pred_hist.front().usedRAS) {
@@ -371,7 +364,7 @@

         // This call should delete the bpHistory.
         squash(tid, pred_hist.front().bpHistory);
-        iPred.deleteDirectionInfo(tid, pred_hist.front().indirectHistory);
+        iPred->deleteDirectionInfo(tid, pred_hist.front().indirectHistory);

         DPRINTF(Branch, "[tid:%i]: Removing history for [sn:%i] "
                 "PC %s.\n", tid, pred_hist.front().seqNum,
@@ -452,8 +445,9 @@
                pred_hist.front().bpHistory, true, pred_hist.front().inst,
                corrTarget.instAddr());

- iPred.changeDirectionPrediction(tid, pred_hist.front().indirectHistory,
-                                        actually_taken);
+        iPred->changeDirectionPrediction(tid,
+                                         pred_hist.front().indirectHistory,
+                                         actually_taken);

         if (actually_taken) {
             if (hist_it->wasReturn && !hist_it->usedRAS) {
@@ -465,7 +459,7 @@
             }
             if (hist_it->wasIndirect) {
                 ++indirectMispredicted;
-                iPred.recordTarget(hist_it->seqNum, corrTarget, tid);
+                iPred->recordTarget(hist_it->seqNum, corrTarget, tid);
             } else {
                 DPRINTF(Branch,"[tid: %i] BTB Update called for [sn:%i]"
                         " PC: %s\n", tid,hist_it->seqNum, hist_it->pc);
diff --git a/src/cpu/pred/bpred_unit.hh b/src/cpu/pred/bpred_unit.hh
index 64d56d0..7d26c3a 100644
--- a/src/cpu/pred/bpred_unit.hh
+++ b/src/cpu/pred/bpred_unit.hh
@@ -289,7 +289,7 @@
     const bool useIndirect;

     /** The indirect target predictor. */
-    IndirectPredictor iPred;
+    IndirectPredictorBase * iPred;

     /** Stat for number of BP lookups. */
     Stats::Scalar lookups;
diff --git a/src/cpu/pred/indirect.cc b/src/cpu/pred/indirect.cc
index 6690abb..be9a59d 100644
--- a/src/cpu/pred/indirect.cc
+++ b/src/cpu/pred/indirect.cc
@@ -33,19 +33,21 @@
 #include "base/intmath.hh"
 #include "debug/Indirect.hh"

-IndirectPredictor::IndirectPredictor(bool hash_ghr, bool hash_targets,
-    unsigned num_sets, unsigned num_ways,
-    unsigned tag_bits, unsigned path_len, unsigned inst_shift,
-    unsigned num_threads)
-    : hashGHR(hash_ghr), hashTargets(hash_targets),
-      numSets(num_sets), numWays(num_ways), tagBits(tag_bits),
-      pathLength(path_len), instShift(inst_shift)
+IndirectPredictor::IndirectPredictor(const IndirectPredictorParams * params)
+    : IndirectPredictorBase(params),
+      hashGHR(params->indirectHashGHR),
+      hashTargets(params->indirectHashTargets),
+      numSets(params->indirectSets),
+      numWays(params->indirectWays),
+      tagBits(params->indirectTagSize),
+      pathLength(params->indirectPathLength),
+      instShift(params->instShiftAmt)
 {
     if (!isPowerOf2(numSets)) {
       panic("Indirect predictor requires power of 2 number of sets");
     }

-    threadInfo.resize(num_threads);
+    threadInfo.resize(params->numThreads);

     targetCache.resize(numSets);
     for (unsigned i = 0; i < numSets; i++) {
@@ -216,3 +218,9 @@
 {
     return (br_addr >> instShift) & ((0x1<<tagBits)-1);
 }
+
+IndirectPredictor *
+IndirectPredictorParams::create()
+{
+    return new IndirectPredictor(this);
+}
diff --git a/src/cpu/pred/indirect.hh b/src/cpu/pred/indirect.hh
index 226a778..37442e6 100644
--- a/src/cpu/pred/indirect.hh
+++ b/src/cpu/pred/indirect.hh
@@ -36,14 +36,13 @@
 #include "arch/isa_traits.hh"
 #include "config/the_isa.hh"
 #include "cpu/inst_seq.hh"
+#include "cpu/pred/indirect_base.hh"
+#include "params/IndirectPredictor.hh"

-class IndirectPredictor
+class IndirectPredictor : public IndirectPredictorBase
 {
   public:
-    IndirectPredictor(bool hash_ghr, bool hash_targets,
-                      unsigned num_sets, unsigned num_ways,
-                      unsigned tag_bits, unsigned path_len,
-                      unsigned inst_shift, unsigned num_threads);
+    IndirectPredictor(const IndirectPredictorParams * params);
     bool lookup(Addr br_addr, TheISA::PCState& br_target, ThreadID tid);
     void recordIndirect(Addr br_addr, Addr tgt_addr, InstSeqNum seq_num,
                         ThreadID tid);
diff --git a/src/cpu/pred/indirect_base.cc b/src/cpu/pred/indirect_base.cc
new file mode 100644
index 0000000..8f336b0
--- /dev/null
+++ b/src/cpu/pred/indirect_base.cc
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2014 ARM Limited
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * 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.
+ *
+ */
+
+#include "cpu/pred/indirect.hh"
diff --git a/src/cpu/pred/indirect_base.hh b/src/cpu/pred/indirect_base.hh
new file mode 100644
index 0000000..e8ffcf6
--- /dev/null
+++ b/src/cpu/pred/indirect_base.hh
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2014 ARM Limited
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * 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: Mitch Hayenga
+ */
+
+#ifndef __CPU_PRED_INDIRECT_BASE_HH__
+#define __CPU_PRED_INDIRECT_BASE_HH__
+
+#include "arch/isa_traits.hh"
+#include "config/the_isa.hh"
+#include "cpu/inst_seq.hh"
+#include "params/IndirectPredictorBase.hh"
+#include "sim/sim_object.hh"
+
+class IndirectPredictorBase : public SimObject
+{
+  public:
+
+    typedef IndirectPredictorBaseParams Params;
+
+    IndirectPredictorBase(const Params *params)
+        : SimObject(params)
+    {
+    }
+
+    virtual bool lookup(Addr br_addr, TheISA::PCState& br_target,
+                        ThreadID tid) = 0;
+    virtual void recordIndirect(Addr br_addr, Addr tgt_addr,
+                                InstSeqNum seq_num, ThreadID tid) = 0;
+    virtual void commit(InstSeqNum seq_num, ThreadID tid,
+                        void * indirect_history) = 0;
+    virtual void squash(InstSeqNum seq_num, ThreadID tid) = 0;
+    virtual void recordTarget(InstSeqNum seq_num,
+ const TheISA::PCState& target, ThreadID tid) = 0;
+    virtual void updateDirectionInfo(ThreadID tid, bool taken,
+                                     void* & indirect_history) = 0;
+    virtual void changeDirectionPrediction(ThreadID tid,
+                                           void * indirect_history,
+                                           bool actually_taken) = 0;
+    virtual void deleteDirectionInfo(ThreadID tid,
+                                     void * indirect_history) = 0;
+};
+
+#endif // __CPU_PRED_INDIRECT_BASE_HH__

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/15319
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: Ice6549773def7d3e944fae450d4a079bc351e2ba
Gerrit-Change-Number: 15319
Gerrit-PatchSet: 1
Gerrit-Owner: Jairo Balart <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to