gem5  v20.0.0.3
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 
42 #ifndef __CPU_O3_DYN_INST_HH__
43 #define __CPU_O3_DYN_INST_HH__
44 
45 #include <array>
46 
47 #include "arch/isa_traits.hh"
48 #include "config/the_isa.hh"
49 #include "cpu/o3/cpu.hh"
50 #include "cpu/o3/isa_specific.hh"
51 #include "cpu/base_dyn_inst.hh"
52 #include "cpu/inst_seq.hh"
53 #include "cpu/reg_class.hh"
54 
55 class Packet;
56 
57 template <class Impl>
58 class BaseO3DynInst : public BaseDynInst<Impl>
59 {
60  public:
62  typedef typename Impl::O3CPU O3CPU;
63 
71 
72  enum {
73  MaxInstSrcRegs = TheISA::MaxInstSrcRegs, //< Max source regs
74  MaxInstDestRegs = TheISA::MaxInstDestRegs //< Max dest regs
75  };
76 
77  public:
81  InstSeqNum seq_num, O3CPU *cpu);
82 
84  BaseO3DynInst(const StaticInstPtr &_staticInst,
85  const StaticInstPtr &_macroop);
86 
88 
90  Fault execute();
91 
94 
97 
98  private:
100  void initVars();
101 
102  protected:
107 
109  std::array<RegVal, TheISA::MaxMiscDestRegs> _destMiscRegVal;
110 
115  std::array<short, TheISA::MaxMiscDestRegs> _destMiscRegIdx;
116 
119 
120 
121  public:
122 #if TRACING_ON
123 
124  Tick fetchTick; // instruction fetch is completed.
125  int32_t decodeTick; // instruction enters decode phase
126  int32_t renameTick; // instruction enters rename phase
127  int32_t dispatchTick;
128  int32_t issueTick;
129  int32_t completeTick;
130  int32_t commitTick;
131  int32_t storeTick;
132 #endif
133 
137  RegVal
138  readMiscReg(int misc_reg) override
139  {
140  return this->cpu->readMiscReg(misc_reg, this->threadNumber);
141  }
142 
146  void
147  setMiscReg(int misc_reg, RegVal val) override
148  {
155  for (int idx = 0; idx < _numDestMiscRegs; idx++) {
156  if (_destMiscRegIdx[idx] == misc_reg) {
157  _destMiscRegVal[idx] = val;
158  return;
159  }
160  }
161 
162  assert(_numDestMiscRegs < TheISA::MaxMiscDestRegs);
163  _destMiscRegIdx[_numDestMiscRegs] = misc_reg;
164  _destMiscRegVal[_numDestMiscRegs] = val;
165  _numDestMiscRegs++;
166  }
167 
171  RegVal
172  readMiscRegOperand(const StaticInst *si, int idx) override
173  {
174  const RegId& reg = si->srcRegIdx(idx);
175  assert(reg.isMiscReg());
176  return this->cpu->readMiscReg(reg.index(), this->threadNumber);
177  }
178 
182  void
183  setMiscRegOperand(const StaticInst *si, int idx, RegVal val) override
184  {
185  const RegId& reg = si->destRegIdx(idx);
186  assert(reg.isMiscReg());
187  setMiscReg(reg.index(), val);
188  }
189 
191  void
193  {
194  // @todo: Pretty convoluted way to avoid squashing from happening when
195  // using the TC during an instruction's execution (specifically for
196  // instructions that have side-effects that use the TC). Fix this.
197  // See cpu/o3/dyn_inst_impl.hh.
198  bool no_squash_from_TC = this->thread->noSquashFromTC;
199  this->thread->noSquashFromTC = true;
200 
201  for (int i = 0; i < _numDestMiscRegs; i++)
202  this->cpu->setMiscReg(
203  _destMiscRegIdx[i], _destMiscRegVal[i], this->threadNumber);
204 
205  this->thread->noSquashFromTC = no_squash_from_TC;
206  }
207 
209  {
210 
211  for (int idx = 0; idx < this->numDestRegs(); idx++) {
212  PhysRegIdPtr prev_phys_reg = this->prevDestRegIdx(idx);
213  const RegId& original_dest_reg =
214  this->staticInst->destRegIdx(idx);
215  switch (original_dest_reg.classValue()) {
216  case IntRegClass:
217  this->setIntRegOperand(this->staticInst.get(), idx,
218  this->cpu->readIntReg(prev_phys_reg));
219  break;
220  case FloatRegClass:
221  this->setFloatRegOperandBits(this->staticInst.get(), idx,
222  this->cpu->readFloatReg(prev_phys_reg));
223  break;
224  case VecRegClass:
225  this->setVecRegOperand(this->staticInst.get(), idx,
226  this->cpu->readVecReg(prev_phys_reg));
227  break;
228  case VecElemClass:
229  this->setVecElemOperand(this->staticInst.get(), idx,
230  this->cpu->readVecElem(prev_phys_reg));
231  break;
232  case VecPredRegClass:
233  this->setVecPredRegOperand(this->staticInst.get(), idx,
234  this->cpu->readVecPredReg(prev_phys_reg));
235  break;
236  case CCRegClass:
237  this->setCCRegOperand(this->staticInst.get(), idx,
238  this->cpu->readCCReg(prev_phys_reg));
239  break;
240  case MiscRegClass:
241  // no need to forward misc reg values
242  break;
243  default:
244  panic("Unknown register class: %d",
245  (int)original_dest_reg.classValue());
246  }
247  }
248  }
250  void trap(const Fault &fault);
251 
253  void syscall(Fault *fault) override;
254 
255  public:
256 
257  // The register accessor methods provide the index of the
258  // instruction's operand (e.g., 0 or 1), not the architectural
259  // register index, to simplify the implementation of register
260  // renaming. We find the architectural register index by indexing
261  // into the instruction's own operand index table. Note that a
262  // raw pointer to the StaticInst is provided instead of a
263  // ref-counted StaticInstPtr to redice overhead. This is fine as
264  // long as these methods don't copy the pointer into any long-term
265  // storage (which is pretty hard to imagine they would have reason
266  // to do).
267 
268  RegVal
269  readIntRegOperand(const StaticInst *si, int idx) override
270  {
271  return this->cpu->readIntReg(this->_srcRegIdx[idx]);
272  }
273 
274  RegVal
275  readFloatRegOperandBits(const StaticInst *si, int idx) override
276  {
277  return this->cpu->readFloatReg(this->_srcRegIdx[idx]);
278  }
279 
280  const VecRegContainer&
281  readVecRegOperand(const StaticInst *si, int idx) const override
282  {
283  return this->cpu->readVecReg(this->_srcRegIdx[idx]);
284  }
285 
290  getWritableVecRegOperand(const StaticInst *si, int idx) override
291  {
292  return this->cpu->getWritableVecReg(this->_destRegIdx[idx]);
293  }
294 
299  readVec8BitLaneOperand(const StaticInst *si, int idx) const override
300  {
301  return cpu->template readVecLane<uint8_t>(_srcRegIdx[idx]);
302  }
303 
306  readVec16BitLaneOperand(const StaticInst *si, int idx) const override
307  {
308  return cpu->template readVecLane<uint16_t>(_srcRegIdx[idx]);
309  }
310 
313  readVec32BitLaneOperand(const StaticInst *si, int idx) const override
314  {
315  return cpu->template readVecLane<uint32_t>(_srcRegIdx[idx]);
316  }
317 
320  readVec64BitLaneOperand(const StaticInst *si, int idx) const override
321  {
322  return cpu->template readVecLane<uint64_t>(_srcRegIdx[idx]);
323  }
324 
326  template <typename LD>
327  void
328  setVecLaneOperandT(const StaticInst *si, int idx, const LD& val)
329  {
330  return cpu->template setVecLane(_destRegIdx[idx], val);
331  }
332  virtual void
333  setVecLaneOperand(const StaticInst *si, int idx,
334  const LaneData<LaneSize::Byte>& val) override
335  {
336  return setVecLaneOperandT(si, idx, val);
337  }
338  virtual void
339  setVecLaneOperand(const StaticInst *si, int idx,
340  const LaneData<LaneSize::TwoByte>& val) override
341  {
342  return setVecLaneOperandT(si, idx, val);
343  }
344  virtual void
345  setVecLaneOperand(const StaticInst *si, int idx,
346  const LaneData<LaneSize::FourByte>& val) override
347  {
348  return setVecLaneOperandT(si, idx, val);
349  }
350  virtual void
351  setVecLaneOperand(const StaticInst *si, int idx,
352  const LaneData<LaneSize::EightByte>& val) override
353  {
354  return setVecLaneOperandT(si, idx, val);
355  }
358  VecElem readVecElemOperand(const StaticInst *si, int idx) const override
359  {
360  return this->cpu->readVecElem(this->_srcRegIdx[idx]);
361  }
362 
363  const VecPredRegContainer&
364  readVecPredRegOperand(const StaticInst *si, int idx) const override
365  {
366  return this->cpu->readVecPredReg(this->_srcRegIdx[idx]);
367  }
368 
370  getWritableVecPredRegOperand(const StaticInst *si, int idx) override
371  {
372  return this->cpu->getWritableVecPredReg(this->_destRegIdx[idx]);
373  }
374 
375  RegVal
376  readCCRegOperand(const StaticInst *si, int idx) override
377  {
378  return this->cpu->readCCReg(this->_srcRegIdx[idx]);
379  }
380 
384  void
385  setIntRegOperand(const StaticInst *si, int idx, RegVal val) override
386  {
387  this->cpu->setIntReg(this->_destRegIdx[idx], val);
389  }
390 
391  void
392  setFloatRegOperandBits(const StaticInst *si, int idx, RegVal val) override
393  {
394  this->cpu->setFloatReg(this->_destRegIdx[idx], val);
396  }
397 
398  void
399  setVecRegOperand(const StaticInst *si, int idx,
400  const VecRegContainer& val) override
401  {
402  this->cpu->setVecReg(this->_destRegIdx[idx], val);
404  }
405 
406  void setVecElemOperand(const StaticInst *si, int idx,
407  const VecElem val) override
408  {
409  int reg_idx = idx;
410  this->cpu->setVecElem(this->_destRegIdx[reg_idx], val);
412  }
413 
414  void
416  const VecPredRegContainer& val) override
417  {
418  this->cpu->setVecPredReg(this->_destRegIdx[idx], val);
420  }
421 
422  void setCCRegOperand(const StaticInst *si, int idx, RegVal val) override
423  {
424  this->cpu->setCCReg(this->_destRegIdx[idx], val);
426  }
427 };
428 
429 #endif // __CPU_O3_ALPHA_DYN_INST_HH__
430 
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:163
uint32_t MachInst
Definition: types.hh:52
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:87
bool isMiscReg() const
true if it is a condition-code physical register.
Definition: reg_class.hh:161
Floating-point register.
Definition: reg_class.hh:54
Bitfield< 7 > i
Vector Register Abstraction This generic class is the model in a particularization of MVC...
Definition: vec_reg.hh:156
Control (misc) register.
Definition: reg_class.hh:61
const VecPredRegContainer & readVecPredRegOperand(const StaticInst *si, int idx) const override
Predicate registers interface.
Definition: dyn_inst.hh:364
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:422
std::array< PhysRegIdPtr, TheISA::MaxInstDestRegs > _destRegIdx
Physical register index of the destination registers of this instruction.
uint64_t RegVal
Definition: types.hh:166
VecPredRegContainer & getWritableVecPredRegOperand(const StaticInst *si, int idx) override
Gets destination predicate register operand for modification.
Definition: dyn_inst.hh:370
const RegId & srcRegIdx(int i) const
Return logical index (architectural reg num) of i&#39;th source reg.
Definition: static_inst.hh:222
const VecRegContainer & readVecRegOperand(const StaticInst *si, int idx) const override
Vector Register Interfaces.
Definition: dyn_inst.hh:281
void setVecLaneOperandT(const StaticInst *si, int idx, const LD &val)
Write a lane of the destination vector operand.
Definition: dyn_inst.hh:328
constexpr unsigned NumVecElemPerVecReg
Definition: registers.hh:66
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:406
void trap(const Fault &fault)
Traps to handle specified fault.
const int MaxInstSrcRegs
Definition: registers.hh:57
uint32_t VecElem
Definition: registers.hh:68
ConstVecLane8 readVec8BitLaneOperand(const StaticInst *si, int idx) const override
Vector Register Lane Interfaces.
Definition: dyn_inst.hh:299
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:275
Bitfield< 63 > val
Definition: misc.hh:769
void setVecElemOperand(const StaticInst *si, int idx, const VecElem val)
Record a vector register being set to a value.
VecRegContainer & getWritableVecRegOperand(const StaticInst *si, int idx) override
Read destination vector register operand for modification.
Definition: dyn_inst.hh:290
Bitfield< 15, 0 > si
Definition: types.hh:53
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:306
LaneSize is an abstraction of a LS byte value for the execution and thread contexts to handle values ...
Definition: vec_reg.hh:458
Vector Register Native Elem lane.
Definition: reg_class.hh:58
uint8_t _numDestMiscRegs
Number of destination misc.
Definition: dyn_inst.hh:118
void setVecRegOperand(const StaticInst *si, int idx, const VecRegContainer &val) override
Record a vector register being set to a value.
Definition: dyn_inst.hh:399
const int MaxMiscDestRegs
Definition: registers.hh:45
uint64_t Tick
Tick count type.
Definition: types.hh:61
VecPredReg::Container VecPredRegContainer
Definition: registers.hh:77
void setIntRegOperand(const StaticInst *si, int idx, RegVal val) override
Definition: dyn_inst.hh:385
RegVal readMiscRegOperand(const StaticInst *si, int idx) override
Reads a misc.
Definition: dyn_inst.hh:172
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:138
Condition-code register.
Definition: reg_class.hh:60
virtual void setVecLaneOperand(const StaticInst *si, int idx, const LaneData< LaneSize::EightByte > &val) override
Definition: dyn_inst.hh:351
uint64_t InstSeqNum
Definition: inst_seq.hh:37
std::array< short, TheISA::MaxMiscDestRegs > _destMiscRegIdx
Indexes of the destination misc.
Definition: dyn_inst.hh:115
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:249
VecElem readVecElemOperand(const StaticInst *si, int idx) const override
Vector Elem Interfaces.
Definition: dyn_inst.hh:358
ConstVecLane32 readVec32BitLaneOperand(const StaticInst *si, int idx) const override
Reads source vector 32bit operand.
Definition: dyn_inst.hh:313
void updateMiscRegs()
Called at the commit stage to update the misc.
Definition: dyn_inst.hh:192
static constexpr auto NumVecElemPerVecReg
Definition: dyn_inst.hh:69
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:223
std::array< RegVal, TheISA::MaxMiscDestRegs > _destMiscRegVal
Values to be written to the destination misc.
Definition: dyn_inst.hh:109
void setMiscReg(int misc_reg, RegVal val) override
Sets a misc.
Definition: dyn_inst.hh:147
ImplCPU * cpu
Pointer to the Impl&#39;s CPU object.
VecReg::Container VecRegContainer
Definition: registers.hh:71
TheISA::MachInst MachInst
Binary machine instruction type.
Definition: dyn_inst.hh:65
Impl::O3CPU O3CPU
Typedef for the CPU.
Definition: dyn_inst.hh:62
const RegClass & classValue() const
Class accessor.
Definition: reg_class.hh:200
Generic predicate register container.
Definition: vec_pred_reg.hh:47
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:415
void setFloatRegOperandBits(const StaticInst *si, int idx, RegVal val) override
Records an fp register being set to an integer value.
Definition: dyn_inst.hh:392
Base, ISA-independent static instruction class.
Definition: static_inst.hh:85
const RegIndex & index() const
Index accessors.
Definition: reg_class.hh:173
const RegId & destRegIdx(int i) const
Return logical index (architectural reg num) of i&#39;th destination reg.
Definition: static_inst.hh:218
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:75
Integer register.
Definition: reg_class.hh:53
RegVal readIntRegOperand(const StaticInst *si, int idx) override
Reads an integer register.
Definition: dyn_inst.hh:269
ConstVecLane64 readVec64BitLaneOperand(const StaticInst *si, int idx) const override
Reads source vector 64bit operand.
Definition: dyn_inst.hh:320
Vector Register.
Definition: reg_class.hh:56
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:345
Vector Lane abstraction Another view of a container.
Definition: vec_reg.hh:262
void setVecRegOperand(const StaticInst *si, int idx, const VecRegContainer &val)
Record a vector register being set to a value.
GenericISA::DelaySlotPCState< MachInst > PCState
Definition: types.hh:41
TheISA::VecElem VecElem
Definition: exec_context.hh:75
void setMiscRegOperand(const StaticInst *si, int idx, RegVal val) override
Sets a misc.
Definition: dyn_inst.hh:183
T * get() const
Directly access the pointer itself without taking a reference.
Definition: refcnt.hh:219
std::shared_ptr< FaultBase > Fault
Definition: types.hh:238
virtual void setVecLaneOperand(const StaticInst *si, int idx, const LaneData< LaneSize::TwoByte > &val) override
Definition: dyn_inst.hh:339
void forwardOldRegs()
Definition: dyn_inst.hh:208
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:333
RegVal readCCRegOperand(const StaticInst *si, int idx) override
Definition: dyn_inst.hh:376
Fault initiateAcc()
Initiates the access.

Generated on Fri Jul 3 2020 15:53:00 for gem5 by doxygen 1.8.13