gem5  v22.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 
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  ++stats.BTBUpdates;
195  BTB.update(instPC, target, 0);
196  }
197 
198 
199  void dump();
200 
201  private:
203  {
208  PredictorHistory(const InstSeqNum &seq_num, Addr instPC,
209  bool pred_taken, void *bp_history,
210  void *indirect_history, ThreadID _tid,
211  const StaticInstPtr & inst)
212  : seqNum(seq_num), pc(instPC), bpHistory(bp_history),
213  indirectHistory(indirect_history), tid(_tid),
214  predTaken(pred_taken), inst(inst)
215  {}
216 
218  seqNum(other.seqNum), pc(other.pc), bpHistory(other.bpHistory),
220  tid(other.tid), predTaken(other.predTaken), usedRAS(other.usedRAS),
221  pushedRAS(other.pushedRAS), wasCall(other.wasCall),
223  target(other.target), inst(other.inst)
224  {
225  set(RASTarget, other.RASTarget);
226  }
227 
228  bool
229  operator==(const PredictorHistory &entry) const
230  {
231  return this->seqNum == entry.seqNum;
232  }
233 
236 
239 
244  void *bpHistory = nullptr;
245 
246  void *indirectHistory = nullptr;
247 
249  std::unique_ptr<PCStateBase> RASTarget;
250 
252  unsigned RASIndex = 0;
253 
256 
258  bool predTaken;
259 
261  bool usedRAS = false;
262 
263  /* Whether or not the RAS was pushed */
264  bool pushedRAS = false;
265 
267  bool wasCall = false;
268 
270  bool wasReturn = false;
271 
273  bool wasIndirect = false;
274 
279 
282  };
283 
285 
287  const unsigned numThreads;
288 
289 
296 
299 
302 
305 
307  {
309 
328 
337  } stats;
338 
339  protected:
341  const unsigned instShiftAmt;
342 
355  probing::PMUUPtr pmuProbePoint(const char *name);
356 
357 
364 
367 
369 };
370 
371 } // namespace branch_prediction
372 } // namespace gem5
373 
374 #endif // __CPU_PRED_BPRED_UNIT_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
virtual std::string name() const
Definition: named.hh:47
Abstract superclass for simulation objects.
Definition: sim_object.hh:148
Basically a wrapper class to hold both the branch predictor and the BTB.
Definition: bpred_unit.hh:69
std::vector< History > predHist
The per-thread predictor history.
Definition: bpred_unit.hh:295
virtual void uncondBranch(ThreadID tid, Addr pc, void *&bp_history)=0
probing::PMUUPtr pmuProbePoint(const char *name)
Helper method to instantiate probe points belonging to this object.
Definition: bpred_unit.cc:107
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...
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:310
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:132
virtual void update(ThreadID tid, Addr instPC, bool taken, void *bp_history, bool squashed, const StaticInstPtr &inst, Addr corrTarget)=0
Updates the BP with taken/not taken information.
probing::PMUUPtr ppMisses
Miss-predicted branches.
Definition: bpred_unit.hh:366
bool BTBValid(Addr instPC)
Looks up a given PC in the BTB to see if a matching entry exists.
Definition: bpred_unit.hh:155
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.
void drainSanityCheck() const
Perform sanity checks after a drain.
Definition: bpred_unit.cc:123
const PCStateBase * BTBLookup(Addr inst_pc)
Looks up a given PC in the BTB to get the predicted target.
Definition: bpred_unit.hh:165
IndirectPredictor * iPred
The indirect target predictor.
Definition: bpred_unit.hh:304
std::deque< PredictorHistory > History
Definition: bpred_unit.hh:284
probing::PMUUPtr ppBranches
Branches seen by the branch predictor.
Definition: bpred_unit.hh:363
void regProbePoints() override
Register probe points for this object.
Definition: bpred_unit.cc:116
std::vector< ReturnAddrStack > RAS
The per-thread return address stack.
Definition: bpred_unit.hh:301
void BTBUpdate(Addr instPC, const PCStateBase &target)
Updates the BTB with the target of a branch.
Definition: bpred_unit.hh:192
const unsigned numThreads
Number of the threads for which the branch history is maintained.
Definition: bpred_unit.hh:287
const unsigned instShiftAmt
Number of bits to shift instructions by for predictor addresses.
Definition: bpred_unit.hh:341
BranchPredictorParams Params
Definition: bpred_unit.hh:71
void squash(const InstSeqNum &squashed_sn, ThreadID tid)
Squashes all outstanding updates until a given sequence number.
Definition: bpred_unit.cc:333
gem5::branch_prediction::BPredUnit::BPredUnitStats stats
virtual void squash(ThreadID tid, void *bp_history)=0
bool valid(Addr instPC, ThreadID tid)
Checks if a branch is in the BTB.
Definition: btb.cc:95
void update(Addr inst_pc, const PCStateBase &target_pc, ThreadID tid)
Updates the BTB with the target of a branch.
Definition: btb.cc:134
const PCStateBase * lookup(Addr instPC, ThreadID tid)
Looks up an address in the BTB.
Definition: btb.cc:116
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2540
Statistics container.
Definition: group.hh:94
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1931
STL deque class.
Definition: stl.hh:44
STL vector class.
Definition: stl.hh:37
Bitfield< 12, 11 > set
Definition: misc_types.hh:709
Bitfield< 4 > pc
Bitfield< 54 > p
Definition: pagetable.hh:70
std::unique_ptr< PMU > PMUUPtr
Definition: pmu.hh:61
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:235
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
const Addr MaxAddr
Definition: types.hh:171
uint64_t InstSeqNum
Definition: inst_seq.hh:40
Declaration of Statistics objects.
statistics::Scalar BTBUpdates
Stat for number of BTB updates.
Definition: bpred_unit.hh:319
statistics::Scalar indirectMispredicted
Stat for the number of indirect target mispredictions.
Definition: bpred_unit.hh:336
statistics::Scalar BTBLookups
Stat for number of BTB lookups.
Definition: bpred_unit.hh:317
statistics::Scalar condIncorrect
Stat for number of conditional branches predicted incorrectly.
Definition: bpred_unit.hh:315
statistics::Scalar indirectLookups
Stat for the number of indirect target lookups.
Definition: bpred_unit.hh:330
statistics::Scalar indirectHits
Stat for the number of indirect target hits.
Definition: bpred_unit.hh:332
statistics::Scalar RASUsed
Stat for number of times the RAS is used to get a target.
Definition: bpred_unit.hh:325
statistics::Scalar condPredicted
Stat for number of conditional branches predicted.
Definition: bpred_unit.hh:313
statistics::Formula BTBHitRatio
Stat for the ratio between BTB hits and BTB lookups.
Definition: bpred_unit.hh:323
statistics::Scalar indirectMisses
Stat for the number of indirect target misses.
Definition: bpred_unit.hh:334
statistics::Scalar RASIncorrect
Stat for number of times the RAS is incorrect.
Definition: bpred_unit.hh:327
statistics::Scalar lookups
Stat for number of BP lookups.
Definition: bpred_unit.hh:311
statistics::Scalar BTBHits
Stat for number of BTB hits.
Definition: bpred_unit.hh:321
InstSeqNum seqNum
The sequence number for the predictor history entry.
Definition: bpred_unit.hh:235
bool predTaken
Whether or not it was predicted taken.
Definition: bpred_unit.hh:258
void * bpHistory
Pointer to the history object passed back from the branch predictor.
Definition: bpred_unit.hh:244
unsigned RASIndex
The RAS index of the instruction (only valid if a call).
Definition: bpred_unit.hh:252
bool wasReturn
Whether or not the instruction was a return.
Definition: bpred_unit.hh:270
bool wasIndirect
Wether this instruction was an indirect branch.
Definition: bpred_unit.hh:273
bool wasCall
Whether or not the instruction was a call.
Definition: bpred_unit.hh:267
Addr pc
The PC associated with the sequence number.
Definition: bpred_unit.hh:238
bool operator==(const PredictorHistory &entry) const
Definition: bpred_unit.hh:229
std::unique_ptr< PCStateBase > RASTarget
The RAS target (only valid if a return).
Definition: bpred_unit.hh:249
PredictorHistory(const PredictorHistory &other)
Definition: bpred_unit.hh:217
bool usedRAS
Whether or not the RAS was used.
Definition: bpred_unit.hh:261
const StaticInstPtr inst
The branch instrction.
Definition: bpred_unit.hh:281
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:208

Generated on Wed Dec 21 2022 10:22:31 for gem5 by doxygen 1.9.1