gem5  v22.1.0.0
dyn_inst.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014, 2016,2018 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/dyn_inst.hh"
39 
40 #include <iomanip>
41 #include <sstream>
42 
43 #include "cpu/base.hh"
44 #include "cpu/minor/trace.hh"
45 #include "cpu/null_static_inst.hh"
46 #include "cpu/reg_class.hh"
47 #include "debug/MinorExecute.hh"
48 #include "enums/OpClass.hh"
49 
50 namespace gem5
51 {
52 
54 namespace minor
55 {
56 
62 
63 std::ostream &
64 operator <<(std::ostream &os, const InstId &id)
65 {
66  os << id.threadId << '/' << id.streamSeqNum << '.'
67  << id.predictionSeqNum << '/' << id.lineSeqNum;
68 
69  /* Not all structures have fetch and exec sequence numbers */
70  if (id.fetchSeqNum != 0) {
71  os << '/' << id.fetchSeqNum;
72  if (id.execSeqNum != 0)
73  os << '.' << id.execSeqNum;
74  }
75 
76  return os;
77 }
78 
80  auto *inst = new MinorDynInst(nullStaticInstPtr);
81  assert(inst->isBubble());
82  // Make bubbleInst immortal.
83  inst->incref();
84  return inst;
85 }();
86 
87 bool
89 {
90  assert(staticInst);
91  return !(staticInst->isMicroop() && !staticInst->isLastMicroop());
92 }
93 
94 bool
96 {
97  return isInst() && staticInst->opClass() == No_OpClass;
98 }
99 
100 void
101 MinorDynInst::reportData(std::ostream &os) const
102 {
103  if (isBubble())
104  os << "-";
105  else if (isFault())
106  os << "F;" << id;
107  else if (translationFault != NoFault)
108  os << "TF;" << id;
109  else
110  os << id;
111 }
112 
113 std::ostream &
114 operator <<(std::ostream &os, const MinorDynInst &inst)
115 {
116  os << inst.id << " pc: 0x"
117  << std::hex << inst.pc->instAddr() << std::dec << " (";
118 
119  if (inst.isFault())
120  os << "fault: \"" << inst.fault->name() << '"';
121  else if (inst.translationFault != NoFault)
122  os << "translation fault: \"" << inst.translationFault->name() << '"';
123  else if (inst.staticInst)
124  os << inst.staticInst->getName();
125  else
126  os << "bubble";
127 
128  os << ')';
129 
130  return os;
131 }
132 
135 static void
136 printRegName(std::ostream &os, const RegId& reg)
137 {
138  switch (reg.classValue()) {
139  case InvalidRegClass:
140  os << 'z';
141  break;
142  case MiscRegClass:
143  {
144  RegIndex misc_reg = reg.index();
145  os << 'm' << misc_reg << '(' << reg << ')';
146  }
147  break;
148  case FloatRegClass:
149  os << 'f' << reg.index();
150  break;
151  case VecRegClass:
152  os << 'v' << reg.index();
153  break;
154  case VecElemClass:
155  os << reg;
156  break;
157  case IntRegClass:
158  os << 'r' << reg.index();
159  break;
160  case CCRegClass:
161  os << 'c' << reg.index();
162  break;
163  default:
164  panic("Unknown register class: %d", (int)reg.classValue());
165  }
166 }
167 
168 void
169 MinorDynInst::minorTraceInst(const Named &named_object) const
170 {
171  if (isFault()) {
172  minorInst(named_object, "id=F;%s addr=0x%x fault=\"%s\"\n",
173  id, pc->instAddr(), fault->name());
174  } else {
175  unsigned int num_src_regs = staticInst->numSrcRegs();
176  unsigned int num_dest_regs = staticInst->numDestRegs();
177 
178  std::ostringstream regs_str;
179 
180  /* Format lists of src and dest registers for microops and
181  * 'full' instructions */
182  if (!staticInst->isMacroop()) {
183  regs_str << " srcRegs=";
184 
185  unsigned int src_reg = 0;
186  while (src_reg < num_src_regs) {
187  printRegName(regs_str, staticInst->srcRegIdx(src_reg));
188 
189  src_reg++;
190  if (src_reg != num_src_regs)
191  regs_str << ',';
192  }
193 
194  regs_str << " destRegs=";
195 
196  unsigned int dest_reg = 0;
197  while (dest_reg < num_dest_regs) {
198  printRegName(regs_str, staticInst->destRegIdx(dest_reg));
199 
200  dest_reg++;
201  if (dest_reg != num_dest_regs)
202  regs_str << ',';
203  }
204 
205  ccprintf(regs_str, " extMachInst=%160x", staticInst->getEMI());
206  }
207 
208  std::ostringstream flags;
209  staticInst->printFlags(flags, " ");
210 
211  minorInst(named_object, "id=%s addr=0x%x inst=\"%s\" class=%s"
212  " flags=\"%s\"%s%s\n",
213  id, pc->instAddr(),
214  (staticInst->opClass() == No_OpClass ?
215  "(invalid)" : staticInst->disassemble(0,NULL)),
216  enums::OpClassStrings[staticInst->opClass()],
217  flags.str(),
218  regs_str.str(),
219  (predictedTaken ? " predictedTaken" : ""));
220  }
221 }
222 
224 {
225  if (traceData)
226  delete traceData;
227 }
228 
229 } // namespace minor
230 } // namespace gem5
Interface for things with names.
Definition: named.hh:39
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:91
void printFlags(std::ostream &outs, const std::string &separator) const
Print a separator separated list of this instruction's set flag names on the given stream.
Definition: static_inst.cc:71
virtual const std::string & disassemble(Addr pc, const loader::SymbolTable *symtab=nullptr) const
Return string representation of disassembled instruction.
Definition: static_inst.cc:60
virtual uint64_t getEMI() const
Definition: static_inst.hh:236
uint8_t numSrcRegs() const
Number of source registers.
Definition: static_inst.hh:123
OpClass opClass() const
Operation class. Used to select appropriate function unit in issue.
Definition: static_inst.hh:210
const RegId & srcRegIdx(int i) const
Return logical index (architectural reg num) of i'th source reg.
Definition: static_inst.hh:225
uint8_t numDestRegs() const
Number of destination registers.
Definition: static_inst.hh:125
bool isMacroop() const
Definition: static_inst.hh:185
std::string getName()
Return name of machine instruction.
Definition: static_inst.hh:351
bool isLastMicroop() const
Definition: static_inst.hh:188
const RegId & destRegIdx(int i) const
Return logical index (architectural reg num) of i'th destination reg.
Definition: static_inst.hh:215
bool isMicroop() const
Definition: static_inst.hh:186
Id for lines and instructions.
Definition: dyn_inst.hh:77
static const InstSeqNum firstFetchSeqNum
Definition: dyn_inst.hh:84
static const InstSeqNum firstExecSeqNum
Definition: dyn_inst.hh:85
static const InstSeqNum firstLineSeqNum
Definition: dyn_inst.hh:83
static const InstSeqNum firstStreamSeqNum
First sequence numbers to use in initialisation of the pipeline and to be expected on the first line/...
Definition: dyn_inst.hh:81
static const InstSeqNum firstPredictionSeqNum
Definition: dyn_inst.hh:82
Dynamic instruction for Minor.
Definition: dyn_inst.hh:164
bool isFault() const
Is this a fault rather than instruction.
Definition: dyn_inst.hh:254
bool isNoCostInst() const
Is this an instruction that can be executed ‘for free’ and needn't spend time in an FU.
Definition: dyn_inst.cc:95
bool isInst() const
Is this a real instruction.
Definition: dyn_inst.hh:257
Fault translationFault
Translation fault in case of a mem ref.
Definition: dyn_inst.hh:204
trace::InstRecord * traceData
Trace information for this instruction's execution.
Definition: dyn_inst.hh:176
std::unique_ptr< PCStateBase > pc
The fetch address of this instruction.
Definition: dyn_inst.hh:179
void minorTraceInst(const Named &named_object) const
Print (possibly verbose) instruction information for MinorTrace using the given Named object's name.
Definition: dyn_inst.cc:169
const StaticInstPtr staticInst
Definition: dyn_inst.hh:171
bool isLastOpInInst() const
Assuming this is not a fault, is this instruction either a whole instruction or the last microop from...
Definition: dyn_inst.cc:88
void reportData(std::ostream &os) const
ReportIF interface.
Definition: dyn_inst.cc:101
static MinorDynInstPtr bubbleInst
A prototypical bubble instruction.
Definition: dyn_inst.hh:168
bool predictedTaken
This instruction was predicted to change control flow and the following instructions will have a newe...
Definition: dyn_inst.hh:190
Fault fault
This is actually a fault masquerading as an instruction.
Definition: dyn_inst.hh:182
bool isBubble() const
The BubbleIF interface.
Definition: dyn_inst.hh:248
This file contains miscellaneous classes and functions for formatting general trace information and a...
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
uint8_t flags
Definition: helpers.cc:66
The dynamic instruction and instruction/line id (sequence numbers) definition for Minor.
Bitfield< 5, 3 > reg
Definition: types.hh:92
Bitfield< 17 > os
Definition: misc.hh:810
static void printRegName(std::ostream &os, const RegId &reg)
Print a register in the form r<n>, f<n>, m<n>(<name>) for integer, float, and misc given an 'architec...
Definition: dyn_inst.cc:136
RefCountingPtr< MinorDynInst > MinorDynInstPtr
MinorDynInsts are currently reference counted.
Definition: dyn_inst.hh:69
std::ostream & operator<<(std::ostream &os, const InstId &id)
Print this id in the usual slash-separated format expected by MinorTrace.
Definition: dyn_inst.cc:64
void minorInst(const Named &named, const char *fmt, Args ...args)
DPRINTFN for MinorTrace MinorInst line reporting.
Definition: trace.hh:75
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint16_t RegIndex
Definition: types.hh:176
const StaticInstPtr nullStaticInstPtr
Statically allocated null StaticInstPtr.
constexpr decltype(nullptr) NoFault
Definition: types.hh:253
uint64_t InstSeqNum
Definition: inst_seq.hh:40
@ FloatRegClass
Floating-point register.
Definition: reg_class.hh:61
@ CCRegClass
Condition-code register.
Definition: reg_class.hh:67
@ VecRegClass
Vector Register.
Definition: reg_class.hh:63
@ IntRegClass
Integer register.
Definition: reg_class.hh:60
@ InvalidRegClass
Definition: reg_class.hh:69
@ MiscRegClass
Control (misc) register.
Definition: reg_class.hh:68
@ VecElemClass
Vector Register Native Elem lane.
Definition: reg_class.hh:65
void ccprintf(cp::Print &print)
Definition: cprintf.hh:130
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
Minor contains all the definitions within the MinorCPU apart from the CPU class itself.

Generated on Wed Dec 21 2022 10:22:30 for gem5 by doxygen 1.9.1