gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
dyn_inst.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010, 2016 ARM Limited
3  * Copyright (c) 2013 Advanced Micro Devices, Inc.
4  * All rights reserved
5  *
6  * The license below extends only to copyright in the software and shall
7  * not be construed as granting a license to any other intellectual
8  * property including but not limited to intellectual property relating
9  * to a hardware implementation of the functionality of the software
10  * licensed hereunder. You may use the software subject to the license
11  * terms below provided that you ensure that this notice is replicated
12  * unmodified and in its entirety in all distributions of the software,
13  * modified or unmodified, in source code or in binary form.
14  *
15  * Copyright (c) 2004-2006 The Regents of The University of Michigan
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions are
20  * met: redistributions of source code must retain the above copyright
21  * notice, this list of conditions and the following disclaimer;
22  * redistributions in binary form must reproduce the above copyright
23  * notice, this list of conditions and the following disclaimer in the
24  * documentation and/or other materials provided with the distribution;
25  * neither the name of the copyright holders nor the names of its
26  * contributors may be used to endorse or promote products derived from
27  * this software without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Authors: Kevin Lim
42  */
43 
44 #ifndef __CPU_O3_DYN_INST_HH__
45 #define __CPU_O3_DYN_INST_HH__
46 
47 #include <array>
48 
49 #include "arch/isa_traits.hh"
50 #include "config/the_isa.hh"
51 #include "cpu/o3/cpu.hh"
52 #include "cpu/o3/isa_specific.hh"
53 #include "cpu/base_dyn_inst.hh"
54 #include "cpu/inst_seq.hh"
55 #include "cpu/reg_class.hh"
56 
57 class Packet;
58 
59 template <class Impl>
60 class BaseO3DynInst : public BaseDynInst<Impl>
61 {
62  public:
64  typedef typename Impl::O3CPU O3CPU;
65 
73 
74  enum {
75  MaxInstSrcRegs = TheISA::MaxInstSrcRegs, //< Max source regs
76  MaxInstDestRegs = TheISA::MaxInstDestRegs //< Max dest regs
77  };
78 
79  public:
83  InstSeqNum seq_num, O3CPU *cpu);
84 
86  BaseO3DynInst(const StaticInstPtr &_staticInst,
87  const StaticInstPtr &_macroop);
88 
90 
92  Fault execute();
93 
96 
99 
100  private:
102  void initVars();
103 
104  protected:
109 
111  std::array<RegVal, TheISA::MaxMiscDestRegs> _destMiscRegVal;
112 
117  std::array<short, TheISA::MaxMiscDestRegs> _destMiscRegIdx;
118 
121 
122 
123  public:
124 #if TRACING_ON
125 
126  Tick fetchTick; // instruction fetch is completed.
127  int32_t decodeTick; // instruction enters decode phase
128  int32_t renameTick; // instruction enters rename phase
129  int32_t dispatchTick;
130  int32_t issueTick;
131  int32_t completeTick;
132  int32_t commitTick;
133  int32_t storeTick;
134 #endif
135 
139  RegVal
140  readMiscReg(int misc_reg) override
141  {
142  return this->cpu->readMiscReg(misc_reg, this->threadNumber);
143  }
144 
148  void
149  setMiscReg(int misc_reg, RegVal val) override
150  {
157  for (int idx = 0; idx < _numDestMiscRegs; idx++) {
158  if (_destMiscRegIdx[idx] == misc_reg) {
159  _destMiscRegVal[idx] = val;
160  return;
161  }
162  }
163 
164  assert(_numDestMiscRegs < TheISA::MaxMiscDestRegs);
165  _destMiscRegIdx[_numDestMiscRegs] = misc_reg;
166  _destMiscRegVal[_numDestMiscRegs] = val;
167  _numDestMiscRegs++;
168  }
169 
173  RegVal
174  readMiscRegOperand(const StaticInst *si, int idx) override
175  {
176  const RegId& reg = si->srcRegIdx(idx);
177  assert(reg.isMiscReg());
178  return this->cpu->readMiscReg(reg.index(), this->threadNumber);
179  }
180 
184  void
185  setMiscRegOperand(const StaticInst *si, int idx, RegVal val) override
186  {
187  const RegId& reg = si->destRegIdx(idx);
188  assert(reg.isMiscReg());
189  setMiscReg(reg.index(), val);
190  }
191 
193  void
195  {
196  // @todo: Pretty convoluted way to avoid squashing from happening when
197  // using the TC during an instruction's execution (specifically for
198  // instructions that have side-effects that use the TC). Fix this.
199  // See cpu/o3/dyn_inst_impl.hh.
200  bool no_squash_from_TC = this->thread->noSquashFromTC;
201  this->thread->noSquashFromTC = true;
202 
203  for (int i = 0; i < _numDestMiscRegs; i++)
204  this->cpu->setMiscReg(
205  _destMiscRegIdx[i], _destMiscRegVal[i], this->threadNumber);
206 
207  this->thread->noSquashFromTC = no_squash_from_TC;
208  }
209 
211  {
212 
213  for (int idx = 0; idx < this->numDestRegs(); idx++) {
214  PhysRegIdPtr prev_phys_reg = this->prevDestRegIdx(idx);
215  const RegId& original_dest_reg =
216  this->staticInst->destRegIdx(idx);
217  switch (original_dest_reg.classValue()) {
218  case IntRegClass:
219  this->setIntRegOperand(this->staticInst.get(), idx,
220  this->cpu->readIntReg(prev_phys_reg));
221  break;
222  case FloatRegClass:
223  this->setFloatRegOperandBits(this->staticInst.get(), idx,
224  this->cpu->readFloatReg(prev_phys_reg));
225  break;
226  case VecRegClass:
227  this->setVecRegOperand(this->staticInst.get(), idx,
228  this->cpu->readVecReg(prev_phys_reg));
229  break;
230  case VecElemClass:
231  this->setVecElemOperand(this->staticInst.get(), idx,
232  this->cpu->readVecElem(prev_phys_reg));
233  break;
234  case VecPredRegClass:
235  this->setVecPredRegOperand(this->staticInst.get(), idx,
236  this->cpu->readVecPredReg(prev_phys_reg));
237  break;
238  case CCRegClass:
239  this->setCCRegOperand(this->staticInst.get(), idx,
240  this->cpu->readCCReg(prev_phys_reg));
241  break;
242  case MiscRegClass:
243  // no need to forward misc reg values
244  break;
245  default:
246  panic("Unknown register class: %d",
247  (int)original_dest_reg.classValue());
248  }
249  }
250  }
252  void trap(const Fault &fault);
253 
255  void syscall(Fault *fault) override;
256 
257  public:
258 
259  // The register accessor methods provide the index of the
260  // instruction's operand (e.g., 0 or 1), not the architectural
261  // register index, to simplify the implementation of register
262  // renaming. We find the architectural register index by indexing
263  // into the instruction's own operand index table. Note that a
264  // raw pointer to the StaticInst is provided instead of a
265  // ref-counted StaticInstPtr to redice overhead. This is fine as
266  // long as these methods don't copy the pointer into any long-term
267  // storage (which is pretty hard to imagine they would have reason
268  // to do).
269 
270  RegVal
271  readIntRegOperand(const StaticInst *si, int idx) override
272  {
273  return this->cpu->readIntReg(this->_srcRegIdx[idx]);
274  }
275 
276  RegVal
277  readFloatRegOperandBits(const StaticInst *si, int idx) override
278  {
279  return this->cpu->readFloatReg(this->_srcRegIdx[idx]);
280  }
281 
282  const VecRegContainer&
283  readVecRegOperand(const StaticInst *si, int idx) const override
284  {
285  return this->cpu->readVecReg(this->_srcRegIdx[idx]);
286  }
287 
292  getWritableVecRegOperand(const StaticInst *si, int idx) override
293  {
294  return this->cpu->getWritableVecReg(this->_destRegIdx[idx]);
295  }
296 
301  readVec8BitLaneOperand(const StaticInst *si, int idx) const override
302  {
303  return cpu->template readVecLane<uint8_t>(_srcRegIdx[idx]);
304  }
305 
308  readVec16BitLaneOperand(const StaticInst *si, int idx) const override
309  {
310  return cpu->template readVecLane<uint16_t>(_srcRegIdx[idx]);
311  }
312 
315  readVec32BitLaneOperand(const StaticInst *si, int idx) const override
316  {
317  return cpu->template readVecLane<uint32_t>(_srcRegIdx[idx]);
318  }
319 
322  readVec64BitLaneOperand(const StaticInst *si, int idx) const override
323  {
324  return cpu->template readVecLane<uint64_t>(_srcRegIdx[idx]);
325  }
326 
328  template <typename LD>
329  void
330  setVecLaneOperandT(const StaticInst *si, int idx, const LD& val)
331  {
332  return cpu->template setVecLane(_destRegIdx[idx], val);
333  }
334  virtual void
335  setVecLaneOperand(const StaticInst *si, int idx,
336  const LaneData<LaneSize::Byte>& val) override
337  {
338  return setVecLaneOperandT(si, idx, val);
339  }
340  virtual void
341  setVecLaneOperand(const StaticInst *si, int idx,
342  const LaneData<LaneSize::TwoByte>& val) override
343  {
344  return setVecLaneOperandT(si, idx, val);
345  }
346  virtual void
347  setVecLaneOperand(const StaticInst *si, int idx,
348  const LaneData<LaneSize::FourByte>& val) override
349  {
350  return setVecLaneOperandT(si, idx, val);
351  }
352  virtual void
353  setVecLaneOperand(const StaticInst *si, int idx,
354  const LaneData<LaneSize::EightByte>& val) override
355  {
356  return setVecLaneOperandT(si, idx, val);
357  }
360  VecElem readVecElemOperand(const StaticInst *si, int idx) const override
361  {
362  return this->cpu->readVecElem(this->_srcRegIdx[idx]);
363  }
364 
365  const VecPredRegContainer&
366  readVecPredRegOperand(const StaticInst *si, int idx) const override
367  {
368  return this->cpu->readVecPredReg(this->_srcRegIdx[idx]);
369  }
370 
372  getWritableVecPredRegOperand(const StaticInst *si, int idx) override
373  {
374  return this->cpu->getWritableVecPredReg(this->_destRegIdx[idx]);
375  }
376 
377  RegVal
378  readCCRegOperand(const StaticInst *si, int idx) override
379  {
380  return this->cpu->readCCReg(this->_srcRegIdx[idx]);
381  }
382 
386  void
387  setIntRegOperand(const StaticInst *si, int idx, RegVal val) override
388  {
389  this->cpu->setIntReg(this->_destRegIdx[idx], val);
391  }
392 
393  void
394  setFloatRegOperandBits(const StaticInst *si, int idx, RegVal val) override
395  {
396  this->cpu->setFloatReg(this->_destRegIdx[idx], val);
398  }
399 
400  void
401  setVecRegOperand(const StaticInst *si, int idx,
402  const VecRegContainer& val) override
403  {
404  this->cpu->setVecReg(this->_destRegIdx[idx], val);
406  }
407 
408  void setVecElemOperand(const StaticInst *si, int idx,
409  const VecElem val) override
410  {
411  int reg_idx = idx;
412  this->cpu->setVecElem(this->_destRegIdx[reg_idx], val);
414  }
415 
416  void
418  const VecPredRegContainer& val) override
419  {
420  this->cpu->setVecPredReg(this->_destRegIdx[idx], val);
422  }
423 
424  void setCCRegOperand(const StaticInst *si, int idx, RegVal val) override
425  {
426  this->cpu->setCCReg(this->_destRegIdx[idx], val);
428  }
429 };
430 
431 #endif // __CPU_O3_ALPHA_DYN_INST_HH__
432 
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
void setFloatRegOperandBits(const StaticInst *si, int idx, RegVal val)
Records an fp register being set to an integer value.
Bitfield< 5, 3 > reg
Definition: types.hh:89
bool isMiscReg() const
true if it is a condition-code physical register.
Definition: reg_class.hh:167
Floating-point register.
Definition: reg_class.hh:58
Bitfield< 7 > i
Vector Register Abstraction This generic class is the model in a particularization of MVC...
Definition: vec_reg.hh:160
Control (misc) register.
Definition: reg_class.hh:65
const VecPredRegContainer & readVecPredRegOperand(const StaticInst *si, int idx) const override
Predicate registers interface.
Definition: dyn_inst.hh:366
Fault fault
The kind of fault this instruction has generated.
void setVecPredRegOperand(const StaticInst *si, int idx, const VecPredRegContainer &val)
Record a vector register being set to a value.
void setCCRegOperand(const StaticInst *si, int idx, RegVal val) override
Records a CC register being set to a value.
Definition: dyn_inst.hh:424
std::array< PhysRegIdPtr, TheISA::MaxInstDestRegs > _destRegIdx
Physical register index of the destination registers of this instruction.
uint64_t RegVal
Definition: types.hh:168
VecPredRegContainer & getWritableVecPredRegOperand(const StaticInst *si, int idx) override
Gets destination predicate register operand for modification.
Definition: dyn_inst.hh:372
const RegId & srcRegIdx(int i) const
Return logical index (architectural reg num) of i&#39;th source reg.
Definition: static_inst.hh:220
const VecRegContainer & readVecRegOperand(const StaticInst *si, int idx) const override
Vector Register Interfaces.
Definition: dyn_inst.hh:283
void setVecLaneOperandT(const StaticInst *si, int idx, const LD &val)
Write a lane of the destination vector operand.
Definition: dyn_inst.hh:330
Fault completeAcc(PacketPtr pkt)
Completes the access.
void setVecElemOperand(const StaticInst *si, int idx, const VecElem val) override
Record a vector register being set to a value.
Definition: dyn_inst.hh:408
void trap(const Fault &fault)
Traps to handle specified fault.
const int MaxInstSrcRegs
Definition: registers.hh:59
ConstVecLane8 readVec8BitLaneOperand(const StaticInst *si, int idx) const override
Vector Register Lane Interfaces.
Definition: dyn_inst.hh:301
RegVal readFloatRegOperandBits(const StaticInst *si, int idx) override
Reads a floating point register in its binary format, instead of by value.
Definition: dyn_inst.hh:277
Bitfield< 63 > val
Definition: misc.hh:771
void setVecElemOperand(const StaticInst *si, int idx, const VecElem val)
Record a vector register being set to a value.
uint32_t MachInst
Definition: types.hh:40
const int MaxMiscDestRegs
Definition: registers.hh:47
VecRegContainer & getWritableVecRegOperand(const StaticInst *si, int idx) override
Read destination vector register operand for modification.
Definition: dyn_inst.hh:292
Bitfield< 15, 0 > si
Definition: types.hh:55
void syscall(Fault *fault) override
Emulates a syscall.
ConstVecLane16 readVec16BitLaneOperand(const StaticInst *si, int idx) const override
Reads source vector 16bit operand.
Definition: dyn_inst.hh:308
LaneSize is an abstraction of a LS byte value for the execution and thread contexts to handle values ...
Definition: vec_reg.hh:457
Vector Register Native Elem lane.
Definition: reg_class.hh:62
uint8_t _numDestMiscRegs
Number of destination misc.
Definition: dyn_inst.hh:120
void setVecRegOperand(const StaticInst *si, int idx, const VecRegContainer &val) override
Record a vector register being set to a value.
Definition: dyn_inst.hh:401
::DummyVecPredRegContainer VecPredRegContainer
Definition: registers.hh:60
uint64_t Tick
Tick count type.
Definition: types.hh:63
::DummyVecRegContainer VecRegContainer
Definition: registers.hh:53
void setIntRegOperand(const StaticInst *si, int idx, RegVal val) override
Definition: dyn_inst.hh:387
RegVal readMiscRegOperand(const StaticInst *si, int idx) override
Reads a misc.
Definition: dyn_inst.hh:174
std::array< PhysRegIdPtr, TheISA::MaxInstSrcRegs > _srcRegIdx
Physical register index of the source registers of this instruction.
RegVal readMiscReg(int misc_reg) override
Reads a misc.
Definition: dyn_inst.hh:140
Condition-code register.
Definition: reg_class.hh:64
virtual void setVecLaneOperand(const StaticInst *si, int idx, const LaneData< LaneSize::EightByte > &val) override
Definition: dyn_inst.hh:353
uint64_t InstSeqNum
Definition: inst_seq.hh:40
std::array< short, TheISA::MaxMiscDestRegs > _destMiscRegIdx
Indexes of the destination misc.
Definition: dyn_inst.hh:117
BaseO3DynInst(const StaticInstPtr &staticInst, const StaticInstPtr &macroop, TheISA::PCState pc, TheISA::PCState predPC, InstSeqNum seq_num, O3CPU *cpu)
BaseDynInst constructor given a binary instruction.
const StaticInstPtr staticInst
The StaticInst used by this BaseDynInst.
TheISA::PCState pc
PC state for this instruction.
Fault execute()
Executes the instruction.
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
VecElem readVecElemOperand(const StaticInst *si, int idx) const override
Vector Elem Interfaces.
Definition: dyn_inst.hh:360
ConstVecLane32 readVec32BitLaneOperand(const StaticInst *si, int idx) const override
Reads source vector 32bit operand.
Definition: dyn_inst.hh:315
void updateMiscRegs()
Called at the commit stage to update the misc.
Definition: dyn_inst.hh:194
static constexpr auto NumVecElemPerVecReg
Definition: dyn_inst.hh:71
void setIntRegOperand(const StaticInst *si, int idx, RegVal val)
Records an integer register being set to a value.
PhysRegIdPtr prevDestRegIdx(int idx) const
Returns the physical register index of the previous physical register that remapped to the same logic...
Physical register ID.
Definition: reg_class.hh:229
std::array< RegVal, TheISA::MaxMiscDestRegs > _destMiscRegVal
Values to be written to the destination misc.
Definition: dyn_inst.hh:111
void setMiscReg(int misc_reg, RegVal val) override
Sets a misc.
Definition: dyn_inst.hh:149
ImplCPU * cpu
Pointer to the Impl&#39;s CPU object.
TheISA::MachInst MachInst
Binary machine instruction type.
Definition: dyn_inst.hh:67
Impl::O3CPU O3CPU
Typedef for the CPU.
Definition: dyn_inst.hh:64
GenericISA::SimplePCState< MachInst > PCState
Definition: types.hh:43
const RegClass & classValue() const
Class accessor.
Definition: reg_class.hh:206
Generic predicate register container.
Definition: vec_pred_reg.hh:51
int8_t numDestRegs() const
Returns the number of destination registers.
void setVecPredRegOperand(const StaticInst *si, int idx, const VecPredRegContainer &val) override
Record a vector register being set to a value.
Definition: dyn_inst.hh:417
void setFloatRegOperandBits(const StaticInst *si, int idx, RegVal val) override
Records an fp register being set to an integer value.
Definition: dyn_inst.hh:394
Base, ISA-independent static instruction class.
Definition: static_inst.hh:83
const RegIndex & index() const
Index accessors.
Definition: reg_class.hh:179
const RegId & destRegIdx(int i) const
Return logical index (architectural reg num) of i&#39;th destination reg.
Definition: static_inst.hh:216
Defines a dynamic instruction context.
const StaticInstPtr macroop
The Macroop if one exists.
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:79
Integer register.
Definition: reg_class.hh:57
RegVal readIntRegOperand(const StaticInst *si, int idx) override
Reads an integer register.
Definition: dyn_inst.hh:271
ConstVecLane64 readVec64BitLaneOperand(const StaticInst *si, int idx) const override
Reads source vector 64bit operand.
Definition: dyn_inst.hh:322
::DummyVecElem VecElem
Definition: registers.hh:50
Vector Register.
Definition: reg_class.hh:60
TheISA::PCState predPC
Predicted PC state after this instruction.
void setCCRegOperand(const StaticInst *si, int idx, RegVal val)
Records a CC register being set to a value.
ThreadID threadNumber
The thread this instruction is from.
virtual void setVecLaneOperand(const StaticInst *si, int idx, const LaneData< LaneSize::FourByte > &val) override
Definition: dyn_inst.hh:347
Vector Lane abstraction Another view of a container.
Definition: vec_reg.hh:262
constexpr unsigned NumVecElemPerVecReg
Definition: registers.hh:54
void setVecRegOperand(const StaticInst *si, int idx, const VecRegContainer &val)
Record a vector register being set to a value.
TheISA::VecElem VecElem
Definition: exec_context.hh:78
void setMiscRegOperand(const StaticInst *si, int idx, RegVal val) override
Sets a misc.
Definition: dyn_inst.hh:185
T * get() const
Directly access the pointer itself without taking a reference.
Definition: refcnt.hh:221
std::shared_ptr< FaultBase > Fault
Definition: types.hh:240
virtual void setVecLaneOperand(const StaticInst *si, int idx, const LaneData< LaneSize::TwoByte > &val) override
Definition: dyn_inst.hh:341
void forwardOldRegs()
Definition: dyn_inst.hh:210
ImplState * thread
Pointer to the thread state.
void initVars()
Initializes variables.
virtual void setVecLaneOperand(const StaticInst *si, int idx, const LaneData< LaneSize::Byte > &val) override
Write a lane of the destination vector operand.
Definition: dyn_inst.hh:335
RegVal readCCRegOperand(const StaticInst *si, int idx) override
Definition: dyn_inst.hh:378
Fault initiateAcc()
Initiates the access.

Generated on Fri Feb 28 2020 16:26:59 for gem5 by doxygen 1.8.13