gem5  v21.1.0.2
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,
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 TheISA::PCState &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)
156  { return BTB.valid(instPC, 0); }
157 
164  { return BTB.lookup(instPC, 0); }
165 
179  virtual void update(ThreadID tid, Addr instPC, bool taken,
180  void *bp_history, bool squashed,
181  const StaticInstPtr &inst, Addr corrTarget) = 0;
187  void BTBUpdate(Addr instPC, const TheISA::PCState &target)
188  { BTB.update(instPC, target, 0); }
189 
190 
191  void dump();
192 
193  private:
195  {
200  PredictorHistory(const InstSeqNum &seq_num, Addr instPC,
201  bool pred_taken, void *bp_history,
202  void *indirect_history, ThreadID _tid,
203  const StaticInstPtr & inst)
204  : seqNum(seq_num), pc(instPC), bpHistory(bp_history),
205  indirectHistory(indirect_history), RASTarget(0), RASIndex(0),
206  tid(_tid), predTaken(pred_taken), usedRAS(0), pushedRAS(0),
208  inst(inst)
209  {}
210 
211  bool operator==(const PredictorHistory &entry) const {
212  return this->seqNum == entry.seqNum;
213  }
214 
217 
220 
225  void *bpHistory;
226 
228 
231 
233  unsigned RASIndex;
234 
237 
239  bool predTaken;
240 
242  bool usedRAS;
243 
244  /* Whether or not the RAS was pushed */
245  bool pushedRAS;
246 
248  bool wasCall;
249 
251  bool wasReturn;
252 
255 
260 
263  };
264 
266 
268  const unsigned numThreads;
269 
270 
277 
280 
283 
286 
288  {
290 
307 
316  } stats;
317 
318  protected:
320  const unsigned instShiftAmt;
321 
334  probing::PMUUPtr pmuProbePoint(const char *name);
335 
336 
343 
346 
348 };
349 
350 } // namespace branch_prediction
351 } // namespace gem5
352 
353 #endif // __CPU_PRED_BPRED_UNIT_HH__
gem5::statistics::Scalar
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1927
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:305
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:105
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:233
gem5::branch_prediction::BPredUnit::PredictorHistory::bpHistory
void * bpHistory
Pointer to the history object passed back from the branch predictor.
Definition: bpred_unit.hh:225
gem5::branch_prediction::BPredUnit::PredictorHistory::target
Addr target
Target of the branch.
Definition: bpred_unit.hh:259
gem5::branch_prediction::BPredUnit::PredictorHistory::tid
ThreadID tid
The thread id.
Definition: bpred_unit.hh:236
gem5::branch_prediction::BPredUnit::PredictorHistory::wasIndirect
bool wasIndirect
Wether this instruction was an indirect branch.
Definition: bpred_unit.hh:254
btb.hh
gem5::branch_prediction::BPredUnit::PredictorHistory::wasCall
bool wasCall
Whether or not the instruction was a call.
Definition: bpred_unit.hh:248
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:2536
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:216
gem5::branch_prediction::BPredUnit::BPredUnitStats::BTBHits
statistics::Scalar BTBHits
Stat for number of BTB hits.
Definition: bpred_unit.hh:300
gem5::branch_prediction::BPredUnit::BPredUnitStats::indirectMispredicted
statistics::Scalar indirectMispredicted
Stat for the number of indirect target mispredictions.
Definition: bpred_unit.hh:315
gem5::branch_prediction::BPredUnit::PredictorHistory::indirectHistory
void * indirectHistory
Definition: bpred_unit.hh:227
gem5::RefCountingPtr< StaticInst >
gem5::branch_prediction::DefaultBTB::update
void update(Addr instPC, const TheISA::PCState &targetPC, ThreadID tid)
Updates the BTB with the target of a branch.
Definition: btb.cc:134
gem5::branch_prediction::BPredUnit::PredictorHistory::RASTarget
TheISA::PCState RASTarget
The RAS target (only valid if a return).
Definition: bpred_unit.hh:230
gem5::branch_prediction::BPredUnit::PredictorHistory::wasReturn
bool wasReturn
Whether or not the instruction was a return.
Definition: bpred_unit.hh:251
pmu.hh
gem5::branch_prediction::BPredUnit::predHist
std::vector< History > predHist
The per-thread predictor history.
Definition: bpred_unit.hh:276
gem5::branch_prediction::BPredUnit::BPredUnitStats::condIncorrect
statistics::Scalar condIncorrect
Stat for number of conditional branches predicted incorrectly.
Definition: bpred_unit.hh:296
gem5::branch_prediction::BPredUnit::BTBLookup
TheISA::PCState BTBLookup(Addr instPC)
Looks up a given PC in the BTB to get the predicted target.
Definition: bpred_unit.hh:163
gem5::branch_prediction::BPredUnit::BPredUnitStats::BTBLookups
statistics::Scalar BTBLookups
Stat for number of BTB lookups.
Definition: bpred_unit.hh:298
inst_seq.hh
gem5::branch_prediction::BPredUnit::PredictorHistory
Definition: bpred_unit.hh:194
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:313
gem5::MipsISA::PCState
GenericISA::DelaySlotPCState< 4 > PCState
Definition: pcstate.hh:40
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:268
gem5::branch_prediction::BPredUnit::BTB
DefaultBTB BTB
The BTB.
Definition: bpred_unit.hh:279
gem5::branch_prediction::DefaultBTB::lookup
TheISA::PCState lookup(Addr instPC, ThreadID tid)
Looks up an address in the BTB.
Definition: btb.cc:116
indirect.hh
gem5::branch_prediction::BPredUnit::drainSanityCheck
void drainSanityCheck() const
Perform sanity checks after a drain.
Definition: bpred_unit.cc:121
gem5::branch_prediction::BPredUnit::ppBranches
probing::PMUUPtr ppBranches
Branches seen by the branch predictor.
Definition: bpred_unit.hh:342
gem5::branch_prediction::BPredUnit::BPredUnitStats::indirectHits
statistics::Scalar indirectHits
Stat for the number of indirect target hits.
Definition: bpred_unit.hh:311
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:265
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:328
gem5::branch_prediction::BPredUnit::BPredUnitStats::RASIncorrect
statistics::Scalar RASIncorrect
Stat for number of times the RAS is incorrect.
Definition: bpred_unit.hh:306
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:245
gem5::branch_prediction::BPredUnit::PredictorHistory::pc
Addr pc
The PC associated with the sequence number.
Definition: bpred_unit.hh:219
gem5::branch_prediction::BPredUnit::PredictorHistory::predTaken
bool predTaken
Whether or not it was predicted taken.
Definition: bpred_unit.hh:239
gem5::branch_prediction::BPredUnit::BPredUnitStats::condPredicted
statistics::Scalar condPredicted
Stat for number of conditional branches predicted.
Definition: bpred_unit.hh:294
gem5::branch_prediction::BPredUnit::BPredUnitStats::lookups
statistics::Scalar lookups
Stat for number of BP lookups.
Definition: bpred_unit.hh:292
gem5::branch_prediction::BPredUnit::instShiftAmt
const unsigned instShiftAmt
Number of bits to shift instructions by for predictor addresses.
Definition: bpred_unit.hh:320
gem5::branch_prediction::BPredUnit::regProbePoints
void regProbePoints() override
Register probe points for this object.
Definition: bpred_unit.cc:114
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::RAS
std::vector< ReturnAddrStack > RAS
The per-thread return address stack.
Definition: bpred_unit.hh:282
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:242
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:287
gem5::branch_prediction::BPredUnit::BPredUnitStats::indirectLookups
statistics::Scalar indirectLookups
Stat for the number of indirect target lookups.
Definition: bpred_unit.hh:309
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:285
ras.hh
gem5::branch_prediction::BPredUnit::BTBUpdate
void BTBUpdate(Addr instPC, const TheISA::PCState &target)
Updates the BTB with the target of a branch.
Definition: bpred_unit.hh:187
gem5::branch_prediction::BPredUnit::ppMisses
probing::PMUUPtr ppMisses
Miss-predicted branches.
Definition: bpred_unit.hh:345
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:200
gem5::branch_prediction::BPredUnit::BPredUnitStats::BTBHitRatio
statistics::Formula BTBHitRatio
Stat for the ratio between BTB hits and BTB lookups.
Definition: bpred_unit.hh:302
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
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:504
gem5::branch_prediction::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:130
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:262
gem5::branch_prediction::BPredUnit::PredictorHistory::operator==
bool operator==(const PredictorHistory &entry) const
Definition: bpred_unit.hh:211
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:304
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 Tue Sep 21 2021 12:25:05 for gem5 by doxygen 1.8.17