gem5  v20.1.0.0
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 
38 #include "cpu/minor/scoreboard.hh"
39 
40 #include "arch/registers.hh"
41 #include "cpu/reg_class.hh"
42 #include "debug/MinorScoreboard.hh"
43 #include "debug/MinorTiming.hh"
44 
45 namespace Minor
46 {
47 
48 bool
49 Scoreboard::findIndex(const RegId& reg, Index &scoreboard_index)
50 {
51  bool ret = false;
52 
53  if (reg.isZeroReg()) {
54  /* Don't bother with the zero register */
55  ret = false;
56  } else {
57  switch (reg.classValue())
58  {
59  case IntRegClass:
60  scoreboard_index = reg.index();
61  ret = true;
62  break;
63  case FloatRegClass:
64  scoreboard_index = TheISA::NumIntRegs + TheISA::NumCCRegs +
65  reg.index();
66  ret = true;
67  break;
68  case VecRegClass:
69  scoreboard_index = TheISA::NumIntRegs + TheISA::NumCCRegs +
70  TheISA::NumFloatRegs + reg.index();
71  ret = true;
72  break;
73  case VecElemClass:
74  scoreboard_index = TheISA::NumIntRegs + TheISA::NumCCRegs +
75  TheISA::NumFloatRegs + reg.flatIndex();
76  ret = true;
77  break;
78  case VecPredRegClass:
79  scoreboard_index = TheISA::NumIntRegs + TheISA::NumCCRegs +
81  ret = true;
82  break;
83  case CCRegClass:
84  scoreboard_index = TheISA::NumIntRegs + reg.index();
85  ret = true;
86  break;
87  case MiscRegClass:
88  /* Don't bother with Misc registers */
89  ret = false;
90  break;
91  default:
92  panic("Unknown register class: %d",
93  static_cast<int>(reg.classValue()));
94  }
95  }
96 
97  return ret;
98 }
99 
101 static RegId
102 flattenRegIndex(const RegId& reg, ThreadContext *thread_context)
103 {
104  return thread_context->flattenRegId(reg);
105 }
106 
107 void
109  ThreadContext *thread_context, bool mark_unpredictable)
110 {
111  if (inst->isFault())
112  return;
113 
114  StaticInstPtr staticInst = inst->staticInst;
115  unsigned int num_dests = staticInst->numDestRegs();
116 
118  for (unsigned int dest_index = 0; dest_index < num_dests;
119  dest_index++)
120  {
122  staticInst->destRegIdx(dest_index), thread_context);
123  Index index;
124 
125  if (findIndex(reg, index)) {
126  if (mark_unpredictable)
128 
129  inst->flatDestRegIdx[dest_index] = reg;
130 
131  numResults[index]++;
132  returnCycle[index] = retire_time;
133  /* We should be able to rely on only being given accending
134  * execSeqNums, but sanity check */
135  if (inst->id.execSeqNum > writingInst[index]) {
136  writingInst[index] = inst->id.execSeqNum;
137  fuIndices[index] = inst->fuIndex;
138  }
139 
140  DPRINTF(MinorScoreboard, "Marking up inst: %s"
141  " regIndex: %d final numResults: %d returnCycle: %d\n",
142  *inst, index, numResults[index], returnCycle[index]);
143  } else {
144  /* Use ZeroReg to mark invalid/untracked dests */
145  inst->flatDestRegIdx[dest_index] = RegId(IntRegClass,
147  }
148  }
149 }
150 
153  ThreadContext *thread_context)
154 {
155  InstSeqNum ret = 0;
156 
157  if (inst->isFault())
158  return ret;
159 
160  StaticInstPtr staticInst = inst->staticInst;
161  unsigned int num_srcs = staticInst->numSrcRegs();
162 
163  for (unsigned int src_index = 0; src_index < num_srcs; src_index++) {
164  RegId reg = flattenRegIndex(staticInst->srcRegIdx(src_index),
165  thread_context);
166  unsigned short int index;
167 
168  if (findIndex(reg, index)) {
169  if (writingInst[index] > ret)
170  ret = writingInst[index];
171  }
172  }
173 
174  DPRINTF(MinorScoreboard, "Inst: %s depends on execSeqNum: %d\n",
175  *inst, ret);
176 
177  return ret;
178 }
179 
180 void
181 Scoreboard::clearInstDests(MinorDynInstPtr inst, bool clear_unpredictable)
182 {
183  if (inst->isFault())
184  return;
185 
186  StaticInstPtr staticInst = inst->staticInst;
187  unsigned int num_dests = staticInst->numDestRegs();
188 
190  for (unsigned int dest_index = 0; dest_index < num_dests;
191  dest_index++)
192  {
193  const RegId& reg = inst->flatDestRegIdx[dest_index];
194  Index index;
195 
196  if (findIndex(reg, index)) {
197  if (clear_unpredictable && numUnpredictableResults[index] != 0)
199 
200  numResults[index] --;
201 
202  if (numResults[index] == 0) {
203  returnCycle[index] = Cycles(0);
204  writingInst[index] = 0;
205  fuIndices[index] = -1;
206  }
207 
208  DPRINTF(MinorScoreboard, "Clearing inst: %s"
209  " regIndex: %d final numResults: %d\n",
210  *inst, index, numResults[index]);
211  }
212  }
213 }
214 
215 bool
217  const std::vector<Cycles> *src_reg_relative_latencies,
218  const std::vector<bool> *cant_forward_from_fu_indices,
219  Cycles now, ThreadContext *thread_context)
220 {
221  /* Always allow fault to be issued */
222  if (inst->isFault())
223  return true;
224 
225  StaticInstPtr staticInst = inst->staticInst;
226  unsigned int num_srcs = staticInst->numSrcRegs();
227 
228  /* Default to saying you can issue */
229  bool ret = true;
230 
231  unsigned int num_relative_latencies = 0;
232  Cycles default_relative_latency = Cycles(0);
233 
234  /* Where relative latencies are given, the default is the last
235  * one as that allows the rel. lat. list to be shorted than the
236  * number of src. regs */
237  if (src_reg_relative_latencies &&
238  src_reg_relative_latencies->size() != 0)
239  {
240  num_relative_latencies = src_reg_relative_latencies->size();
241  default_relative_latency = (*src_reg_relative_latencies)
242  [num_relative_latencies-1];
243  }
244 
245  /* For each source register, find the latest result */
246  unsigned int src_index = 0;
247  while (src_index < num_srcs && /* More registers */
248  ret /* Still possible */)
249  {
250  RegId reg = flattenRegIndex(staticInst->srcRegIdx(src_index),
251  thread_context);
252  unsigned short int index;
253 
254  if (findIndex(reg, index)) {
255  bool cant_forward = fuIndices[index] != 1 &&
256  cant_forward_from_fu_indices &&
257  index < cant_forward_from_fu_indices->size() &&
258  (*cant_forward_from_fu_indices)[index];
259 
260  Cycles relative_latency = (cant_forward ? Cycles(0) :
261  (src_index >= num_relative_latencies ?
262  default_relative_latency :
263  (*src_reg_relative_latencies)[src_index]));
264 
265  if (returnCycle[index] > (now + relative_latency) ||
267  {
268  ret = false;
269  }
270  }
271  src_index++;
272  }
273 
274  if (DTRACE(MinorTiming)) {
275  if (ret && num_srcs > num_relative_latencies &&
276  num_relative_latencies != 0)
277  {
278  DPRINTF(MinorTiming, "Warning, inst: %s timing extra decode has"
279  " more src. regs: %d than relative latencies: %d\n",
280  staticInst->disassemble(0), num_srcs, num_relative_latencies);
281  }
282  }
283 
284  return ret;
285 }
286 
287 void
289 {
290  std::ostringstream result_stream;
291 
292  bool printed_element = false;
293 
294  unsigned int i = 0;
295  while (i < numRegs) {
296  unsigned short int num_results = numResults[i];
297  unsigned short int num_unpredictable_results =
299 
300  if (!(num_results == 0 && num_unpredictable_results == Cycles(0))) {
301  if (printed_element)
302  result_stream << ',';
303 
304  result_stream << '(' << i << ','
305  << num_results << '/'
306  << num_unpredictable_results << '/'
307  << returnCycle[i] << '/'
308  << writingInst[i] << ')';
309 
310  printed_element = true;
311  }
312 
313  i++;
314  }
315 
316  MINORTRACE("busy=%s\n", result_stream.str());
317 }
318 
319 }
scoreboard.hh
StaticInst::destRegIdx
const RegId & destRegIdx(int i) const
Return logical index (architectural reg num) of i'th destination reg.
Definition: static_inst.hh:230
VecElemClass
@ VecElemClass
Vector Register Native Elem lane.
Definition: reg_class.hh:58
MipsISA::index
Bitfield< 30, 0 > index
Definition: pra_constants.hh:44
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
Minor::Scoreboard::findIndex
bool findIndex(const RegId &reg, Index &scoreboard_index)
Sets scoreboard_index to the index into numResults of the given register index.
Definition: scoreboard.cc:49
MINORTRACE
#define MINORTRACE(...)
DPRINTFN for MinorTrace reporting.
Definition: trace.hh:60
DTRACE
#define DTRACE(x)
Definition: debug.hh:146
Minor::Scoreboard::Index
unsigned short int Index
Type to use when indexing numResults.
Definition: scoreboard.hh:69
std::vector< Cycles >
X86ISA::reg
Bitfield< 5, 3 > reg
Definition: types.hh:87
Minor
Definition: activity.cc:44
RegId
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:75
FloatRegClass
@ FloatRegClass
Floating-point register.
Definition: reg_class.hh:54
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
Minor::Scoreboard::execSeqNumToWaitFor
InstSeqNum execSeqNumToWaitFor(MinorDynInstPtr inst, ThreadContext *thread_context)
Returns the exec sequence number of the most recent inst on which the given inst depends.
Definition: scoreboard.cc:152
StaticInst::numDestRegs
int8_t numDestRegs() const
Number of destination registers.
Definition: static_inst.hh:137
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
ThreadContext::flattenRegId
virtual RegId flattenRegId(const RegId &regId) const =0
Minor::Scoreboard::numRegs
const unsigned numRegs
The number of registers in the Scoreboard.
Definition: scoreboard.hh:66
ArmISA::ZeroReg
const int ZeroReg
Definition: registers.hh:118
Minor::Scoreboard::numUnpredictableResults
std::vector< Index > numUnpredictableResults
Count of the number of results which can't be predicted.
Definition: scoreboard.hh:76
Minor::Scoreboard::clearInstDests
void clearInstDests(MinorDynInstPtr inst, bool clear_unpredictable)
Clear down the dependencies for this instruction.
Definition: scoreboard.cc:181
ArmISA::NumFloatRegs
const int NumFloatRegs
Definition: registers.hh:83
VecPredRegClass
@ VecPredRegClass
Definition: reg_class.hh:59
StaticInst::srcRegIdx
const RegId & srcRegIdx(int i) const
Return logical index (architectural reg num) of i'th source reg.
Definition: static_inst.hh:234
InstSeqNum
uint64_t InstSeqNum
Definition: inst_seq.hh:37
ArmISA::NumIntRegs
const int NumIntRegs
Definition: registers.hh:82
IntRegClass
@ IntRegClass
Integer register.
Definition: reg_class.hh:53
CCRegClass
@ CCRegClass
Condition-code register.
Definition: reg_class.hh:60
Minor::Scoreboard::minorTrace
void minorTrace() const
MinorTraceIF interface.
Definition: scoreboard.cc:288
StaticInst::numSrcRegs
int8_t numSrcRegs() const
Number of source registers.
Definition: static_inst.hh:135
MiscRegClass
@ MiscRegClass
Control (misc) register.
Definition: reg_class.hh:61
VecRegClass
@ VecRegClass
Vector Register.
Definition: reg_class.hh:56
ArmISA::NumCCRegs
const int NumCCRegs
Definition: registers.hh:84
Minor::Scoreboard::numResults
std::vector< Index > numResults
Count of the number of in-flight instructions that have results for each register.
Definition: scoreboard.hh:73
StaticInst::disassemble
virtual const std::string & disassemble(Addr pc, const Loader::SymbolTable *symtab=nullptr) const
Return string representation of disassembled instruction.
Definition: static_inst.cc:121
Minor::Scoreboard::writingInst
std::vector< InstSeqNum > writingInst
The execute sequence number of the most recent inst to generate this register value.
Definition: scoreboard.hh:89
reg_class.hh
Minor::flattenRegIndex
static RegId flattenRegIndex(const RegId &reg, ThreadContext *thread_context)
Flatten a RegId, irrespective of what reg type it's pointing to.
Definition: scoreboard.cc:102
Minor::Scoreboard::returnCycle
std::vector< Cycles > returnCycle
The estimated cycle number that the result will be presented.
Definition: scoreboard.hh:85
Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
Minor::Scoreboard::canInstIssue
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.
Definition: scoreboard.cc:216
Minor::Scoreboard::markupInstDests
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:108
RefCountingPtr< MinorDynInst >
Minor::Scoreboard::fuIndices
std::vector< int > fuIndices
Index of the FU generating this result.
Definition: scoreboard.hh:79
ArmISA::NumVecRegs
const int NumVecRegs
Definition: registers.hh:97
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171

Generated on Wed Sep 30 2020 14:02:08 for gem5 by doxygen 1.8.17