gem5 [DEVELOP-FOR-25.1]
Loading...
Searching...
No Matches
ftq.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022-2023 The University of Edinburgh
3 * Copyright (c) 2025 Arm Limited
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 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions are
17 * met: redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer;
19 * redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution;
22 * neither the name of the copyright holders nor the names of its
23 * contributors may be used to endorse or promote products derived from
24 * this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
38
39#ifndef __CPU_O3_FTQ_HH__
40#define __CPU_O3_FTQ_HH__
41
42#include <list>
43#include <string>
44
46#include "base/statistics.hh"
47#include "base/types.hh"
48#include "cpu/inst_seq.hh"
49#include "cpu/o3/limits.hh"
51#include "sim/probe/probe.hh"
52
53namespace gem5
54{
55
56struct BaseO3CPUParams;
57
58namespace o3
59{
60
61class CPU;
62
63struct DerivO3CPUParams;
64
65// Fetch target sequence type. Basically the same as the instruction sequence
66// number but since the fetch target is generated before instructions.
68
83{
84 public:
85 FetchTarget(const ThreadID _tid, const PCStateBase &_start_pc,
86 FTSeqNum _seqNum);
87
88 private:
90 std::unique_ptr<PCStateBase> startPC;
91
93 std::unique_ptr<PCStateBase> endPC;
94
97 std::unique_ptr<PCStateBase> predPC;
98
99 /* Fetch targets sequence number */
101
104
107
109 bool taken;
110
111 public:
115
116 /* Start address of the basic block */
117 Addr
119 {
120 return startPC->instAddr();
121 }
122
123 /* End address of the basic block */
124 Addr
126 {
127 return (endPC) ? endPC->instAddr() : MaxAddr;
128 }
129
130 /* Fetch Target size (number of bytes) */
131 unsigned
133 {
134 return endAddress() - startAddress();
135 }
136
137 bool
139 {
140 return addr >= startAddress() && addr <= endAddress();
141 }
142
143 bool
145 {
146 return addr == endAddress();
147 }
148
149 bool
151 {
152 return (addr == endAddress()) && is_branch;
153 }
154
155 bool
157 {
158 return addr > endAddress();
159 }
160
164 {
165 return ftSeqNum;
166 }
167
171 {
172 return tid;
173 }
174
176 void
177 setPredTarg(const PCStateBase &pred_pc)
178 {
179 set(predPC, pred_pc);
180 }
181
183 const PCStateBase &
185 {
186 assert(predPC != nullptr);
187 return *predPC;
188 }
189
191 const PCStateBase &
193 {
194 assert(startPC != nullptr);
195 return *startPC;
196 }
197
199 const PCStateBase &
201 {
202 assert(endPC != nullptr);
203 return *endPC;
204 }
205
207 bool
209 {
210 return taken;
211 }
212
214 void finalize(const PCStateBase &exit_pc, bool _is_branch, bool pred_taken,
215 const PCStateBase &pred_pc);
216
218 std::string toString();
219};
220
221typedef std::shared_ptr<FetchTarget> FetchTargetPtr;
222
226class FTQ
227{
228 public:
233 FTQ(CPU *_cpu, const BaseO3CPUParams &params);
234
235 std::string name() const;
236
237 private:
246
248 std::array<Status, MaxThreads> ftqStatus;
249
252
254 const unsigned numEntries;
255
259
261 std::array<std::list<FetchTargetPtr>, MaxThreads> ftq;
262
263 public:
265 void regProbePoints();
266
268 void resetState(ThreadID tid);
269
271 unsigned numFreeEntries(ThreadID tid);
272
274 unsigned size(ThreadID tid);
275
277 bool isFull(ThreadID tid);
278
280 bool isEmpty(ThreadID tid) const;
281
284 void invalidate(ThreadID tid);
285
288 bool isReady(ThreadID tid);
289
294 void lock(ThreadID tid);
295
297 bool isLocked(ThreadID tid);
298
301 void forAllForward(ThreadID tid, std::function<void(FetchTargetPtr &)> f);
302
305 void forAllBackward(ThreadID tid, std::function<void(FetchTargetPtr &)> f);
306
310 void insert(ThreadID tid, FetchTargetPtr fetchTarget);
311
313 void squash(ThreadID tid);
314
318 void squashSanityCheck(ThreadID tid);
319
321 bool isHeadReady(ThreadID tid);
322
328
334 bool popHead(ThreadID tid);
335
337 void printFTQ(ThreadID tid);
338
339 private:
351};
352
353} // namespace o3
354} // namespace gem5
355
356#endif //__CPU_O3_FTQ_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
ProbePointArg generates a point for the class of Arg.
Definition probe.hh:273
O3CPU class, has each of the stages (fetch through commit) within it, as well as all of the time buff...
Definition cpu.hh:97
void insert(ThreadID tid, FetchTargetPtr fetchTarget)
Pushes a fetch target into the back/tail of the FTQ.
Definition ftq.cc:186
void forAllForward(ThreadID tid, std::function< void(FetchTargetPtr &)> f)
Iterates forward over all fetch targets in the FTQ from head/front to tail/back and applies a given f...
Definition ftq.cc:170
const unsigned numEntries
Number of fetch targets in the FTQ.
Definition ftq.hh:254
Status
Possible FTQ statuses.
Definition ftq.hh:240
void resetState(ThreadID tid)
Reset the FTQ state.
Definition ftq.cc:97
ProbePointArg< FetchTargetPtr > * ppFTQInsert
Probe points to attach the FDP prefetcher.
Definition ftq.hh:257
void squash(ThreadID tid)
Squashes all fetch targets in the FTQ for a specific thread.
Definition ftq.cc:199
FTQ(CPU *_cpu, const BaseO3CPUParams &params)
FTQ constructor.
Definition ftq.cc:86
unsigned size(ThreadID tid)
Returns the size of the ftq for a specific partition.
Definition ftq.cc:125
ProbePointArg< FetchTargetPtr > * ppFTQRemove
Definition ftq.hh:258
void regProbePoints()
Registers probes.
Definition ftq.cc:110
FetchTargetPtr readHead(ThreadID tid)
Returns a pointer to the head fetch target of a specific thread within the FTQ.
Definition ftq.cc:225
bool isReady(ThreadID tid)
Returns if the FTQ is in a ready state and its safe to consmume fetch targets.
Definition ftq.cc:152
unsigned numFreeEntries(ThreadID tid)
Returns the number of free entries in a specific FTQ paritition.
Definition ftq.cc:119
bool isLocked(ThreadID tid)
Check if the FTQ is locked.
Definition ftq.cc:164
void invalidate(ThreadID tid)
Invalidates all fetch targets in the FTQ.
Definition ftq.cc:143
void squashSanityCheck(ThreadID tid)
Sanity check to verify that the fetch targets in the ftq do not have a valid bpu_history.
Definition ftq.cc:211
std::array< Status, MaxThreads > ftqStatus
Per-thread FTQ status.
Definition ftq.hh:248
bool isEmpty(ThreadID tid) const
Returns whether or not a specific thread's queue is empty.
Definition ftq.cc:137
bool isHeadReady(ThreadID tid)
Is the head entry ready for the fetch stage to be consumed.
Definition ftq.cc:219
std::string name() const
Definition ftq.cc:104
bool popHead(ThreadID tid)
Pops the head fetch target once its fully processed.
Definition ftq.cc:238
CPU * cpu
Pointer to the CPU.
Definition ftq.hh:251
bool isFull(ThreadID tid)
Returns whether or not a specific thread's queue is full.
Definition ftq.cc:131
std::array< std::list< FetchTargetPtr >, MaxThreads > ftq
FTQ List of Fetch targets.
Definition ftq.hh:261
gem5::o3::FTQ::FTQStats stats
void printFTQ(ThreadID tid)
Print the all fetch targets in the FTQ for debugging.
Definition ftq.cc:268
void forAllBackward(ThreadID tid, std::function< void(FetchTargetPtr &)> f)
Iterates backward over all fetch targets in the FTQ from tail/back to head/front and applies a given ...
Definition ftq.cc:178
bool isExitInst(Addr addr)
Definition ftq.hh:144
std::unique_ptr< PCStateBase > predPC
Predicted target address of the fetch target.
Definition ftq.hh:97
bool predTaken()
Check if the exit branch was predicted taken.
Definition ftq.hh:208
bool taken
If the exit branch is predicted taken.
Definition ftq.hh:109
unsigned size()
Definition ftq.hh:132
const PCStateBase & readEndPC()
Read the exit/end address PC.
Definition ftq.hh:200
const ThreadID tid
The thread this FT belongs to.
Definition ftq.hh:103
FTSeqNum ftNum()
Returns the fetch target number.
Definition ftq.hh:163
std::unique_ptr< PCStateBase > startPC
Start address of the fetch target.
Definition ftq.hh:90
const FTSeqNum ftSeqNum
Definition ftq.hh:100
const PCStateBase & readPredTarg()
Read the predicted target of the exit branch.
Definition ftq.hh:184
bool hasExceeded(Addr addr)
Definition ftq.hh:156
void finalize(const PCStateBase &exit_pc, bool _is_branch, bool pred_taken, const PCStateBase &pred_pc)
Complete a fetch target with the exit instruction.
Definition ftq.cc:66
FetchTarget(const ThreadID _tid, const PCStateBase &_start_pc, FTSeqNum _seqNum)
Fetch Target Methods -----------------------------—.
Definition ftq.cc:54
std::unique_ptr< PCStateBase > endPC
End address of the fetch target.
Definition ftq.hh:93
ThreadID getTid()
Returns the thread ID.
Definition ftq.hh:170
std::string toString()
Print the fetch target for debugging.
Definition ftq.cc:76
bool inRange(Addr addr)
Definition ftq.hh:138
void setPredTarg(const PCStateBase &pred_pc)
Set the predicted target of the exit branch.
Definition ftq.hh:177
bool isExitBranch(Addr addr)
Definition ftq.hh:150
Addr startAddress()
Definition ftq.hh:118
branch_prediction::BPredUnit::PredictorHistory * bpuHistory
Anchor point to attach a branch predictor history.
Definition ftq.hh:114
const PCStateBase & readStartPC()
Read the start address PC.
Definition ftq.hh:192
bool is_branch
Whether the exit instruction is a branch.
Definition ftq.hh:106
A simple distribution stat.
Statistics container.
Definition group.hh:93
This is a simple scalar statistic, like a counter.
Bitfield< 6 > f
Definition misc_types.hh:68
Bitfield< 12, 11 > set
Bitfield< 3 > addr
Definition types.hh:84
Bitfield< 5 > lock
Definition types.hh:82
InstSeqNum FTSeqNum
Definition ftq.hh:67
std::shared_ptr< FetchTarget > FetchTargetPtr
Definition bac.hh:62
static constexpr int MaxThreads
Definition limits.hh:38
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
const Addr MaxAddr
Definition types.hh:171
uint64_t InstSeqNum
Definition inst_seq.hh:40
Declaration of Statistics objects.
Branch Predictor Unit (BPU) history object PredictorHistory This class holds all information needed t...
statistics::Distribution occupancy
Definition ftq.hh:349
FTQStats(CPU *cpu, unsigned numFTQEntries)
Definition ftq.cc:277
statistics::Scalar inserts
Definition ftq.hh:344
statistics::Scalar removals
Definition ftq.hh:345
statistics::Scalar squashes
Definition ftq.hh:346
statistics::Scalar locks
Definition ftq.hh:347

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