gem5 v24.0.0.0
Loading...
Searching...
No Matches
scoreboard.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013-2014, 2016-2017 ARM Limited
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 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
39
40#include "cpu/reg_class.hh"
41#include "debug/MinorScoreboard.hh"
42#include "debug/MinorTiming.hh"
43
44namespace gem5
45{
46
47namespace minor
48{
49
50bool
51Scoreboard::findIndex(const RegId& reg, Index &scoreboard_index)
52{
53 bool ret = false;
54
55 switch (reg.classValue()) {
56 case IntRegClass:
57 scoreboard_index = reg.index();
58 ret = true;
59 break;
60 case FloatRegClass:
61 scoreboard_index = floatRegOffset + reg.index();
62 ret = true;
63 break;
64 case VecRegClass:
65 scoreboard_index = vecRegOffset + reg.index();
66 ret = true;
67 break;
68 case VecElemClass:
69 scoreboard_index = vecRegElemOffset + reg.index();
70 ret = true;
71 break;
72 case VecPredRegClass:
73 scoreboard_index = vecPredRegOffset + reg.index();
74 ret = true;
75 break;
76 case MatRegClass:
77 scoreboard_index = matRegOffset + reg.index();
78 ret = true;
79 break;
80 case CCRegClass:
81 scoreboard_index = ccRegOffset + reg.index();
82 ret = true;
83 break;
84 case MiscRegClass:
85 /* Don't bother with Misc registers */
86 ret = false;
87 break;
88 case InvalidRegClass:
89 ret = false;
90 break;
91 default:
92 panic("Unknown register class: %d", reg.classValue());
93 }
94
95 return ret;
96}
97
98void
100 ThreadContext *thread_context, bool mark_unpredictable)
101{
102 if (inst->isFault())
103 return;
104
105 StaticInstPtr staticInst = inst->staticInst;
106 unsigned int num_dests = staticInst->numDestRegs();
107
108 auto *isa = thread_context->getIsaPtr();
109
111 for (unsigned int dest_index = 0; dest_index < num_dests;
112 dest_index++)
113 {
114 RegId reg = staticInst->destRegIdx(dest_index).flatten(*isa);
115 Index index;
116
117 if (findIndex(reg, index)) {
118 if (mark_unpredictable)
120
121 inst->flatDestRegIdx[dest_index] = reg;
122
123 numResults[index]++;
124 returnCycle[index] = retire_time;
125 /* We should be able to rely on only being given accending
126 * execSeqNums, but sanity check */
127 if (inst->id.execSeqNum > writingInst[index]) {
128 writingInst[index] = inst->id.execSeqNum;
129 fuIndices[index] = inst->fuIndex;
130 }
131
132 DPRINTF(MinorScoreboard, "Marking up inst: %s"
133 " regIndex: %d final numResults: %d returnCycle: %d\n",
135 } else {
136 /* Use an invalid ID to mark invalid/untracked dests */
137 inst->flatDestRegIdx[dest_index] = RegId();
138 }
139 }
140}
141
144 ThreadContext *thread_context)
145{
146 InstSeqNum ret = 0;
147
148 if (inst->isFault())
149 return ret;
150
151 StaticInstPtr staticInst = inst->staticInst;
152 unsigned int num_srcs = staticInst->numSrcRegs();
153
154 auto *isa = thread_context->getIsaPtr();
155
156 for (unsigned int src_index = 0; src_index < num_srcs; src_index++) {
157 RegId reg = staticInst->srcRegIdx(src_index).flatten(*isa);
158 unsigned short int index;
159
160 if (findIndex(reg, index)) {
161 if (writingInst[index] > ret)
162 ret = writingInst[index];
163 }
164 }
165
166 DPRINTF(MinorScoreboard, "Inst: %s depends on execSeqNum: %d\n",
167 *inst, ret);
168
169 return ret;
170}
171
172void
173Scoreboard::clearInstDests(MinorDynInstPtr inst, bool clear_unpredictable)
174{
175 if (inst->isFault())
176 return;
177
178 StaticInstPtr staticInst = inst->staticInst;
179 unsigned int num_dests = staticInst->numDestRegs();
180
182 for (unsigned int dest_index = 0; dest_index < num_dests;
183 dest_index++)
184 {
185 const RegId& reg = inst->flatDestRegIdx[dest_index];
186 Index index;
187
188 if (findIndex(reg, index)) {
189 if (clear_unpredictable && numUnpredictableResults[index] != 0)
191
192 numResults[index] --;
193
194 if (numResults[index] == 0) {
196 writingInst[index] = 0;
198 }
199
200 DPRINTF(MinorScoreboard, "Clearing inst: %s"
201 " regIndex: %d final numResults: %d\n",
202 *inst, index, numResults[index]);
203 }
204 }
205}
206
207bool
209 const std::vector<Cycles> *src_reg_relative_latencies,
210 const std::vector<bool> *cant_forward_from_fu_indices,
211 Cycles now, ThreadContext *thread_context)
212{
213 /* Always allow fault to be issued */
214 if (inst->isFault())
215 return true;
216
217 StaticInstPtr staticInst = inst->staticInst;
218 unsigned int num_srcs = staticInst->numSrcRegs();
219
220 /* Default to saying you can issue */
221 bool ret = true;
222
223 unsigned int num_relative_latencies = 0;
224 Cycles default_relative_latency = Cycles(0);
225
226 /* Where relative latencies are given, the default is the last
227 * one as that allows the rel. lat. list to be shorted than the
228 * number of src. regs */
229 if (src_reg_relative_latencies &&
230 src_reg_relative_latencies->size() != 0)
231 {
232 num_relative_latencies = src_reg_relative_latencies->size();
233 default_relative_latency = (*src_reg_relative_latencies)
234 [num_relative_latencies-1];
235 }
236
237 auto *isa = thread_context->getIsaPtr();
238
239 /* For each source register, find the latest result */
240 unsigned int src_index = 0;
241 while (src_index < num_srcs && /* More registers */
242 ret /* Still possible */)
243 {
244 RegId reg = staticInst->srcRegIdx(src_index).flatten(*isa);
245 unsigned short int index;
246
247 if (findIndex(reg, index)) {
248 int src_reg_fu = fuIndices[index];
249 bool cant_forward = src_reg_fu != invalidFUIndex &&
250 cant_forward_from_fu_indices &&
251 src_reg_fu < cant_forward_from_fu_indices->size() &&
252 (*cant_forward_from_fu_indices)[src_reg_fu];
253
254 Cycles relative_latency = (cant_forward ? Cycles(0) :
255 (src_index >= num_relative_latencies ?
256 default_relative_latency :
257 (*src_reg_relative_latencies)[src_index]));
258
259 if (returnCycle[index] > (now + relative_latency) ||
261 {
262 ret = false;
263 }
264 }
265 src_index++;
266 }
267
268 if (debug::MinorTiming) {
269 if (ret && num_srcs > num_relative_latencies &&
270 num_relative_latencies != 0)
271 {
272 DPRINTF(MinorTiming, "Warning, inst: %s timing extra decode has"
273 " more src. regs: %d than relative latencies: %d\n",
274 staticInst->disassemble(0), num_srcs, num_relative_latencies);
275 }
276 }
277
278 return ret;
279}
280
281void
283{
284 std::ostringstream result_stream;
285
286 bool printed_element = false;
287
288 unsigned int i = 0;
289 while (i < numRegs) {
290 unsigned short int num_results = numResults[i];
291 unsigned short int num_unpredictable_results =
293
294 if (!(num_results == 0 && num_unpredictable_results == Cycles(0))) {
295 if (printed_element)
296 result_stream << ',';
297
298 result_stream << '(' << i << ','
299 << num_results << '/'
300 << num_unpredictable_results << '/'
301 << returnCycle[i] << '/'
302 << writingInst[i] << ')';
303
304 printed_element = true;
305 }
306
307 i++;
308 }
309
310 minor::minorTrace("busy=%s\n", result_stream.str());
311}
312
313} // namespace minor
314} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
Cycles is a wrapper class for representing cycle counts, i.e.
Definition types.hh:79
Register ID: describe an architectural register with its class and index.
Definition reg_class.hh:94
RegId flatten(const BaseISA &isa) const
Definition reg_class.hh:285
virtual const std::string & disassemble(Addr pc, const loader::SymbolTable *symtab=nullptr) const
Return string representation of disassembled instruction.
uint8_t numSrcRegs() const
Number of source registers.
uint8_t numDestRegs() const
Number of destination registers.
const RegId & destRegIdx(int i) const
Return logical index (architectural reg num) of i'th destination reg.
const RegId & srcRegIdx(int i) const
Return logical index (architectural reg num) of i'th source reg.
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual BaseISA * getIsaPtr() const =0
std::vector< Index > numUnpredictableResults
Count of the number of results which can't be predicted.
Definition scoreboard.hh:94
void clearInstDests(MinorDynInstPtr inst, bool clear_unpredictable)
Clear down the dependencies for this instruction.
std::vector< Cycles > returnCycle
The estimated cycle number that the result will be presented.
static constexpr int invalidFUIndex
Definition scoreboard.hh:98
const unsigned floatRegOffset
Definition scoreboard.hh:71
bool canInstIssue(MinorDynInstPtr inst, const std::vector< Cycles > *src_reg_relative_latencies, const std::vector< bool > *cant_forward_from_fu_indices, Cycles now, ThreadContext *thread_context)
Can this instruction be issued.
InstSeqNum execSeqNumToWaitFor(MinorDynInstPtr inst, ThreadContext *thread_context)
Returns the exec sequence number of the most recent inst on which the given inst depends.
const unsigned matRegOffset
Definition scoreboard.hh:76
const unsigned vecRegOffset
Definition scoreboard.hh:73
unsigned short int Index
Type to use when indexing numResults.
Definition scoreboard.hh:87
const unsigned ccRegOffset
Definition scoreboard.hh:72
std::vector< Index > numResults
Count of the number of in-flight instructions that have results for each register.
Definition scoreboard.hh:91
std::vector< int > fuIndices
Index of the FU generating this result.
Definition scoreboard.hh:97
const unsigned vecRegElemOffset
Definition scoreboard.hh:74
const unsigned vecPredRegOffset
Definition scoreboard.hh:75
bool findIndex(const RegId &reg, Index &scoreboard_index)
Sets scoreboard_index to the index into numResults of the given register index.
Definition scoreboard.cc:51
void markupInstDests(MinorDynInstPtr inst, Cycles retire_time, ThreadContext *thread_context, bool mark_unpredictable)
Mark up an instruction's effects by incrementing numResults counts.
Definition scoreboard.cc:99
std::vector< InstSeqNum > writingInst
The execute sequence number of the most recent inst to generate this register value.
void minorTrace() const
MinorTraceIF interface.
const unsigned numRegs
The number of registers in the Scoreboard.
Definition scoreboard.hh:84
STL vector class.
Definition stl.hh:37
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
A simple instruction scoreboard for tracking dependencies in Execute.
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 30, 0 > index
Bitfield< 5, 3 > reg
Definition types.hh:92
void minorTrace(const char *fmt, Args ...args)
DPRINTFN for MinorTrace reporting.
Definition trace.hh:66
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t InstSeqNum
Definition inst_seq.hh:40
@ VecPredRegClass
Definition reg_class.hh:67
@ MatRegClass
Matrix Register.
Definition reg_class.hh:68
@ FloatRegClass
Floating-point register.
Definition reg_class.hh:62
@ CCRegClass
Condition-code register.
Definition reg_class.hh:69
@ VecRegClass
Vector Register.
Definition reg_class.hh:64
@ IntRegClass
Integer register.
Definition reg_class.hh:61
@ InvalidRegClass
Definition reg_class.hh:71
@ MiscRegClass
Control (misc) register.
Definition reg_class.hh:70
@ VecElemClass
Vector Register Native Elem lane.
Definition reg_class.hh:66
Minor contains all the definitions within the MinorCPU apart from the CPU class itself.

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