gem5 [DEVELOP-FOR-25.1]
Loading...
Searching...
No Matches
bpred_unit.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2012, 2014 ARM Limited
3 * Copyright (c) 2010,2022-2023 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/inst_seq.hh"
51#include "cpu/pred/btb.hh"
53#include "cpu/pred/indirect.hh"
54#include "cpu/pred/ras.hh"
55#include "cpu/static_inst.hh"
56#include "enums/TargetProvider.hh"
57#include "params/BranchPredictor.hh"
58#include "sim/probe/pmu.hh"
59#include "sim/sim_object.hh"
60
61namespace gem5
62{
63
64namespace branch_prediction
65{
66
71class BPredUnit : public SimObject
72{
73 typedef BranchPredictorParams Params;
74 typedef enums::TargetProvider TargetProvider;
75
77 public:
81 BPredUnit(const Params &p);
82
83 void regProbePoints() override;
84
86 void drainSanityCheck() const;
87
97 bool predict(const StaticInstPtr &inst, const InstSeqNum &seqNum,
98 PCStateBase &pc, ThreadID tid);
99
106 void update(const InstSeqNum &done_sn, ThreadID tid);
107
114 void squash(const InstSeqNum &squashed_sn, ThreadID tid);
115
127 void squash(const InstSeqNum &squashed_sn, const PCStateBase &corr_target,
128 bool actually_taken, ThreadID tid, bool from_commit=true);
129
137 {
138 return btb->valid(tid, pc);
139 }
140
149 const PCStateBase *
151 {
152 return btb->lookup(tid, pc.instAddr());
153 }
154
165 const StaticInstPtr
167 {
168 return btb->getInst(tid, pc);
169 }
170
177 void
178 BTBUpdate(ThreadID tid, Addr pc, const PCStateBase &target)
179 {
180 ++stats.BTBUpdates;
181 return btb->update(tid, pc, target);
182 }
183
200 bool uncond, void * &bp_history);
201
202 void dump();
203
273 {
279 const StaticInstPtr & inst)
280 : seqNum(sn), tid(_tid), pc(_pc),
282 call(inst->isCall()), uncond(!inst->isCondCtrl()),
283 predTaken(false), actuallyTaken(false), condPred(false),
284 btbHit(false), targetProvider(TargetProvider::NoTarget),
285 resteered(false), mispredict(false), target(nullptr),
286 bpHistory(nullptr),
287 indirectHistory(nullptr), rasHistory(nullptr)
288 { }
289
291 {
292 assert(bpHistory == nullptr);
293 assert(indirectHistory == nullptr);
294 assert(rasHistory == nullptr);
295 }
296
299
300 bool
301 operator==(const PredictorHistory &entry) const
302 {
303 return this->seqNum == entry.seqNum;
304 }
305
308
311
313 const Addr pc;
314
317
320
322 const bool call;
323
325 const bool uncond;
326
329
332
335
337 bool btbHit;
338
341
344
347
349 std::unique_ptr<PCStateBase> target;
350
357 void *bpHistory = nullptr;
358
359 void *indirectHistory = nullptr;
360
361 void *rasHistory = nullptr;
362
363 };
364
372 void insertPredictorHistory(ThreadID tid, PredictorHistory *&bpu_history);
373
377 bool predict(const StaticInstPtr &inst, const InstSeqNum &seqNum,
378 PCStateBase &pc, ThreadID tid, PredictorHistory* &bpu_history);
379
386 void squashHistory(ThreadID tid, PredictorHistory* &bpu_history);
387
388
394 void commitBranch(ThreadID tid, PredictorHistory* &bpu_history);
395
401 void updateBTB(ThreadID tid, PredictorHistory *&bpu_history);
402
403 protected:
405 const unsigned numThreads;
406
413 const bool requiresBTBHit;
414
420
422 const unsigned instShiftAmt;
423
430
433
436
439
442
482
483 protected:
484
489
498
499
506
509
511};
512
513} // namespace branch_prediction
514} // namespace gem5
515
516#endif // __CPU_PRED_BPRED_UNIT_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
const StaticInstPtr BTBGetInst(ThreadID tid, Addr pc)
Looks up a given PC in the BTB to get current static instruction information.
std::vector< std::deque< PredictorHistory * > > predHist
The per-thread predictor history.
probing::PMUUPtr pmuProbePoint(const char *name)
Helper method to instantiate probe points belonging to this object.
Definition bpred_unit.cc:70
void update(const InstSeqNum &done_sn, ThreadID tid)
Tells the branch predictor to commit any updates until the given sequence number.
BPredUnit(const Params &p)
Branch Predictor Unit (BPU) interface functions.
Definition bpred_unit.cc:58
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:96
ConditionalPredictor * cPred
The conditional branch predictor.
void branchPlaceholder(ThreadID tid, Addr pc, bool uncond, void *&bp_history)
Special function for the decoupled front-end.
void BTBUpdate(ThreadID tid, Addr pc, const PCStateBase &target)
Updates the BTB with the target of a branch.
probing::PMUUPtr ppMisses
Miss-predicted branches.
const bool requiresBTBHit
Requires the BTB to hit for returns and indirect branches.
void drainSanityCheck() const
Perform sanity checks after a drain.
Definition bpred_unit.cc:86
IndirectPredictor * iPred
The indirect target predictor.
const PCStateBase * BTBLookup(ThreadID tid, PCStateBase &pc)
Looks up a given PC in the BTB to get the predicted target.
void commitBranch(ThreadID tid, PredictorHistory *&bpu_history)
Commit a particular branch.
probing::PMUUPtr ppBranches
Branches seen by the branch predictor.
void regProbePoints() override
Register probe points for this object.
Definition bpred_unit.cc:79
enums::TargetProvider TargetProvider
Definition bpred_unit.hh:74
void insertPredictorHistory(ThreadID tid, PredictorHistory *&bpu_history)
Pushes a PredictorHistory object into the branch predictor history queue.
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:73
void squashHistory(ThreadID tid, PredictorHistory *&bpu_history)
Squashes a particular branch instance.
const bool updateBTBAtSquash
Update the BTB at squash time instead of commit.
ReturnAddrStack * ras
The return address stack.
void squash(const InstSeqNum &squashed_sn, ThreadID tid)
Squashes all outstanding updates until a given sequence number.
gem5::branch_prediction::BPredUnit::BPredUnitStats stats
BranchTargetBuffer * btb
The BTB.
void updateBTB(ThreadID tid, PredictorHistory *&bpu_history)
Update the BTB with the correct target of a branch.
bool BTBValid(ThreadID tid, Addr pc)
Looks up a given PC in the BTB to see if a matching entry exists.
Return address stack class, implements a simple RAS.
Definition ras.hh:62
A formula for statistics that is calculated when printed.
Statistics container.
Definition group.hh:93
This is a simple scalar statistic, like a counter.
A 2-Dimensional vecto of scalar stats.
STL vector class.
Definition stl.hh:37
SimObject(const Params &p)
Definition sim_object.cc:58
Bitfield< 4 > pc
Bitfield< 0 > p
BranchType getBranchType(StaticInstPtr inst)
enums::BranchType BranchType
std::unique_ptr< PMU > PMUUPtr
Definition pmu.hh:60
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
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
RefCountingPtr< StaticInst > StaticInstPtr
uint64_t InstSeqNum
Definition inst_seq.hh:40
Declaration of Statistics objects.
statistics::Scalar indirectLookups
Indirect stats.
statistics::Vector2d lookups
Stats per branch type.
statistics::Vector2d targetProvider
Target prediction per branch type.
statistics::Scalar condPredicted
Additional scalar stats for conditional branches.
Branch Predictor Unit (BPU) history object PredictorHistory This class holds all information needed t...
InstSeqNum seqNum
The sequence number for the predictor history entry.
bool predTaken
Whether or not it was predicted taken.
bool condPred
The prediction of the conditional predictor.
void * bpHistory
Pointer to the history objects passed back from the branch predictor subcomponents.
const Addr pc
The PC associated with the sequence number.
const bool call
Whether or not the instruction was a call.
PredictorHistory & operator=(const PredictorHistory &)=delete
bool operator==(const PredictorHistory &entry) const
PredictorHistory(const PredictorHistory &)=delete
const StaticInstPtr inst
The branch instrction.
bool actuallyTaken
To record the actual outcome of the branch.
bool mispredict
The branch was corrected hence was mispredicted.
PredictorHistory(ThreadID _tid, InstSeqNum sn, Addr _pc, const StaticInstPtr &inst)
Makes a predictor history struct that contains any information needed to update the predictor,...
const bool uncond
Was unconditional control.
const BranchType type
The type of the branch.
bool btbHit
Was BTB hit at prediction time.
std::unique_ptr< PCStateBase > target
The predicted target.
TargetProvider targetProvider
Which component provided the target.
const std::string & name()
Definition trace.cc:48

Generated on Mon Oct 27 2025 04:13:00 for gem5 by doxygen 1.14.0