gem5  v20.1.0.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  macroop(_macroop),
68  memData(nullptr),
69  savedReq(nullptr),
70  reqToVerify(nullptr)
71 {
72  seqNum = seq_num;
73 
74  pc = _pc;
75  predPC = _predPC;
76 
77  initVars();
78 }
79 
80 template <class Impl>
82  const StaticInstPtr &_macroop)
83  : staticInst(_staticInst), traceData(NULL), macroop(_macroop)
84 {
85  seqNum = 0;
86  initVars();
87 }
88 
89 template <class Impl>
90 void
92 {
93  memData = NULL;
94  effAddr = 0;
95  physEffAddr = 0;
96  readyRegs = 0;
97  memReqFlags = 0;
98  // hardware transactional memory
99  htmUid = -1;
100  htmDepth = 0;
101 
102  status.reset();
103 
104  instFlags.reset();
105  instFlags[RecordResult] = true;
106  instFlags[Predicate] = true;
107  instFlags[MemAccPredicate] = true;
108 
109  lqIdx = -1;
110  sqIdx = -1;
111 
112  // Eventually make this a parameter.
113  threadNumber = 0;
114 
115  // Initialize the fault to be NoFault.
116  fault = NoFault;
117 
118 #ifndef NDEBUG
119  ++cpu->instcount;
120 
121  if (cpu->instcount > 1500) {
122 #ifdef DEBUG
123  cpu->dumpInsts();
124  dumpSNList();
125 #endif
126  assert(cpu->instcount <= 1500);
127  }
128 
129  DPRINTF(DynInst,
130  "DynInst: [sn:%lli] Instruction created. Instcount for %s = %i\n",
131  seqNum, cpu->name(), cpu->instcount);
132 #endif
133 
134 #ifdef DEBUG
135  cpu->snList.insert(seqNum);
136 #endif
137 
138 }
139 
140 template <class Impl>
142 {
143  if (memData) {
144  delete [] memData;
145  }
146 
147  if (traceData) {
148  delete traceData;
149  }
150 
151  fault = NoFault;
152 
153 #ifndef NDEBUG
154  --cpu->instcount;
155 
156  DPRINTF(DynInst,
157  "DynInst: [sn:%lli] Instruction destroyed. Instcount for %s = %i\n",
158  seqNum, cpu->name(), cpu->instcount);
159 #endif
160 #ifdef DEBUG
161  cpu->snList.erase(seqNum);
162 #endif
163 
164 }
165 
166 #ifdef DEBUG
167 template <class Impl>
168 void
170 {
171  std::set<InstSeqNum>::iterator sn_it = cpu->snList.begin();
172 
173  int count = 0;
174  while (sn_it != cpu->snList.end()) {
175  cprintf("%i: [sn:%lli] not destroyed\n", count, (*sn_it));
176  count++;
177  sn_it++;
178  }
179 }
180 #endif
181 
182 template <class Impl>
183 void
185 {
186  cprintf("T%d : %#08d `", threadNumber, pc.instAddr());
187  std::cout << staticInst->disassemble(pc.instAddr());
188  cprintf("'\n");
189 }
190 
191 template <class Impl>
192 void
193 BaseDynInst<Impl>::dump(std::string &outstring)
194 {
195  std::ostringstream s;
196  s << "T" << threadNumber << " : 0x" << pc.instAddr() << " "
197  << staticInst->disassemble(pc.instAddr());
198 
199  outstring = s.str();
200 }
201 
202 template <class Impl>
203 void
205 {
206  DPRINTF(IQ, "[sn:%lli] has %d ready out of %d sources. RTI %d)\n",
207  seqNum, readyRegs+1, numSrcRegs(), readyToIssue());
208  if (++readyRegs == numSrcRegs()) {
209  setCanIssue();
210  }
211 }
212 
213 template <class Impl>
214 void
216 {
217  _readySrcRegIdx[src_idx] = true;
218 
219  markSrcRegReady();
220 }
221 
222 template <class Impl>
223 bool
225 {
226  // For now I am assuming that src registers 1..n-1 are the ones that the
227  // EA calc depends on. (i.e. src reg 0 is the source of the data to be
228  // stored)
229 
230  for (int i = 1; i < numSrcRegs(); ++i) {
231  if (!_readySrcRegIdx[i])
232  return false;
233  }
234 
235  return true;
236 }
237 
238 
239 
240 template <class Impl>
241 void
243 {
244  status.set(Squashed);
245 
246  if (!isPinnedRegsRenamed() || isPinnedRegsSquashDone())
247  return;
248 
249  // This inst has been renamed already so it may go through rename
250  // again (e.g. if the squash is due to memory access order violation).
251  // Reset the write counters for all pinned destination register to ensure
252  // that they are in a consistent state for a possible re-rename. This also
253  // ensures that dest regs will be pinned to the same phys register if
254  // re-rename happens.
255  for (int idx = 0; idx < numDestRegs(); idx++) {
256  PhysRegIdPtr phys_dest_reg = renamedDestRegIdx(idx);
257  if (phys_dest_reg->isPinned()) {
258  phys_dest_reg->incrNumPinnedWrites();
259  if (isPinnedRegsWritten())
260  phys_dest_reg->incrNumPinnedWritesToComplete();
261  }
262  }
263  setPinnedRegsSquashDone();
264 }
265 
266 
267 
268 #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:200
BaseDynInst::seqNum
InstSeqNum seqNum
The sequence number of the instruction.
Definition: base_dyn_inst.hh:150
BaseDynInst::ImplCPU
Impl::CPUType ImplCPU
Definition: base_dyn_inst.hh:80
PhysRegId::incrNumPinnedWritesToComplete
void incrNumPinnedWritesToComplete()
Definition: reg_class.hh:343
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:242
base_dyn_inst.hh
exetrace.hh
BaseDynInst::~BaseDynInst
~BaseDynInst()
BaseDynInst destructor.
Definition: base_dyn_inst_impl.hh:141
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:204
PhysRegId::incrNumPinnedWrites
void incrNumPinnedWrites()
Definition: reg_class.hh:328
BaseDynInst::pc
TheISA::PCState pc
PC state for this instruction.
Definition: base_dyn_inst.hh:176
cprintf
void cprintf(const char *format, const Args &...args)
Definition: cprintf.hh:152
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:240
BaseDynInst
Definition: base_dyn_inst.hh:76
cprintf.hh
InstSeqNum
uint64_t InstSeqNum
Definition: inst_seq.hh:37
NoFault
constexpr decltype(nullptr) NoFault
Definition: types.hh:245
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:224
PhysRegId::isPinned
bool isPinned() const
Definition: reg_class.hh:330
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:184
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:91

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