cpu: Fix bi-mode branch predictor thresholds
[gem5.git] / src / cpu / pred / 2bit_local.hh
index 8b7bb8463d1c2d1820d836c8264febc3bea0a40c..30327b7bcb035023588af5624af60edc0a91e49c 100644 (file)
@@ -1,4 +1,16 @@
 /*
+ * Copyright (c) 2011, 2014 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-2006 The Regents of The University of Michigan
  * All rights reserved.
  *
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * Authors: Kevin Lim
+ *          Timothy M. Jones
  */
 
-#ifndef __CPU_O3_2BIT_LOCAL_PRED_HH__
-#define __CPU_O3_2BIT_LOCAL_PRED_HH__
+#ifndef __CPU_PRED_2BIT_LOCAL_PRED_HH__
+#define __CPU_PRED_2BIT_LOCAL_PRED_HH__
 
 #include <vector>
 
 #include "base/types.hh"
-#include "cpu/o3/sat_counter.hh"
+#include "cpu/pred/bpred_unit.hh"
+#include "cpu/pred/sat_counter.hh"
+#include "params/LocalBP.hh"
 
 /**
  * Implements a local predictor that uses the PC to index into a table of
  * predictor state that needs to be recorded or updated; the update can be
  * determined solely by the branch being taken or not taken.
  */
-class LocalBP
+class LocalBP : public BPredUnit
 {
   public:
     /**
      * Default branch predictor constructor.
-     * @param localPredictorSize Size of the local predictor.
-     * @param localCtrBits Number of bits per counter.
-     * @param instShiftAmt Offset amount for instructions to ignore alignment.
      */
-    LocalBP(unsigned localPredictorSize, unsigned localCtrBits,
-            unsigned instShiftAmt);
+    LocalBP(const LocalBPParams *params);
+
+    virtual void uncondBranch(ThreadID tid, Addr pc, void * &bp_history);
 
     /**
      * Looks up the given address in the branch predictor and returns
@@ -62,16 +75,26 @@ class LocalBP
      * @param bp_history Pointer to any bp history state.
      * @return Whether or not the branch is taken.
      */
-    bool lookup(Addr &branch_addr, void * &bp_history);
+    bool lookup(ThreadID tid, Addr branch_addr, void * &bp_history);
+
+    /**
+     * Updates the branch predictor to Not Taken if a BTB entry is
+     * invalid or not found.
+     * @param branch_addr The address of the branch to look up.
+     * @param bp_history Pointer to any bp history state.
+     * @return Whether or not the branch is taken.
+     */
+    void btbUpdate(ThreadID tid, Addr branch_addr, void * &bp_history);
 
     /**
      * Updates the branch predictor with the actual result of a branch.
      * @param branch_addr The address of the branch to update.
      * @param taken Whether or not the branch was taken.
      */
-    void update(Addr &branch_addr, bool taken, void *bp_history);
+    void update(ThreadID tid, Addr branch_addr, bool taken, void *bp_history,
+                bool squashed);
 
-    void squash(void *bp_history)
+    void squash(ThreadID tid, void *bp_history)
     { assert(bp_history == NULL); }
 
     void reset();
@@ -100,11 +123,8 @@ class LocalBP
     /** Number of bits of the local predictor's counters. */
     unsigned localCtrBits;
 
-    /** Number of bits to shift the PC when calculating index. */
-    unsigned instShiftAmt;
-
     /** Mask to get index bits. */
     unsigned indexMask;
 };
 
-#endif // __CPU_O3_2BIT_LOCAL_PRED_HH__
+#endif // __CPU_PRED_2BIT_LOCAL_PRED_HH__