gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 
183  virtual void update(ThreadID tid, Addr instPC, bool taken,
184  void *bp_history, bool squashed,
186  Addr corrTarget = MaxAddr) = 0;
192  void BTBUpdate(Addr instPC, const TheISA::PCState &target)
193  { BTB.update(instPC, target, 0); }
194 
195 
196  void dump();
197 
198  private:
204  PredictorHistory(const InstSeqNum &seq_num, Addr instPC,
205  bool pred_taken, void *bp_history,
206  void *indirect_history, ThreadID _tid,
207  const StaticInstPtr & inst)
208  : seqNum(seq_num), pc(instPC), bpHistory(bp_history),
209  indirectHistory(indirect_history), RASTarget(0), RASIndex(0),
210  tid(_tid), predTaken(pred_taken), usedRAS(0), pushedRAS(0),
212  inst(inst)
213  {}
214 
215  bool operator==(const PredictorHistory &entry) const {
216  return this->seqNum == entry.seqNum;
217  }
218 
221 
224 
229  void *bpHistory;
230 
232 
235 
237  unsigned RASIndex;
238 
241 
243  bool predTaken;
244 
246  bool usedRAS;
247 
248  /* Whether or not the RAS was pushed */
249  bool pushedRAS;
250 
252  bool wasCall;
253 
255  bool wasReturn;
256 
259 
264 
267  };
268 
270 
272  const unsigned numThreads;
273 
274 
281 
284 
287 
290 
309 
318 
319  protected:
321  const unsigned instShiftAmt;
322 
336 
337 
344 
347 
349 };
350 
351 #endif // __CPU_PRED_BPRED_UNIT_HH__
Stats::Scalar indirectHits
Stat for the number of indirect target hits.
Definition: bpred_unit.hh:313
const Addr MaxAddr
Definition: types.hh:166
Addr target
Target of the branch.
Definition: bpred_unit.hh:263
Stats::Scalar BTBHits
Stat for number of BTB hits.
Definition: bpred_unit.hh:300
ThreadID tid
The thread id.
Definition: bpred_unit.hh:240
Stats::Scalar usedRAS
Stat for number of times the RAS is used to get a target.
Definition: bpred_unit.hh:306
bool wasReturn
Whether or not the instruction was a return.
Definition: bpred_unit.hh:255
BranchPredictorParams Params
Definition: bpred_unit.hh:70
std::vector< History > predHist
The per-thread predictor history.
Definition: bpred_unit.hh:280
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:345
IndirectPredictor * iPred
The indirect target predictor.
Definition: bpred_unit.hh:289
Stats::Scalar condIncorrect
Stat for number of conditional branches predicted incorrectly.
Definition: bpred_unit.hh:296
Stats::Scalar BTBCorrect
Stat for number of times the BTB is correct.
Definition: bpred_unit.hh:302
void * bpHistory
Pointer to the history object passed back from the branch predictor.
Definition: bpred_unit.hh:229
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:2508
STL vector class.
Definition: stl.hh:40
TheISA::PCState RASTarget
The RAS target (only valid if a return).
Definition: bpred_unit.hh:234
void regProbePoints() override
Register probe points for this object.
Definition: bpred_unit.cc:156
bool usedRAS
Whether or not the RAS was used.
Definition: bpred_unit.hh:246
Bitfield< 4 > pc
const StaticInstPtr inst
The branch instrction.
Definition: bpred_unit.hh:266
unsigned RASIndex
The RAS index of the instruction (only valid if a call).
Definition: bpred_unit.hh:237
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:304
bool operator==(const PredictorHistory &entry) const
Definition: bpred_unit.hh:215
void dump()
Definition: bpred_unit.cc:544
Stats::Scalar indirectMisses
Stat for the number of indirect target misses.
Definition: bpred_unit.hh:315
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:294
std::deque< PredictorHistory > History
Definition: bpred_unit.hh:269
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:298
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:172
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:147
DefaultBTB BTB
The BTB.
Definition: bpred_unit.hh:283
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:346
virtual const std::string name() const
Definition: sim_object.hh:120
void regStats() override
Registers statistics.
Definition: bpred_unit.cc:73
bool wasIndirect
Wether this instruction was an indirect branch.
Definition: bpred_unit.hh:258
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:286
Stats::Scalar RASIncorrect
Stat for number of times the RAS is incorrect.
Definition: bpred_unit.hh:308
STL deque class.
Definition: stl.hh:47
A formula for statistics that is calculated when printed.
Definition: statistics.hh:3012
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:227
Addr pc
The PC associated with the sequence number.
Definition: bpred_unit.hh:223
InstSeqNum seqNum
The sequence number for the predictor history entry.
Definition: bpred_unit.hh:220
bool predTaken
Whether or not it was predicted taken.
Definition: bpred_unit.hh:243
bool valid(Addr instPC, ThreadID tid)
Checks if a branch is in the BTB.
Definition: btb.cc:91
void drainSanityCheck() const
Perform sanity checks after a drain.
Definition: bpred_unit.cc:163
GenericISA::SimplePCState< MachInst > PCState
Definition: types.hh:43
Stats::Scalar indirectMispredicted
Stat for the number of indirect target mispredictions.
Definition: bpred_unit.hh:317
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:321
void squash(const InstSeqNum &squashed_sn, ThreadID tid)
Squashes all outstanding updates until a given sequence number.
Definition: bpred_unit.cc:368
const unsigned numThreads
Number of the threads for which the branch history is maintained.
Definition: bpred_unit.hh:272
static StaticInstPtr nullStaticInstPtr
Pointer to a statically allocated "null" instruction object.
Definition: static_inst.hh:223
bool wasCall
Whether or not the instruction was a call.
Definition: bpred_unit.hh:252
Bitfield< 0 > p
Stats::Scalar indirectLookups
Stat for the number of indirect target lookups.
Definition: bpred_unit.hh:311
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:204
ProbePoints::PMUUPtr ppBranches
Branches seen by the branch predictor.
Definition: bpred_unit.hh:343
Abstract superclass for simulation objects.
Definition: sim_object.hh:96
Stats::Scalar lookups
Stat for number of BP lookups.
Definition: bpred_unit.hh:292
void BTBUpdate(Addr instPC, const TheISA::PCState &target)
Updates the BTB with the target of a branch.
Definition: bpred_unit.hh:192

Generated on Fri Feb 28 2020 16:26:59 for gem5 by doxygen 1.8.13