gem5 [DEVELOP-FOR-25.0]
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"
52#include "cpu/pred/indirect.hh"
53#include "cpu/pred/ras.hh"
54#include "cpu/static_inst.hh"
55#include "enums/TargetProvider.hh"
56#include "params/BranchPredictor.hh"
57#include "sim/probe/pmu.hh"
58#include "sim/sim_object.hh"
59
60namespace gem5
61{
62
63namespace branch_prediction
64{
65
70class BPredUnit : public SimObject
71{
72 typedef BranchPredictorParams Params;
73 typedef enums::TargetProvider TargetProvider;
74
76 public:
77
78
79
83 BPredUnit(const Params &p);
84
85 void regProbePoints() override;
86
88 void drainSanityCheck() const;
89
99 bool predict(const StaticInstPtr &inst, const InstSeqNum &seqNum,
100 PCStateBase &pc, ThreadID tid);
101
108 void update(const InstSeqNum &done_sn, ThreadID tid);
109
116 void squash(const InstSeqNum &squashed_sn, ThreadID tid);
117
129 void squash(const InstSeqNum &squashed_sn, const PCStateBase &corr_target,
130 bool actually_taken, ThreadID tid, bool from_commit=true);
131
132 protected:
133
138
148 virtual bool lookup(ThreadID tid, Addr pc, void * &bp_history) = 0;
149
165 virtual void updateHistories(ThreadID tid, Addr pc, bool uncond,
166 bool taken, Addr target,
167 const StaticInstPtr &inst, void * &bp_history) = 0;
168
174 virtual void squash(ThreadID tid, void * &bp_history) = 0;
175
176
191 virtual void update(ThreadID tid, Addr pc, bool taken,
192 void * &bp_history, bool squashed,
193 const StaticInstPtr &inst, Addr target) = 0;
194
210 virtual void branchPlaceholder(ThreadID tid, Addr pc,
211 bool uncond, void * &bp_history);
212
220 {
221 return btb->valid(tid, pc);
222 }
223
232 const PCStateBase *
234 {
235 return btb->lookup(tid, pc.instAddr());
236 }
237
248 const StaticInstPtr
250 {
251 return btb->getInst(tid, pc);
252 }
253
260 void
261 BTBUpdate(ThreadID tid, Addr pc, const PCStateBase &target)
262 {
263 ++stats.BTBUpdates;
264 return btb->update(tid, pc, target);
265 }
266
267
268 void dump();
269
270 private:
271
272
342 {
348 const StaticInstPtr & inst)
349 : seqNum(sn), tid(_tid), pc(_pc),
351 call(inst->isCall()), uncond(inst->isUncondCtrl()),
352 predTaken(false), actuallyTaken(false), condPred(false),
353 btbHit(false), targetProvider(TargetProvider::NoTarget),
354 resteered(false), mispredict(false), target(nullptr),
355 bpHistory(nullptr),
356 indirectHistory(nullptr), rasHistory(nullptr)
357 { }
358
360 {
361 assert(bpHistory == nullptr);
362 assert(indirectHistory == nullptr);
363 assert(rasHistory == nullptr);
364 }
365
368
369 bool
370 operator==(const PredictorHistory &entry) const
371 {
372 return this->seqNum == entry.seqNum;
373 }
374
377
380
382 const Addr pc;
383
386
389
391 const bool call;
392
394 const bool uncond;
395
398
401
404
406 bool btbHit;
407
410
413
416
418 std::unique_ptr<PCStateBase> target;
419
426 void *bpHistory = nullptr;
427
428 void *indirectHistory = nullptr;
429
430 void *rasHistory = nullptr;
431
432 };
433
435
436
440 bool predict(const StaticInstPtr &inst, const InstSeqNum &seqNum,
441 PCStateBase &pc, ThreadID tid, PredictorHistory* &bpu_history);
442
449 void squashHistory(ThreadID tid, PredictorHistory* &bpu_history);
450
451
457 void commitBranch(ThreadID tid, PredictorHistory* &bpu_history);
458
459
460
461 protected:
463 const unsigned numThreads;
464
471 const bool requiresBTBHit;
472
474 const unsigned instShiftAmt;
475
482
485
488
491
531
532 protected:
533
538
547
548
555
558
560};
561
562} // namespace branch_prediction
563} // namespace gem5
564
565#endif // __CPU_PRED_BPRED_UNIT_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
std::vector< History > predHist
The per-thread predictor history.
const StaticInstPtr BTBGetInst(ThreadID tid, Addr pc)
Looks up a given PC in the BTB to get current static instruction information.
probing::PMUUPtr pmuProbePoint(const char *name)
Helper method to instantiate probe points belonging to this object.
Definition bpred_unit.cc:73
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...
virtual void branchPlaceholder(ThreadID tid, Addr pc, bool uncond, void *&bp_history)
Special function for the decoupled front-end.
Definition bpred_unit.cc:98
void BTBUpdate(ThreadID tid, Addr pc, const PCStateBase &target)
Updates the BTB with the target of a branch.
virtual void updateHistories(ThreadID tid, Addr pc, bool uncond, bool taken, Addr target, const StaticInstPtr &inst, void *&bp_history)=0
Ones done with the prediction this function updates the path and global history.
probing::PMUUPtr ppMisses
Miss-predicted branches.
const bool requiresBTBHit
Requires the BTB to hit for returns and indirect branches.
virtual void squash(ThreadID tid, void *&bp_history)=0
void drainSanityCheck() const
Perform sanity checks after a drain.
Definition bpred_unit.cc:89
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.
virtual void update(ThreadID tid, Addr pc, bool taken, void *&bp_history, bool squashed, const StaticInstPtr &inst, Addr target)=0
Updates the BP with taken/not taken information.
void regProbePoints() override
Register probe points for this object.
Definition bpred_unit.cc:82
enums::TargetProvider TargetProvider
Definition bpred_unit.hh:73
const unsigned numThreads
Number of the threads for which the branch history is maintained.
virtual bool lookup(ThreadID tid, Addr pc, void *&bp_history)=0
Looks up a given conditional branch PC of in the BP to see if it is taken or not taken.
const unsigned instShiftAmt
Number of bits to shift instructions by for predictor addresses.
BranchPredictorParams Params
Definition bpred_unit.hh:72
void squashHistory(ThreadID tid, PredictorHistory *&bpu_history)
Squashes a particular branch instance.
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.
std::deque< PredictorHistory * > History
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 deque class.
Definition stl.hh:44
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...
bool predTaken
Whether or not it was predicted taken.
const InstSeqNum seqNum
The sequence number for the predictor history entry.
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 May 26 2025 09:19:08 for gem5 by doxygen 1.13.2