gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
bpred_unit.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2012, 2014 ARM Limited
3  * Copyright (c) 2010 The University of Edinburgh
4  * All rights reserved
5  *
6  * The license below extends only to copyright in the software and shall
7  * not be construed as granting a license to any other intellectual
8  * property including but not limited to intellectual property relating
9  * to a hardware implementation of the functionality of the software
10  * licensed hereunder. You may use the software subject to the license
11  * terms below provided that you ensure that this notice is replicated
12  * unmodified and in its entirety in all distributions of the software,
13  * modified or unmodified, in source code or in binary form.
14  *
15  * Copyright (c) 2004-2005 The Regents of The University of Michigan
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions are
20  * met: redistributions of source code must retain the above copyright
21  * notice, this list of conditions and the following disclaimer;
22  * redistributions in binary form must reproduce the above copyright
23  * notice, this list of conditions and the following disclaimer in the
24  * documentation and/or other materials provided with the distribution;
25  * neither the name of the copyright holders nor the names of its
26  * contributors may be used to endorse or promote products derived from
27  * this software without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Authors: Kevin Lim
42  * Korey Sewell
43  * Timothy M. Jones
44  * Nilay Vaish
45  */
46 
47 #ifndef __CPU_PRED_BPRED_UNIT_HH__
48 #define __CPU_PRED_BPRED_UNIT_HH__
49 
50 #include <deque>
51 
52 #include "base/statistics.hh"
53 #include "base/types.hh"
54 #include "cpu/pred/btb.hh"
55 #include "cpu/pred/indirect.hh"
56 #include "cpu/pred/ras.hh"
57 #include "cpu/inst_seq.hh"
58 #include "cpu/static_inst.hh"
59 #include "params/BranchPredictor.hh"
60 #include "sim/probe/pmu.hh"
61 #include "sim/sim_object.hh"
62 
67 class BPredUnit : public SimObject
68 {
69  public:
70  typedef BranchPredictorParams Params;
74  BPredUnit(const Params *p);
75 
79  void regStats() override;
80 
81  void regProbePoints() override;
82 
84  void drainSanityCheck() const;
85 
94  bool predict(const StaticInstPtr &inst, const InstSeqNum &seqNum,
96 
97  // @todo: Rename this function.
98  virtual void uncondBranch(ThreadID tid, Addr pc, void * &bp_history) = 0;
99 
106  void update(const InstSeqNum &done_sn, ThreadID tid);
107 
114  void squash(const InstSeqNum &squashed_sn, ThreadID tid);
115 
125  void squash(const InstSeqNum &squashed_sn,
126  const TheISA::PCState &corr_target,
127  bool actually_taken, ThreadID tid);
128 
133  virtual void squash(ThreadID tid, void *bp_history) = 0;
134 
142  virtual bool lookup(ThreadID tid, Addr instPC, void * &bp_history) = 0;
143 
152  virtual void btbUpdate(ThreadID tid, Addr instPC, void * &bp_history) = 0;
153 
159  bool BTBValid(Addr instPC)
160  { return BTB.valid(instPC, 0); }
161 
168  { return BTB.lookup(instPC, 0); }
169 
180  virtual void update(ThreadID tid, Addr instPC, bool taken,
181  void *bp_history, bool squashed) = 0;
187  void BTBUpdate(Addr instPC, const TheISA::PCState &target)
188  { BTB.update(instPC, target, 0); }
189 
190 
191  virtual unsigned getGHR(ThreadID tid, void* bp_history) const { return 0; }
192 
193  void dump();
194 
195  private:
201  PredictorHistory(const InstSeqNum &seq_num, Addr instPC,
202  bool pred_taken, void *bp_history,
203  ThreadID _tid)
204  : seqNum(seq_num), pc(instPC), bpHistory(bp_history), RASTarget(0),
205  RASIndex(0), tid(_tid), predTaken(pred_taken), usedRAS(0), pushedRAS(0),
206  wasCall(0), wasReturn(0), wasIndirect(0)
207  {}
208 
209  bool operator==(const PredictorHistory &entry) const {
210  return this->seqNum == entry.seqNum;
211  }
212 
215 
218 
223  void *bpHistory;
224 
227 
229  unsigned RASIndex;
230 
233 
235  bool predTaken;
236 
238  bool usedRAS;
239 
240  /* Whether or not the RAS was pushed */
241  bool pushedRAS;
242 
244  bool wasCall;
245 
247  bool wasReturn;
248 
251  };
252 
254 
256  const unsigned numThreads;
257 
258 
265 
268 
271 
273  const bool useIndirect;
274 
277 
296 
305 
306  protected:
308  const unsigned instShiftAmt;
309 
323 
324 
331 
334 
336 };
337 
338 #endif // __CPU_PRED_BPRED_UNIT_HH__
IndirectPredictor iPred
The indirect target predictor.
Definition: bpred_unit.hh:276
Stats::Scalar indirectHits
Stat for the number of indirect target hits.
Definition: bpred_unit.hh:300
Stats::Scalar BTBHits
Stat for number of BTB hits.
Definition: bpred_unit.hh:287
ThreadID tid
The thread id.
Definition: bpred_unit.hh:232
bool operator==(const PredictorHistory &entry) const
Definition: bpred_unit.hh:209
Stats::Scalar usedRAS
Stat for number of times the RAS is used to get a target.
Definition: bpred_unit.hh:293
bool wasReturn
Whether or not the instruction was a return.
Definition: bpred_unit.hh:247
BranchPredictorParams Params
Definition: bpred_unit.hh:70
std::vector< History > predHist
The per-thread predictor history.
Definition: bpred_unit.hh:264
void update(const InstSeqNum &done_sn, ThreadID tid)
Tells the branch predictor to commit any updates until the given sequence number. ...
Definition: bpred_unit.cc:324
Stats::Scalar condIncorrect
Stat for number of conditional branches predicted incorrectly.
Definition: bpred_unit.hh:283
Stats::Scalar BTBCorrect
Stat for number of times the BTB is correct.
Definition: bpred_unit.hh:289
void * bpHistory
Pointer to the history object passed back from the branch predictor.
Definition: bpred_unit.hh:223
const bool useIndirect
Option to disable indirect predictor.
Definition: bpred_unit.hh:273
Declaration of Statistics objects.
bool BTBValid(Addr instPC)
Looks up a given PC in the BTB to see if a matching entry exists.
Definition: bpred_unit.hh:159
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2475
STL vector class.
Definition: stl.hh:40
TheISA::PCState RASTarget
The RAS target (only valid if a return).
Definition: bpred_unit.hh:226
void regProbePoints() override
Register probe points for this object.
Definition: bpred_unit.cc:164
PredictorHistory(const InstSeqNum &seq_num, Addr instPC, bool pred_taken, void *bp_history, ThreadID _tid)
Makes a predictor history struct that contains any information needed to update the predictor...
Definition: bpred_unit.hh:201
bool usedRAS
Whether or not the RAS was used.
Definition: bpred_unit.hh:238
void drainSanityCheck() const
Perform sanity checks after a drain.
Definition: bpred_unit.cc:171
unsigned RASIndex
The RAS index of the instruction (only valid if a call).
Definition: bpred_unit.hh:229
TheISA::PCState BTBLookup(Addr instPC)
Looks up a given PC in the BTB to get the predicted target.
Definition: bpred_unit.hh:167
Stats::Formula BTBHitPct
Stat for percent times an entry in BTB found.
Definition: bpred_unit.hh:291
void dump()
Definition: bpred_unit.cc:491
Stats::Scalar indirectMisses
Stat for the number of indirect target misses.
Definition: bpred_unit.hh:302
std::unique_ptr< PMU > PMUUPtr
Definition: pmu.hh:57
virtual void uncondBranch(ThreadID tid, Addr pc, void *&bp_history)=0
Stats::Scalar condPredicted
Stat for number of conditional branches predicted.
Definition: bpred_unit.hh:281
std::deque< PredictorHistory > History
Definition: bpred_unit.hh:253
virtual void btbUpdate(ThreadID tid, Addr instPC, void *&bp_history)=0
If a branch is not taken, because the BTB address is invalid or missing, this function sets the appro...
Stats::Scalar BTBLookups
Stat for number of BTB lookups.
Definition: bpred_unit.hh:285
bool predict(const StaticInstPtr &inst, const InstSeqNum &seqNum, TheISA::PCState &pc, ThreadID tid)
Predicts whether or not the instruction is a taken branch, and the target of the branch if it is take...
Definition: bpred_unit.cc:180
uint64_t InstSeqNum
Definition: inst_seq.hh:40
ProbePoints::PMUUPtr pmuProbePoint(const char *name)
Helper method to instantiate probe points belonging to this object.
Definition: bpred_unit.cc:155
DefaultBTB BTB
The BTB.
Definition: bpred_unit.hh:267
void update(Addr instPC, const TheISA::PCState &targetPC, ThreadID tid)
Updates the BTB with the target of a branch.
Definition: btb.cc:130
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
TheISA::PCState lookup(Addr instPC, ThreadID tid)
Looks up an address in the BTB.
Definition: btb.cc:112
ProbePoints::PMUUPtr ppMisses
Miss-predicted branches.
Definition: bpred_unit.hh:333
void regStats() override
Registers statistics.
Definition: bpred_unit.cc:81
bool wasIndirect
Wether this instruction was an indirect branch.
Definition: bpred_unit.hh:250
virtual bool lookup(ThreadID tid, Addr instPC, void *&bp_history)=0
Looks up a given PC in the BP to see if it is taken or not taken.
std::vector< ReturnAddrStack > RAS
The per-thread return address stack.
Definition: bpred_unit.hh:270
Stats::Scalar RASIncorrect
Stat for number of times the RAS is incorrect.
Definition: bpred_unit.hh:295
STL deque class.
Definition: stl.hh:47
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2895
Basically a wrapper class to hold both the branch predictor and the BTB.
Definition: bpred_unit.hh:67
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:171
Addr pc
The PC associated with the sequence number.
Definition: bpred_unit.hh:217
InstSeqNum seqNum
The sequence number for the predictor history entry.
Definition: bpred_unit.hh:214
virtual const std::string name() const
Definition: sim_object.hh:117
bool predTaken
Whether or not it was predicted taken.
Definition: bpred_unit.hh:235
bool valid(Addr instPC, ThreadID tid)
Checks if a branch is in the BTB.
Definition: btb.cc:91
GenericISA::SimplePCState< MachInst > PCState
Definition: types.hh:43
Stats::Scalar indirectMispredicted
Stat for the number of indirect target mispredictions.
Definition: bpred_unit.hh:304
BPredUnit(const Params *p)
Definition: bpred_unit.cc:56
const unsigned instShiftAmt
Number of bits to shift instructions by for predictor addresses.
Definition: bpred_unit.hh:308
void squash(const InstSeqNum &squashed_sn, ThreadID tid)
Squashes all outstanding updates until a given sequence number.
Definition: bpred_unit.cc:342
IntReg pc
Definition: remote_gdb.hh:91
const unsigned numThreads
Number of the threads for which the branch history is maintained.
Definition: bpred_unit.hh:256
bool wasCall
Whether or not the instruction was a call.
Definition: bpred_unit.hh:244
Bitfield< 0 > p
Stats::Scalar indirectLookups
Stat for the number of indirect target lookups.
Definition: bpred_unit.hh:298
virtual unsigned getGHR(ThreadID tid, void *bp_history) const
Definition: bpred_unit.hh:191
ProbePoints::PMUUPtr ppBranches
Branches seen by the branch predictor.
Definition: bpred_unit.hh:330
Abstract superclass for simulation objects.
Definition: sim_object.hh:94
Stats::Scalar lookups
Stat for number of BP lookups.
Definition: bpred_unit.hh:279
void BTBUpdate(Addr instPC, const TheISA::PCState &target)
Updates the BTB with the target of a branch.
Definition: bpred_unit.hh:187

Generated on Fri Jun 9 2017 13:03:44 for gem5 by doxygen 1.8.6