gem5 v24.0.0.0
Loading...
Searching...
No Matches
loop_predictor.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022-2023 The University of Edinburgh
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2006 INRIA (Institut National de Recherche en
15 * Informatique et en Automatique / French National Research Institute
16 * for Computer Science and Applied Mathematics)
17 *
18 * All rights reserved.
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions are
22 * met: redistributions of source code must retain the above copyright
23 * notice, this list of conditions and the following disclaimer;
24 * redistributions in binary form must reproduce the above copyright
25 * notice, this list of conditions and the following disclaimer in the
26 * documentation and/or other materials provided with the distribution;
27 * neither the name of the copyright holders nor the names of its
28 * contributors may be used to endorse or promote products derived from
29 * this software without specific prior written permission.
30 *
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
41 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 */
43
44#ifndef __CPU_PRED_LOOP_PREDICTOR_HH__
45#define __CPU_PRED_LOOP_PREDICTOR_HH__
46
47#include "base/statistics.hh"
48#include "base/types.hh"
49#include "sim/sim_object.hh"
50
51namespace gem5
52{
53
54struct LoopPredictorParams;
55
56namespace branch_prediction
57{
58
60{
61 protected:
62 const unsigned logSizeLoopPred;
63 const unsigned loopTableAgeBits;
65 const unsigned loopTableTagBits;
66 const unsigned loopTableIterBits;
67 const unsigned logLoopTableAssoc;
68 const uint8_t confidenceThreshold;
69 const uint16_t loopTagMask;
70 const uint16_t loopNumIterMask;
71 const int loopSetMask;
72
73 // Prediction Structures
74 // Loop Predictor Entry
75 struct LoopEntry
76 {
77 uint16_t numIter;
78 uint16_t currentIter;
79 uint16_t currentIterSpec; // only for useSpeculation
80 uint8_t confidence;
81 uint16_t tag;
82 uint8_t age;
83 bool dir; // only for useDirectionBit
84
86 confidence(0), tag(0), age(0), dir(0) { }
87 };
88
90
92 unsigned withLoopBits;
93
94 const bool useDirectionBit;
95 const bool useSpeculation;
96 const bool useHashing;
98 const unsigned initialLoopIter;
99 const unsigned initialLoopAge;
101
109
117 static inline void unsignedCtrUpdate(uint8_t &ctr, bool up, unsigned nbits)
118 {
119 assert(nbits <= sizeof(uint8_t) << 3);
120 if (up) {
121 if (ctr < ((1 << nbits) - 1))
122 ctr++;
123 } else {
124 if (ctr)
125 ctr--;
126 }
127 }
128 static inline void signedCtrUpdate(int8_t &ctr, bool up, unsigned nbits)
129 {
130 if (up) {
131 if (ctr < ((1 << (nbits - 1)) - 1))
132 ctr++;
133 } else {
134 if (ctr > -(1 << (nbits - 1)))
135 ctr--;
136 }
137 }
138 public:
139 // Primary branch history entry
141 {
142 uint16_t loopTag;
143 uint16_t currentIter;
144
149 int loopIndexB; // only for useHashing
152
154 : loopTag(0), currentIter(0),
155 loopPred(false),
156 loopPredValid(false), loopIndex(0), loopIndexB(0), loopHit(0),
157 predTaken(false)
158 {}
159 };
160
167 int lindex(Addr pc_in, unsigned instShiftAmt) const;
168
177 int finallindex(int lindex, int lowPcBits, int way) const;
178
190 bool getLoop(Addr pc, BranchInfo* bi, bool speculative,
191 unsigned instShiftAmt) const;
192
201 void loopUpdate(Addr pc, bool Taken, BranchInfo* bi, bool tage_pred);
202
210 void specLoopUpdate(bool taken, BranchInfo* bi);
211
221 void condBranchUpdate(ThreadID tid, Addr branch_pc, bool taken,
222 bool tage_pred, BranchInfo* bi, unsigned instShiftAmt);
223
237 bool loopPredict(
238 ThreadID tid, Addr branch_pc, bool cond_branch,
239 BranchInfo* bi, bool prev_pred_taken, unsigned instShiftAmt);
240
247 void updateStats(bool taken, BranchInfo* bi);
248
249 void squashLoop(BranchInfo * bi);
250
251 void squash(ThreadID tid, BranchInfo *bi);
252
253 virtual bool calcConf(int index) const;
254
255 virtual bool optionalAgeInc() const;
256
257 virtual BranchInfo *makeBranchInfo();
258
263 int8_t getLoopUseCounter() const
264 {
265 return loopUseCounter;
266 }
267
271 void init() override;
272
273 LoopPredictor(const LoopPredictorParams &p);
274
275 size_t getSizeInBits() const;
276};
277
278} // namespace branch_prediction
279} // namespace gem5
280
281#endif//__CPU_PRED_LOOP_PREDICTOR_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
Abstract superclass for simulation objects.
LoopPredictor(const LoopPredictorParams &p)
void updateStats(bool taken, BranchInfo *bi)
Update the stats.
int finallindex(int lindex, int lowPcBits, int way) const
Computes the index used to access the ltable structures.
static void unsignedCtrUpdate(uint8_t &ctr, bool up, unsigned nbits)
Updates an unsigned counter based on up/down parameter.
static void signedCtrUpdate(int8_t &ctr, bool up, unsigned nbits)
void specLoopUpdate(bool taken, BranchInfo *bi)
Speculatively updates the loop predictor iteration count (only for useSpeculation).
gem5::branch_prediction::LoopPredictor::LoopPredictorStats stats
int lindex(Addr pc_in, unsigned instShiftAmt) const
Computes the index used to access the loop predictor.
void init() override
Initialize the loop predictor.
void condBranchUpdate(ThreadID tid, Addr branch_pc, bool taken, bool tage_pred, BranchInfo *bi, unsigned instShiftAmt)
Update LTAGE for conditional branches.
virtual bool calcConf(int index) const
int8_t getLoopUseCounter() const
Gets the value of the loop use counter.
bool getLoop(Addr pc, BranchInfo *bi, bool speculative, unsigned instShiftAmt) const
Get a branch prediction from the loop predictor.
bool loopPredict(ThreadID tid, Addr branch_pc, bool cond_branch, BranchInfo *bi, bool prev_pred_taken, unsigned instShiftAmt)
Get the loop prediction.
void loopUpdate(Addr pc, bool Taken, BranchInfo *bi, bool tage_pred)
Updates the loop predictor.
void squash(ThreadID tid, BranchInfo *bi)
Statistics container.
Definition group.hh:93
This is a simple scalar statistic, like a counter.
Bitfield< 23 > up
Definition types.hh:124
Bitfield< 4 > pc
Bitfield< 30, 0 > index
Bitfield< 0 > p
Bitfield< 20, 16 > bi
Definition types.hh:80
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria 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
Declaration of Statistics objects.

Generated on Tue Jun 18 2024 16:24:02 for gem5 by doxygen 1.11.0