gem5  v20.1.0.0
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 
42 #ifndef __CPU_PRED_BPRED_UNIT_HH__
43 #define __CPU_PRED_BPRED_UNIT_HH__
44 
45 #include <deque>
46 
47 #include "base/statistics.hh"
48 #include "base/types.hh"
49 #include "cpu/pred/btb.hh"
50 #include "cpu/pred/indirect.hh"
51 #include "cpu/pred/ras.hh"
52 #include "cpu/inst_seq.hh"
53 #include "cpu/static_inst.hh"
54 #include "params/BranchPredictor.hh"
55 #include "sim/probe/pmu.hh"
56 #include "sim/sim_object.hh"
57 
62 class BPredUnit : public SimObject
63 {
64  public:
65  typedef BranchPredictorParams Params;
69  BPredUnit(const Params *p);
70 
71  void regProbePoints() override;
72 
74  void drainSanityCheck() const;
75 
84  bool predict(const StaticInstPtr &inst, const InstSeqNum &seqNum,
86 
87  // @todo: Rename this function.
88  virtual void uncondBranch(ThreadID tid, Addr pc, void * &bp_history) = 0;
89 
96  void update(const InstSeqNum &done_sn, ThreadID tid);
97 
104  void squash(const InstSeqNum &squashed_sn, ThreadID tid);
105 
115  void squash(const InstSeqNum &squashed_sn,
116  const TheISA::PCState &corr_target,
117  bool actually_taken, ThreadID tid);
118 
123  virtual void squash(ThreadID tid, void *bp_history) = 0;
124 
132  virtual bool lookup(ThreadID tid, Addr instPC, void * &bp_history) = 0;
133 
142  virtual void btbUpdate(ThreadID tid, Addr instPC, void * &bp_history) = 0;
143 
149  bool BTBValid(Addr instPC)
150  { return BTB.valid(instPC, 0); }
151 
158  { return BTB.lookup(instPC, 0); }
159 
173  virtual void update(ThreadID tid, Addr instPC, bool taken,
174  void *bp_history, bool squashed,
175  const StaticInstPtr &inst, Addr corrTarget) = 0;
181  void BTBUpdate(Addr instPC, const TheISA::PCState &target)
182  { BTB.update(instPC, target, 0); }
183 
184 
185  void dump();
186 
187  private:
193  PredictorHistory(const InstSeqNum &seq_num, Addr instPC,
194  bool pred_taken, void *bp_history,
195  void *indirect_history, ThreadID _tid,
196  const StaticInstPtr & inst)
197  : seqNum(seq_num), pc(instPC), bpHistory(bp_history),
198  indirectHistory(indirect_history), RASTarget(0), RASIndex(0),
199  tid(_tid), predTaken(pred_taken), usedRAS(0), pushedRAS(0),
201  inst(inst)
202  {}
203 
204  bool operator==(const PredictorHistory &entry) const {
205  return this->seqNum == entry.seqNum;
206  }
207 
210 
213 
218  void *bpHistory;
219 
221 
224 
226  unsigned RASIndex;
227 
230 
232  bool predTaken;
233 
235  bool usedRAS;
236 
237  /* Whether or not the RAS was pushed */
238  bool pushedRAS;
239 
241  bool wasCall;
242 
244  bool wasReturn;
245 
248 
253 
256  };
257 
259 
261  const unsigned numThreads;
262 
263 
270 
273 
276 
279 
280  struct BPredUnitStats : public Stats::Group {
281  BPredUnitStats(Stats::Group *parent);
282 
299 
308  } stats;
309 
310  protected:
312  const unsigned instShiftAmt;
313 
327 
328 
335 
338 
340 };
341 
342 #endif // __CPU_PRED_BPRED_UNIT_HH__
BPredUnit::PredictorHistory::wasReturn
bool wasReturn
Whether or not the instruction was a return.
Definition: bpred_unit.hh:244
BPredUnit::PredictorHistory::indirectHistory
void * indirectHistory
Definition: bpred_unit.hh:220
BPredUnit::regProbePoints
void regProbePoints() override
Register probe points for this object.
Definition: bpred_unit.cc:100
BPredUnit::BPredUnitStats::BTBHitPct
Stats::Formula BTBHitPct
Stat for percent times an entry in BTB found.
Definition: bpred_unit.hh:294
BPredUnit::ppMisses
ProbePoints::PMUUPtr ppMisses
Miss-predicted branches.
Definition: bpred_unit.hh:337
BPredUnit::RAS
std::vector< ReturnAddrStack > RAS
The per-thread return address stack.
Definition: bpred_unit.hh:275
BPredUnit::BPredUnitStats
Definition: bpred_unit.hh:280
ThreadID
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:227
DefaultBTB
Definition: btb.hh:37
BPredUnit::dump
void dump()
Definition: bpred_unit.cc:490
BPredUnit::BPredUnitStats::lookups
Stats::Scalar lookups
Stat for number of BP lookups.
Definition: bpred_unit.hh:284
BPredUnit::BPredUnitStats::indirectMisses
Stats::Scalar indirectMisses
Stat for the number of indirect target misses.
Definition: bpred_unit.hh:305
BPredUnit::PredictorHistory::RASTarget
TheISA::PCState RASTarget
The RAS target (only valid if a return).
Definition: bpred_unit.hh:223
BPredUnit::iPred
IndirectPredictor * iPred
The indirect target predictor.
Definition: bpred_unit.hh:278
BPredUnit::PredictorHistory::target
Addr target
Target of the branch.
Definition: bpred_unit.hh:252
btb.hh
IndirectPredictor
Definition: indirect.hh:38
BPredUnit::drainSanityCheck
void drainSanityCheck() const
Perform sanity checks after a drain.
Definition: bpred_unit.cc:107
BPredUnit::btbUpdate
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...
std::vector
STL vector class.
Definition: stl.hh:37
BPredUnit::PredictorHistory::seqNum
InstSeqNum seqNum
The sequence number for the predictor history entry.
Definition: bpred_unit.hh:209
BPredUnit::BPredUnitStats::condPredicted
Stats::Scalar condPredicted
Stat for number of conditional branches predicted.
Definition: bpred_unit.hh:286
BPredUnit::pmuProbePoint
ProbePoints::PMUUPtr pmuProbePoint(const char *name)
Helper method to instantiate probe points belonging to this object.
Definition: bpred_unit.cc:91
BPredUnit::BTB
DefaultBTB BTB
The BTB.
Definition: bpred_unit.hh:272
BPredUnit::BPredUnitStats::BPredUnitStats
BPredUnitStats(Stats::Group *parent)
Definition: bpred_unit.cc:70
MaxAddr
const Addr MaxAddr
Definition: types.hh:166
BPredUnit::update
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:291
BPredUnit::BPredUnit
BPredUnit(const Params *p)
Definition: bpred_unit.cc:53
BPredUnit::instShiftAmt
const unsigned instShiftAmt
Number of bits to shift instructions by for predictor addresses.
Definition: bpred_unit.hh:312
BPredUnit::PredictorHistory::bpHistory
void * bpHistory
Pointer to the history object passed back from the branch predictor.
Definition: bpred_unit.hh:218
BPredUnit::numThreads
const unsigned numThreads
Number of the threads for which the branch history is maintained.
Definition: bpred_unit.hh:261
pmu.hh
BPredUnit::lookup
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.
BPredUnit::PredictorHistory
Definition: bpred_unit.hh:188
Stats::Scalar
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2533
BPredUnit::BPredUnitStats::indirectHits
Stats::Scalar indirectHits
Stat for the number of indirect target hits.
Definition: bpred_unit.hh:303
BPredUnit::BTBValid
bool BTBValid(Addr instPC)
Looks up a given PC in the BTB to see if a matching entry exists.
Definition: bpred_unit.hh:149
BPredUnit::BPredUnitStats::condIncorrect
Stats::Scalar condIncorrect
Stat for number of conditional branches predicted incorrectly.
Definition: bpred_unit.hh:288
inst_seq.hh
DefaultBTB::update
void update(Addr instPC, const TheISA::PCState &targetPC, ThreadID tid)
Updates the BTB with the target of a branch.
Definition: btb.cc:128
BPredUnit::PredictorHistory::PredictorHistory
PredictorHistory(const InstSeqNum &seq_num, Addr instPC, bool pred_taken, void *bp_history, void *indirect_history, ThreadID _tid, const StaticInstPtr &inst)
Makes a predictor history struct that contains any information needed to update the predictor,...
Definition: bpred_unit.hh:193
sim_object.hh
BPredUnit::BPredUnitStats::BTBHits
Stats::Scalar BTBHits
Stat for number of BTB hits.
Definition: bpred_unit.hh:292
BPredUnit::BTBUpdate
void BTBUpdate(Addr instPC, const TheISA::PCState &target)
Updates the BTB with the target of a branch.
Definition: bpred_unit.hh:181
BPredUnit::BPredUnitStats::RASUsed
Stats::Scalar RASUsed
Stat for number of times the RAS is used to get a target.
Definition: bpred_unit.hh:296
BPredUnit::BPredUnitStats::indirectMispredicted
Stats::Scalar indirectMispredicted
Stat for the number of indirect target mispredictions.
Definition: bpred_unit.hh:307
BPredUnit::PredictorHistory::inst
const StaticInstPtr inst
The branch instrction.
Definition: bpred_unit.hh:255
BPredUnit::BPredUnitStats::indirectLookups
Stats::Scalar indirectLookups
Stat for the number of indirect target lookups.
Definition: bpred_unit.hh:301
MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:240
statistics.hh
DefaultBTB::valid
bool valid(Addr instPC, ThreadID tid)
Checks if a branch is in the BTB.
Definition: btb.cc:89
BPredUnit::PredictorHistory::operator==
bool operator==(const PredictorHistory &entry) const
Definition: bpred_unit.hh:204
BPredUnit::BPredUnitStats::RASIncorrect
Stats::Scalar RASIncorrect
Stat for number of times the RAS is incorrect.
Definition: bpred_unit.hh:298
BPredUnit
Basically a wrapper class to hold both the branch predictor and the BTB.
Definition: bpred_unit.hh:62
indirect.hh
BPredUnit::uncondBranch
virtual void uncondBranch(ThreadID tid, Addr pc, void *&bp_history)=0
BPredUnit::stats
BPredUnit::BPredUnitStats stats
BPredUnit::predHist
std::vector< History > predHist
The per-thread predictor history.
Definition: bpred_unit.hh:269
static_inst.hh
BPredUnit::PredictorHistory::usedRAS
bool usedRAS
Whether or not the RAS was used.
Definition: bpred_unit.hh:235
InstSeqNum
uint64_t InstSeqNum
Definition: inst_seq.hh:37
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
BPredUnit::PredictorHistory::wasIndirect
bool wasIndirect
Wether this instruction was an indirect branch.
Definition: bpred_unit.hh:247
ProbePoints::PMUUPtr
std::unique_ptr< PMU > PMUUPtr
Definition: pmu.hh:56
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:133
BPredUnit::PredictorHistory::RASIndex
unsigned RASIndex
The RAS index of the instruction (only valid if a call).
Definition: bpred_unit.hh:226
BPredUnit::PredictorHistory::wasCall
bool wasCall
Whether or not the instruction was a call.
Definition: bpred_unit.hh:241
BPredUnit::PredictorHistory::pc
Addr pc
The PC associated with the sequence number.
Definition: bpred_unit.hh:212
BPredUnit::Params
BranchPredictorParams Params
Definition: bpred_unit.hh:65
MipsISA::PCState
GenericISA::DelaySlotPCState< MachInst > PCState
Definition: types.hh:41
types.hh
BPredUnit::BPredUnitStats::BTBLookups
Stats::Scalar BTBLookups
Stat for number of BTB lookups.
Definition: bpred_unit.hh:290
Stats::Formula
A formula for statistics that is calculated when printed.
Definition: statistics.hh:3037
std::deque
STL deque class.
Definition: stl.hh:44
Stats::Group
Statistics container.
Definition: group.hh:83
BPredUnit::predict
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:116
BPredUnit::History
std::deque< PredictorHistory > History
Definition: bpred_unit.hh:258
ras.hh
RefCountingPtr< StaticInst >
BPredUnit::PredictorHistory::pushedRAS
bool pushedRAS
Definition: bpred_unit.hh:238
DefaultBTB::lookup
TheISA::PCState lookup(Addr instPC, ThreadID tid)
Looks up an address in the BTB.
Definition: btb.cc:110
BPredUnit::ppBranches
ProbePoints::PMUUPtr ppBranches
Branches seen by the branch predictor.
Definition: bpred_unit.hh:334
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
BPredUnit::squash
void squash(const InstSeqNum &squashed_sn, ThreadID tid)
Squashes all outstanding updates until a given sequence number.
Definition: bpred_unit.cc:314
BPredUnit::PredictorHistory::predTaken
bool predTaken
Whether or not it was predicted taken.
Definition: bpred_unit.hh:232
BPredUnit::BTBLookup
TheISA::PCState BTBLookup(Addr instPC)
Looks up a given PC in the BTB to get the predicted target.
Definition: bpred_unit.hh:157
BPredUnit::PredictorHistory::tid
ThreadID tid
The thread id.
Definition: bpred_unit.hh:229
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:92

Generated on Wed Sep 30 2020 14:02:09 for gem5 by doxygen 1.8.17