gem5  v21.2.1.1
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 
58 namespace gem5
59 {
60 
61 namespace branch_prediction
62 {
63 
68 class BPredUnit : public SimObject
69 {
70  public:
71  typedef BranchPredictorParams Params;
75  BPredUnit(const Params &p);
76 
77  void regProbePoints() override;
78 
80  void drainSanityCheck() const;
81 
90  bool predict(const StaticInstPtr &inst, const InstSeqNum &seqNum,
91  PCStateBase &pc, ThreadID tid);
92 
93  // @todo: Rename this function.
94  virtual void uncondBranch(ThreadID tid, Addr pc, void * &bp_history) = 0;
95 
102  void update(const InstSeqNum &done_sn, ThreadID tid);
103 
110  void squash(const InstSeqNum &squashed_sn, ThreadID tid);
111 
121  void squash(const InstSeqNum &squashed_sn,
122  const PCStateBase &corr_target,
123  bool actually_taken, ThreadID tid);
124 
129  virtual void squash(ThreadID tid, void *bp_history) = 0;
130 
138  virtual bool lookup(ThreadID tid, Addr instPC, void * &bp_history) = 0;
139 
148  virtual void btbUpdate(ThreadID tid, Addr instPC, void * &bp_history) = 0;
149 
155  bool BTBValid(Addr instPC) { return BTB.valid(instPC, 0); }
156 
164  const PCStateBase *
165  BTBLookup(Addr inst_pc)
166  {
167  return BTB.lookup(inst_pc, 0);
168  }
169 
183  virtual void update(ThreadID tid, Addr instPC, bool taken,
184  void *bp_history, bool squashed,
185  const StaticInstPtr &inst, Addr corrTarget) = 0;
191  void
192  BTBUpdate(Addr instPC, const PCStateBase &target)
193  {
194  BTB.update(instPC, target, 0);
195  }
196 
197 
198  void dump();
199 
200  private:
202  {
207  PredictorHistory(const InstSeqNum &seq_num, Addr instPC,
208  bool pred_taken, void *bp_history,
209  void *indirect_history, ThreadID _tid,
210  const StaticInstPtr & inst)
211  : seqNum(seq_num), pc(instPC), bpHistory(bp_history),
212  indirectHistory(indirect_history), tid(_tid),
213  predTaken(pred_taken), inst(inst)
214  {}
215 
217  seqNum(other.seqNum), pc(other.pc), bpHistory(other.bpHistory),
219  tid(other.tid), predTaken(other.predTaken), usedRAS(other.usedRAS),
220  pushedRAS(other.pushedRAS), wasCall(other.wasCall),
222  target(other.target), inst(other.inst)
223  {
224  set(RASTarget, other.RASTarget);
225  }
226 
227  bool
228  operator==(const PredictorHistory &entry) const
229  {
230  return this->seqNum == entry.seqNum;
231  }
232 
235 
238 
243  void *bpHistory = nullptr;
244 
245  void *indirectHistory = nullptr;
246 
248  std::unique_ptr<PCStateBase> RASTarget;
249 
251  unsigned RASIndex = 0;
252 
255 
257  bool predTaken;
258 
260  bool usedRAS = false;
261 
262  /* Whether or not the RAS was pushed */
263  bool pushedRAS = false;
264 
266  bool wasCall = false;
267 
269  bool wasReturn = false;
270 
272  bool wasIndirect = false;
273 
278 
281  };
282 
284 
286  const unsigned numThreads;
287 
288 
295 
298 
301 
304 
306  {
308 
325 
334  } stats;
335 
336  protected:
338  const unsigned instShiftAmt;
339 
352  probing::PMUUPtr pmuProbePoint(const char *name);
353 
354 
361 
364 
366 };
367 
368 } // namespace branch_prediction
369 } // namespace gem5
370 
371 #endif // __CPU_PRED_BPRED_UNIT_HH__
gem5::statistics::Scalar
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1930
gem5::branch_prediction::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:304
gem5::branch_prediction::BPredUnit::predict
bool predict(const StaticInstPtr &inst, const InstSeqNum &seqNum, PCStateBase &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:131
gem5::branch_prediction::DefaultBTB
Definition: btb.hh:43
gem5::branch_prediction::BPredUnit::pmuProbePoint
probing::PMUUPtr pmuProbePoint(const char *name)
Helper method to instantiate probe points belonging to this object.
Definition: bpred_unit.cc:106
gem5::branch_prediction::BPredUnit::BPredUnit
BPredUnit(const Params &p)
Definition: bpred_unit.cc:59
gem5::branch_prediction::BPredUnit::PredictorHistory::RASIndex
unsigned RASIndex
The RAS index of the instruction (only valid if a call).
Definition: bpred_unit.hh:251
gem5::branch_prediction::DefaultBTB::lookup
const PCStateBase * lookup(Addr instPC, ThreadID tid)
Looks up an address in the BTB.
Definition: btb.cc:116
gem5::branch_prediction::BPredUnit::PredictorHistory::bpHistory
void * bpHistory
Pointer to the history object passed back from the branch predictor.
Definition: bpred_unit.hh:243
gem5::branch_prediction::BPredUnit::PredictorHistory::PredictorHistory
PredictorHistory(const PredictorHistory &other)
Definition: bpred_unit.hh:216
gem5::branch_prediction::BPredUnit::PredictorHistory::target
Addr target
Target of the branch.
Definition: bpred_unit.hh:277
gem5::branch_prediction::BPredUnit::BTBLookup
const PCStateBase * BTBLookup(Addr inst_pc)
Looks up a given PC in the BTB to get the predicted target.
Definition: bpred_unit.hh:165
gem5::branch_prediction::BPredUnit::PredictorHistory::tid
ThreadID tid
The thread id.
Definition: bpred_unit.hh:254
gem5::branch_prediction::BPredUnit::PredictorHistory::wasIndirect
bool wasIndirect
Wether this instruction was an indirect branch.
Definition: bpred_unit.hh:272
btb.hh
gem5::branch_prediction::BPredUnit::PredictorHistory::wasCall
bool wasCall
Whether or not the instruction was a call.
Definition: bpred_unit.hh:266
gem5::branch_prediction::BPredUnit::Params
BranchPredictorParams Params
Definition: bpred_unit.hh:71
gem5::statistics::Formula
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2539
std::vector
STL vector class.
Definition: stl.hh:37
gem5::branch_prediction::BPredUnit::stats
gem5::branch_prediction::BPredUnit::BPredUnitStats stats
gem5::branch_prediction::BPredUnit::PredictorHistory::seqNum
InstSeqNum seqNum
The sequence number for the predictor history entry.
Definition: bpred_unit.hh:234
gem5::branch_prediction::BPredUnit::BPredUnitStats::BTBHits
statistics::Scalar BTBHits
Stat for number of BTB hits.
Definition: bpred_unit.hh:318
gem5::branch_prediction::BPredUnit::BPredUnitStats::indirectMispredicted
statistics::Scalar indirectMispredicted
Stat for the number of indirect target mispredictions.
Definition: bpred_unit.hh:333
gem5::branch_prediction::BPredUnit::PredictorHistory::indirectHistory
void * indirectHistory
Definition: bpred_unit.hh:245
gem5::RefCountingPtr< StaticInst >
gem5::branch_prediction::BPredUnit::PredictorHistory::wasReturn
bool wasReturn
Whether or not the instruction was a return.
Definition: bpred_unit.hh:269
pmu.hh
gem5::branch_prediction::BPredUnit::predHist
std::vector< History > predHist
The per-thread predictor history.
Definition: bpred_unit.hh:294
gem5::branch_prediction::BPredUnit::BPredUnitStats::condIncorrect
statistics::Scalar condIncorrect
Stat for number of conditional branches predicted incorrectly.
Definition: bpred_unit.hh:314
gem5::branch_prediction::BPredUnit::BPredUnitStats::BTBLookups
statistics::Scalar BTBLookups
Stat for number of BTB lookups.
Definition: bpred_unit.hh:316
inst_seq.hh
gem5::branch_prediction::BPredUnit::PredictorHistory
Definition: bpred_unit.hh:201
gem5::Named::name
virtual std::string name() const
Definition: named.hh:47
sim_object.hh
gem5::probing::PMUUPtr
std::unique_ptr< PMU > PMUUPtr
Definition: pmu.hh:61
gem5::MaxAddr
const Addr MaxAddr
Definition: types.hh:171
gem5::branch_prediction::BPredUnit::BPredUnitStats::indirectMisses
statistics::Scalar indirectMisses
Stat for the number of indirect target misses.
Definition: bpred_unit.hh:331
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
statistics.hh
gem5::branch_prediction::BPredUnit::numThreads
const unsigned numThreads
Number of the threads for which the branch history is maintained.
Definition: bpred_unit.hh:286
gem5::branch_prediction::BPredUnit::BTB
DefaultBTB BTB
The BTB.
Definition: bpred_unit.hh:297
indirect.hh
gem5::branch_prediction::BPredUnit::drainSanityCheck
void drainSanityCheck() const
Perform sanity checks after a drain.
Definition: bpred_unit.cc:122
gem5::branch_prediction::BPredUnit::ppBranches
probing::PMUUPtr ppBranches
Branches seen by the branch predictor.
Definition: bpred_unit.hh:360
gem5::branch_prediction::BPredUnit::BPredUnitStats::indirectHits
statistics::Scalar indirectHits
Stat for the number of indirect target hits.
Definition: bpred_unit.hh:329
static_inst.hh
gem5::branch_prediction::BPredUnit::BPredUnitStats::BPredUnitStats
BPredUnitStats(statistics::Group *parent)
Definition: bpred_unit.cc:76
gem5::SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:146
gem5::branch_prediction::BPredUnit::History
std::deque< PredictorHistory > History
Definition: bpred_unit.hh:283
gem5::branch_prediction::BPredUnit::squash
void squash(const InstSeqNum &squashed_sn, ThreadID tid)
Squashes all outstanding updates until a given sequence number.
Definition: bpred_unit.cc:327
gem5::branch_prediction::BPredUnit::BPredUnitStats::RASIncorrect
statistics::Scalar RASIncorrect
Stat for number of times the RAS is incorrect.
Definition: bpred_unit.hh:324
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::branch_prediction::BPredUnit::PredictorHistory::pushedRAS
bool pushedRAS
Definition: bpred_unit.hh:263
gem5::branch_prediction::BPredUnit::PredictorHistory::pc
Addr pc
The PC associated with the sequence number.
Definition: bpred_unit.hh:237
gem5::branch_prediction::BPredUnit::PredictorHistory::predTaken
bool predTaken
Whether or not it was predicted taken.
Definition: bpred_unit.hh:257
gem5::branch_prediction::BPredUnit::BPredUnitStats::condPredicted
statistics::Scalar condPredicted
Stat for number of conditional branches predicted.
Definition: bpred_unit.hh:312
gem5::branch_prediction::BPredUnit::PredictorHistory::RASTarget
std::unique_ptr< PCStateBase > RASTarget
The RAS target (only valid if a return).
Definition: bpred_unit.hh:248
gem5::branch_prediction::BPredUnit::BPredUnitStats::lookups
statistics::Scalar lookups
Stat for number of BP lookups.
Definition: bpred_unit.hh:310
gem5::branch_prediction::BPredUnit::instShiftAmt
const unsigned instShiftAmt
Number of bits to shift instructions by for predictor addresses.
Definition: bpred_unit.hh:338
gem5::branch_prediction::BPredUnit::regProbePoints
void regProbePoints() override
Register probe points for this object.
Definition: bpred_unit.cc:115
gem5::branch_prediction::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:155
gem5::branch_prediction::BPredUnit::BTBUpdate
void BTBUpdate(Addr instPC, const PCStateBase &target)
Updates the BTB with the target of a branch.
Definition: bpred_unit.hh:192
gem5::branch_prediction::BPredUnit::RAS
std::vector< ReturnAddrStack > RAS
The per-thread return address stack.
Definition: bpred_unit.hh:300
gem5::branch_prediction::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.
gem5::branch_prediction::IndirectPredictor
Definition: indirect.hh:44
types.hh
gem5::branch_prediction::BPredUnit::PredictorHistory::usedRAS
bool usedRAS
Whether or not the RAS was used.
Definition: bpred_unit.hh:260
gem5::branch_prediction::BPredUnit::uncondBranch
virtual void uncondBranch(ThreadID tid, Addr pc, void *&bp_history)=0
std::deque
STL deque class.
Definition: stl.hh:44
gem5::MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:243
gem5::branch_prediction::BPredUnit
Basically a wrapper class to hold both the branch predictor and the BTB.
Definition: bpred_unit.hh:68
gem5::statistics::Group
Statistics container.
Definition: group.hh:93
gem5::branch_prediction::BPredUnit::BPredUnitStats
Definition: bpred_unit.hh:305
gem5::branch_prediction::BPredUnit::BPredUnitStats::indirectLookups
statistics::Scalar indirectLookups
Stat for the number of indirect target lookups.
Definition: bpred_unit.hh:327
gem5::InstSeqNum
uint64_t InstSeqNum
Definition: inst_seq.hh:40
gem5::branch_prediction::BPredUnit::iPred
IndirectPredictor * iPred
The indirect target predictor.
Definition: bpred_unit.hh:303
ras.hh
gem5::branch_prediction::BPredUnit::ppMisses
probing::PMUUPtr ppMisses
Miss-predicted branches.
Definition: bpred_unit.hh:363
gem5::PCStateBase
Definition: pcstate.hh:57
gem5::branch_prediction::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:207
gem5::branch_prediction::BPredUnit::BPredUnitStats::BTBHitRatio
statistics::Formula BTBHitRatio
Stat for the ratio between BTB hits and BTB lookups.
Definition: bpred_unit.hh:320
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: tlb.cc:60
gem5::branch_prediction::DefaultBTB::valid
bool valid(Addr instPC, ThreadID tid)
Checks if a branch is in the BTB.
Definition: btb.cc:95
gem5::branch_prediction::BPredUnit::dump
void dump()
Definition: bpred_unit.cc:503
gem5::branch_prediction::DefaultBTB::update
void update(Addr inst_pc, const PCStateBase &target_pc, ThreadID tid)
Updates the BTB with the target of a branch.
Definition: btb.cc:134
gem5::ThreadID
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:242
gem5::branch_prediction::BPredUnit::PredictorHistory::inst
const StaticInstPtr inst
The branch instrction.
Definition: bpred_unit.hh:280
gem5::branch_prediction::BPredUnit::PredictorHistory::operator==
bool operator==(const PredictorHistory &entry) const
Definition: bpred_unit.hh:228
gem5::branch_prediction::BPredUnit::BPredUnitStats::RASUsed
statistics::Scalar RASUsed
Stat for number of times the RAS is used to get a target.
Definition: bpred_unit.hh:322
gem5::branch_prediction::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...

Generated on Wed May 4 2022 12:13:54 for gem5 by doxygen 1.8.17