gem5  v21.0.1.0
base_dyn_inst_impl.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011, 2019 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  * Copyright (c) 2004-2006 The Regents of The University of Michigan
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  */
40 
41 #ifndef __CPU_BASE_DYN_INST_IMPL_HH__
42 #define __CPU_BASE_DYN_INST_IMPL_HH__
43 
44 #include <iostream>
45 #include <set>
46 #include <sstream>
47 #include <string>
48 
49 #include "base/cprintf.hh"
50 #include "base/trace.hh"
51 #include "config/the_isa.hh"
52 #include "cpu/base_dyn_inst.hh"
53 #include "cpu/exetrace.hh"
54 #include "debug/DynInst.hh"
55 #include "debug/IQ.hh"
56 #include "mem/request.hh"
57 #include "sim/faults.hh"
58 
59 template <class Impl>
61  const StaticInstPtr &_macroop,
62  TheISA::PCState _pc, TheISA::PCState _predPC,
63  InstSeqNum seq_num, ImplCPU *cpu)
64  : staticInst(_staticInst), cpu(cpu),
65  thread(nullptr),
66  traceData(nullptr),
67  regs(staticInst->numSrcRegs(), staticInst->numDestRegs()),
68  macroop(_macroop),
69  memData(nullptr),
70  savedReq(nullptr),
71  reqToVerify(nullptr)
72 {
73  seqNum = seq_num;
74 
75  pc = _pc;
76  predPC = _predPC;
77 
78  initVars();
79 }
80 
81 template <class Impl>
83  const StaticInstPtr &_macroop)
84  : staticInst(_staticInst), traceData(NULL),
85  regs(staticInst->numSrcRegs(), staticInst->numDestRegs()),
86  macroop(_macroop)
87 {
88  seqNum = 0;
89  initVars();
90 }
91 
92 template <class Impl>
93 void
95 {
96  memData = NULL;
97  effAddr = 0;
98  physEffAddr = 0;
99  readyRegs = 0;
100  memReqFlags = 0;
101  // hardware transactional memory
102  htmUid = -1;
103  htmDepth = 0;
104 
105  status.reset();
106 
107  instFlags.reset();
108  instFlags[RecordResult] = true;
109  instFlags[Predicate] = true;
110  instFlags[MemAccPredicate] = true;
111 
112  lqIdx = -1;
113  sqIdx = -1;
114 
115  // Eventually make this a parameter.
116  threadNumber = 0;
117 
118  // Initialize the fault to be NoFault.
119  fault = NoFault;
120 
121 #ifndef NDEBUG
122  ++cpu->instcount;
123 
124  if (cpu->instcount > 1500) {
125 #ifdef DEBUG
126  cpu->dumpInsts();
127  dumpSNList();
128 #endif
129  assert(cpu->instcount <= 1500);
130  }
131 
132  DPRINTF(DynInst,
133  "DynInst: [sn:%lli] Instruction created. Instcount for %s = %i\n",
134  seqNum, cpu->name(), cpu->instcount);
135 #endif
136 
137 #ifdef DEBUG
138  cpu->snList.insert(seqNum);
139 #endif
140 
141 }
142 
143 template <class Impl>
145 {
146  if (memData) {
147  delete [] memData;
148  }
149 
150  if (traceData) {
151  delete traceData;
152  }
153 
154  fault = NoFault;
155 
156 #ifndef NDEBUG
157  --cpu->instcount;
158 
159  DPRINTF(DynInst,
160  "DynInst: [sn:%lli] Instruction destroyed. Instcount for %s = %i\n",
161  seqNum, cpu->name(), cpu->instcount);
162 #endif
163 #ifdef DEBUG
164  cpu->snList.erase(seqNum);
165 #endif
166 
167 }
168 
169 #ifdef DEBUG
170 template <class Impl>
171 void
173 {
174  std::set<InstSeqNum>::iterator sn_it = cpu->snList.begin();
175 
176  int count = 0;
177  while (sn_it != cpu->snList.end()) {
178  cprintf("%i: [sn:%lli] not destroyed\n", count, (*sn_it));
179  count++;
180  sn_it++;
181  }
182 }
183 #endif
184 
185 template <class Impl>
186 void
188 {
189  cprintf("T%d : %#08d `", threadNumber, pc.instAddr());
190  std::cout << staticInst->disassemble(pc.instAddr());
191  cprintf("'\n");
192 }
193 
194 template <class Impl>
195 void
196 BaseDynInst<Impl>::dump(std::string &outstring)
197 {
198  std::ostringstream s;
199  s << "T" << threadNumber << " : 0x" << pc.instAddr() << " "
200  << staticInst->disassemble(pc.instAddr());
201 
202  outstring = s.str();
203 }
204 
205 template <class Impl>
206 void
208 {
209  DPRINTF(IQ, "[sn:%lli] has %d ready out of %d sources. RTI %d)\n",
210  seqNum, readyRegs+1, numSrcRegs(), readyToIssue());
211  if (++readyRegs == numSrcRegs()) {
212  setCanIssue();
213  }
214 }
215 
216 template <class Impl>
217 void
219 {
220  regs.readySrcIdx(src_idx, true);
221  markSrcRegReady();
222 }
223 
224 template <class Impl>
225 bool
227 {
228  // For now I am assuming that src registers 1..n-1 are the ones that the
229  // EA calc depends on. (i.e. src reg 0 is the source of the data to be
230  // stored)
231 
232  for (int i = 1; i < numSrcRegs(); ++i) {
233  if (!regs.readySrcIdx(i))
234  return false;
235  }
236 
237  return true;
238 }
239 
240 
241 
242 template <class Impl>
243 void
245 {
246  status.set(Squashed);
247 
248  if (!isPinnedRegsRenamed() || isPinnedRegsSquashDone())
249  return;
250 
251  // This inst has been renamed already so it may go through rename
252  // again (e.g. if the squash is due to memory access order violation).
253  // Reset the write counters for all pinned destination register to ensure
254  // that they are in a consistent state for a possible re-rename. This also
255  // ensures that dest regs will be pinned to the same phys register if
256  // re-rename happens.
257  for (int idx = 0; idx < numDestRegs(); idx++) {
258  PhysRegIdPtr phys_dest_reg = regs.renamedDestIdx(idx);
259  if (phys_dest_reg->isPinned()) {
260  phys_dest_reg->incrNumPinnedWrites();
261  if (isPinnedRegsWritten())
262  phys_dest_reg->incrNumPinnedWritesToComplete();
263  }
264  }
265  setPinnedRegsSquashDone();
266 }
267 
268 
269 
270 #endif//__CPU_BASE_DYN_INST_IMPL_HH__
ArmISA::status
Bitfield< 5, 0 > status
Definition: miscregs_types.hh:417
BaseDynInst::predPC
TheISA::PCState predPC
Predicted PC state after this instruction.
Definition: base_dyn_inst.hh:351
BaseDynInst::seqNum
InstSeqNum seqNum
The sequence number of the instruction.
Definition: base_dyn_inst.hh:145
BaseDynInst::ImplCPU
Impl::CPUType ImplCPU
Definition: base_dyn_inst.hh:81
PhysRegId::incrNumPinnedWritesToComplete
void incrNumPinnedWritesToComplete()
Definition: reg_class.hh:351
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
BaseDynInst::setSquashed
void setSquashed()
Sets this instruction as squashed.
Definition: base_dyn_inst_impl.hh:244
base_dyn_inst.hh
exetrace.hh
BaseDynInst::~BaseDynInst
~BaseDynInst()
BaseDynInst destructor.
Definition: base_dyn_inst_impl.hh:144
X86ISA::count
count
Definition: misc.hh:703
faults.hh
request.hh
BaseDynInst::markSrcRegReady
void markSrcRegReady()
Records that one of the source registers is ready.
Definition: base_dyn_inst_impl.hh:207
PhysRegId::incrNumPinnedWrites
void incrNumPinnedWrites()
Definition: reg_class.hh:334
BaseDynInst::pc
TheISA::PCState pc
PC state for this instruction.
Definition: base_dyn_inst.hh:171
cprintf
void cprintf(const char *format, const Args &...args)
Definition: cprintf.hh:152
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:237
MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:240
BaseDynInst
Definition: base_dyn_inst.hh:77
cprintf.hh
InstSeqNum
uint64_t InstSeqNum
Definition: inst_seq.hh:37
NoFault
constexpr decltype(nullptr) NoFault
Definition: types.hh:251
BaseDynInst::BaseDynInst
BaseDynInst(const StaticInstPtr &staticInst, const StaticInstPtr &macroop, TheISA::PCState pc, TheISA::PCState predPC, InstSeqNum seq_num, ImplCPU *cpu)
BaseDynInst constructor given a binary instruction.
Definition: base_dyn_inst_impl.hh:60
BaseDynInst::eaSrcsReady
bool eaSrcsReady() const
Returns whether or not the eff.
Definition: base_dyn_inst_impl.hh:226
PhysRegId::isPinned
bool isPinned() const
Definition: reg_class.hh:336
MipsISA::PCState
GenericISA::DelaySlotPCState< MachInst > PCState
Definition: types.hh:41
RegIndex
uint16_t RegIndex
Definition: types.hh:52
PhysRegId
Physical register ID.
Definition: reg_class.hh:223
RefCountingPtr< StaticInst >
trace.hh
BaseDynInst::dump
void dump()
Dumps out contents of this BaseDynInst.
Definition: base_dyn_inst_impl.hh:187
ArmISA::s
Bitfield< 4 > s
Definition: miscregs_types.hh:556
BaseDynInst::initVars
void initVars()
Function to initialize variables in the constructors.
Definition: base_dyn_inst_impl.hh:94

Generated on Tue Jun 22 2021 15:28:25 for gem5 by doxygen 1.8.17