gem5 v23.0.0.1
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
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
58namespace gem5
59{
60
61namespace branch_prediction
62{
63
68class 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 *
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 {
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
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
338
339 protected:
341 const unsigned instShiftAmt;
342
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.
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.
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.
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.
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...
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.
bool BTBValid(Addr instPC)
Looks up a given PC in the BTB to see if a matching entry exists.
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.
IndirectPredictor * iPred
The indirect target predictor.
std::deque< PredictorHistory > History
probing::PMUUPtr ppBranches
Branches seen by the branch predictor.
void regProbePoints() override
Register probe points for this object.
std::vector< ReturnAddrStack > RAS
The per-thread return address stack.
void BTBUpdate(Addr instPC, const PCStateBase &target)
Updates the BTB with the target of a branch.
const PCStateBase * BTBLookup(Addr inst_pc)
Looks up a given PC in the BTB to get the predicted target.
const unsigned numThreads
Number of the threads for which the branch history is maintained.
const unsigned instShiftAmt
Number of bits to shift instructions by for predictor addresses.
BranchPredictorParams Params
Definition bpred_unit.hh:71
void squash(const InstSeqNum &squashed_sn, ThreadID tid)
Squashes all outstanding updates until a given sequence number.
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.
Statistics container.
Definition group.hh:93
This is a simple scalar statistic, like a counter.
STL deque class.
Definition stl.hh:44
STL vector class.
Definition stl.hh:37
Bitfield< 12, 11 > set
Bitfield< 4 > pc
Bitfield< 0 > p
std::unique_ptr< PMU > PMUUPtr
Definition pmu.hh:60
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.
statistics::Scalar indirectMispredicted
Stat for the number of indirect target mispredictions.
statistics::Scalar BTBLookups
Stat for number of BTB lookups.
statistics::Scalar condIncorrect
Stat for number of conditional branches predicted incorrectly.
statistics::Scalar indirectLookups
Stat for the number of indirect target lookups.
statistics::Scalar indirectHits
Stat for the number of indirect target hits.
statistics::Scalar RASUsed
Stat for number of times the RAS is used to get a target.
statistics::Scalar condPredicted
Stat for number of conditional branches predicted.
statistics::Formula BTBHitRatio
Stat for the ratio between BTB hits and BTB lookups.
statistics::Scalar indirectMisses
Stat for the number of indirect target misses.
statistics::Scalar RASIncorrect
Stat for number of times the RAS is incorrect.
statistics::Scalar lookups
Stat for number of BP lookups.
statistics::Scalar BTBHits
Stat for number of BTB hits.
InstSeqNum seqNum
The sequence number for the predictor history entry.
bool predTaken
Whether or not it was predicted taken.
void * bpHistory
Pointer to the history object passed back from the branch predictor.
unsigned RASIndex
The RAS index of the instruction (only valid if a call).
bool wasReturn
Whether or not the instruction was a return.
bool wasIndirect
Wether this instruction was an indirect branch.
bool wasCall
Whether or not the instruction was a call.
Addr pc
The PC associated with the sequence number.
bool operator==(const PredictorHistory &entry) const
std::unique_ptr< PCStateBase > RASTarget
The RAS target (only valid if a return).
PredictorHistory(const PredictorHistory &other)
bool usedRAS
Whether or not the RAS was used.
const StaticInstPtr inst
The branch instrction.
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,...

Generated on Mon Jul 10 2023 15:32:01 for gem5 by doxygen 1.9.7