2 * Copyright (c) 2010, 2016 ARM Limited
3 * Copyright (c) 2013 Advanced Micro Devices, Inc.
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.
15 * Copyright (c) 2004-2006 The Regents of The University of Michigan
16 * All rights reserved.
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.
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.
42 #ifndef __CPU_O3_DYN_INST_HH__
43 #define __CPU_O3_DYN_INST_HH__
47 #include "config/the_isa.hh"
48 #include "cpu/o3/cpu.hh"
49 #include "cpu/o3/isa_specific.hh"
50 #include "cpu/base_dyn_inst.hh"
51 #include "cpu/inst_seq.hh"
52 #include "cpu/reg_class.hh"
57 class BaseO3DynInst : public BaseDynInst<Impl>
60 /** Typedef for the CPU. */
61 typedef typename Impl::O3CPU O3CPU;
63 /** Register types. */
64 static constexpr auto NumVecElemPerVecReg = TheISA::NumVecElemPerVecReg;
67 /** BaseDynInst constructor given a binary instruction. */
68 BaseO3DynInst(const StaticInstPtr &staticInst, const StaticInstPtr
69 ¯oop, TheISA::PCState pc, TheISA::PCState predPC,
70 InstSeqNum seq_num, O3CPU *cpu);
72 /** BaseDynInst constructor given a static inst pointer. */
73 BaseO3DynInst(const StaticInstPtr &_staticInst,
74 const StaticInstPtr &_macroop);
78 /** Executes the instruction.*/
81 /** Initiates the access. Only valid for memory operations. */
84 /** Completes the access. Only valid for memory operations. */
85 Fault completeAcc(PacketPtr pkt);
88 /** Initializes variables. */
92 /** Explicitation of dependent names. */
93 using BaseDynInst<Impl>::cpu;
95 /** Values to be written to the destination misc. registers. */
96 std::array<RegVal, TheISA::MaxMiscDestRegs> _destMiscRegVal;
98 /** Indexes of the destination misc. registers. They are needed to defer
99 * the write accesses to the misc. registers until the commit stage, when
100 * the instruction is out of its speculative state.
102 std::array<short, TheISA::MaxMiscDestRegs> _destMiscRegIdx;
104 /** Number of destination misc. registers. */
105 uint8_t _numDestMiscRegs;
110 /** Tick records used for the pipeline activity viewer. */
111 Tick fetchTick; // instruction fetch is completed.
112 int32_t decodeTick; // instruction enters decode phase
113 int32_t renameTick; // instruction enters rename phase
114 int32_t dispatchTick;
116 int32_t completeTick;
121 /** Reads a misc. register, including any side-effects the read
122 * might have as defined by the architecture.
125 readMiscReg(int misc_reg) override
127 return this->cpu->readMiscReg(misc_reg, this->threadNumber);
130 /** Sets a misc. register, including any side-effects the write
131 * might have as defined by the architecture.
134 setMiscReg(int misc_reg, RegVal val) override
136 /** Writes to misc. registers are recorded and deferred until the
137 * commit stage, when updateMiscRegs() is called. First, check if
138 * the misc reg has been written before and update its value to be
139 * committed instead of making a new entry. If not, make a new
140 * entry and record the write.
142 for (int idx = 0; idx < _numDestMiscRegs; idx++) {
143 if (_destMiscRegIdx[idx] == misc_reg) {
144 _destMiscRegVal[idx] = val;
149 assert(_numDestMiscRegs < TheISA::MaxMiscDestRegs);
150 _destMiscRegIdx[_numDestMiscRegs] = misc_reg;
151 _destMiscRegVal[_numDestMiscRegs] = val;
155 /** Reads a misc. register, including any side-effects the read
156 * might have as defined by the architecture.
159 readMiscRegOperand(const StaticInst *si, int idx) override
161 const RegId& reg = si->srcRegIdx(idx);
162 assert(reg.isMiscReg());
163 return this->cpu->readMiscReg(reg.index(), this->threadNumber);
166 /** Sets a misc. register, including any side-effects the write
167 * might have as defined by the architecture.
170 setMiscRegOperand(const StaticInst *si, int idx, RegVal val) override
172 const RegId& reg = si->destRegIdx(idx);
173 assert(reg.isMiscReg());
174 setMiscReg(reg.index(), val);
177 /** Called at the commit stage to update the misc. registers. */
181 // @todo: Pretty convoluted way to avoid squashing from happening when
182 // using the TC during an instruction's execution (specifically for
183 // instructions that have side-effects that use the TC). Fix this.
184 // See cpu/o3/dyn_inst_impl.hh.
185 bool no_squash_from_TC = this->thread->noSquashFromTC;
186 this->thread->noSquashFromTC = true;
188 for (int i = 0; i < _numDestMiscRegs; i++)
189 this->cpu->setMiscReg(
190 _destMiscRegIdx[i], _destMiscRegVal[i], this->threadNumber);
192 this->thread->noSquashFromTC = no_squash_from_TC;
195 void forwardOldRegs()
198 for (int idx = 0; idx < this->numDestRegs(); idx++) {
199 PhysRegIdPtr prev_phys_reg = this->regs.prevDestIdx(idx);
200 const RegId& original_dest_reg =
201 this->staticInst->destRegIdx(idx);
202 switch (original_dest_reg.classValue()) {
204 this->setIntRegOperand(this->staticInst.get(), idx,
205 this->cpu->readIntReg(prev_phys_reg));
208 this->setFloatRegOperandBits(this->staticInst.get(), idx,
209 this->cpu->readFloatReg(prev_phys_reg));
212 this->setVecRegOperand(this->staticInst.get(), idx,
213 this->cpu->readVecReg(prev_phys_reg));
216 this->setVecElemOperand(this->staticInst.get(), idx,
217 this->cpu->readVecElem(prev_phys_reg));
219 case VecPredRegClass:
220 this->setVecPredRegOperand(this->staticInst.get(), idx,
221 this->cpu->readVecPredReg(prev_phys_reg));
224 this->setCCRegOperand(this->staticInst.get(), idx,
225 this->cpu->readCCReg(prev_phys_reg));
228 // no need to forward misc reg values
231 panic("Unknown register class: %d",
232 (int)original_dest_reg.classValue());
236 /** Traps to handle specified fault. */
237 void trap(const Fault &fault);
241 // The register accessor methods provide the index of the
242 // instruction's operand (e.g., 0 or 1), not the architectural
243 // register index, to simplify the implementation of register
244 // renaming. We find the architectural register index by indexing
245 // into the instruction's own operand index table. Note that a
246 // raw pointer to the StaticInst is provided instead of a
247 // ref-counted StaticInstPtr to redice overhead. This is fine as
248 // long as these methods don't copy the pointer into any long-term
249 // storage (which is pretty hard to imagine they would have reason
253 readIntRegOperand(const StaticInst *si, int idx) override
255 return this->cpu->readIntReg(this->regs.renamedSrcIdx(idx));
259 readFloatRegOperandBits(const StaticInst *si, int idx) override
261 return this->cpu->readFloatReg(this->regs.renamedSrcIdx(idx));
264 const TheISA::VecRegContainer&
265 readVecRegOperand(const StaticInst *si, int idx) const override
267 return this->cpu->readVecReg(this->regs.renamedSrcIdx(idx));
271 * Read destination vector register operand for modification.
273 TheISA::VecRegContainer&
274 getWritableVecRegOperand(const StaticInst *si, int idx) override
276 return this->cpu->getWritableVecReg(this->regs.renamedDestIdx(idx));
279 /** Vector Register Lane Interfaces. */
281 /** Reads source vector 8bit operand. */
283 readVec8BitLaneOperand(const StaticInst *si, int idx) const override
285 return cpu->template readVecLane<uint8_t>(
286 this->regs.renamedSrcIdx(idx));
289 /** Reads source vector 16bit operand. */
291 readVec16BitLaneOperand(const StaticInst *si, int idx) const override
293 return cpu->template readVecLane<uint16_t>(
294 this->regs.renamedSrcIdx(idx));
297 /** Reads source vector 32bit operand. */
299 readVec32BitLaneOperand(const StaticInst *si, int idx) const override
301 return cpu->template readVecLane<uint32_t>(
302 this->regs.renamedSrcIdx(idx));
305 /** Reads source vector 64bit operand. */
307 readVec64BitLaneOperand(const StaticInst *si, int idx) const override
309 return cpu->template readVecLane<uint64_t>(
310 this->regs.renamedSrcIdx(idx));
313 /** Write a lane of the destination vector operand. */
314 template <typename LD>
316 setVecLaneOperandT(const StaticInst *si, int idx, const LD& val)
318 return cpu->template setVecLane(this->regs.renamedDestIdx(idx), val);
321 setVecLaneOperand(const StaticInst *si, int idx,
322 const LaneData<LaneSize::Byte>& val) override
324 return setVecLaneOperandT(si, idx, val);
327 setVecLaneOperand(const StaticInst *si, int idx,
328 const LaneData<LaneSize::TwoByte>& val) override
330 return setVecLaneOperandT(si, idx, val);
333 setVecLaneOperand(const StaticInst *si, int idx,
334 const LaneData<LaneSize::FourByte>& val) override
336 return setVecLaneOperandT(si, idx, val);
339 setVecLaneOperand(const StaticInst *si, int idx,
340 const LaneData<LaneSize::EightByte>& val) override
342 return setVecLaneOperandT(si, idx, val);
347 readVecElemOperand(const StaticInst *si, int idx) const override
349 return this->cpu->readVecElem(this->regs.renamedSrcIdx(idx));
352 const TheISA::VecPredRegContainer&
353 readVecPredRegOperand(const StaticInst *si, int idx) const override
355 return this->cpu->readVecPredReg(this->regs.renamedSrcIdx(idx));
358 TheISA::VecPredRegContainer&
359 getWritableVecPredRegOperand(const StaticInst *si, int idx) override
361 return this->cpu->getWritableVecPredReg(
362 this->regs.renamedDestIdx(idx));
366 readCCRegOperand(const StaticInst *si, int idx) override
368 return this->cpu->readCCReg(this->regs.renamedSrcIdx(idx));
371 /** @todo: Make results into arrays so they can handle multiple dest
375 setIntRegOperand(const StaticInst *si, int idx, RegVal val) override
377 this->cpu->setIntReg(this->regs.renamedDestIdx(idx), val);
378 BaseDynInst<Impl>::setIntRegOperand(si, idx, val);
382 setFloatRegOperandBits(const StaticInst *si, int idx, RegVal val) override
384 this->cpu->setFloatReg(this->regs.renamedDestIdx(idx), val);
385 BaseDynInst<Impl>::setFloatRegOperandBits(si, idx, val);
389 setVecRegOperand(const StaticInst *si, int idx,
390 const TheISA::VecRegContainer& val) override
392 this->cpu->setVecReg(this->regs.renamedDestIdx(idx), val);
393 BaseDynInst<Impl>::setVecRegOperand(si, idx, val);
397 setVecElemOperand(const StaticInst *si, int idx,
398 const TheISA::VecElem val) override
401 this->cpu->setVecElem(this->regs.renamedDestIdx(reg_idx), val);
402 BaseDynInst<Impl>::setVecElemOperand(si, idx, val);
406 setVecPredRegOperand(const StaticInst *si, int idx,
407 const TheISA::VecPredRegContainer& val) override
409 this->cpu->setVecPredReg(this->regs.renamedDestIdx(idx), val);
410 BaseDynInst<Impl>::setVecPredRegOperand(si, idx, val);
413 void setCCRegOperand(const StaticInst *si, int idx, RegVal val) override
415 this->cpu->setCCReg(this->regs.renamedDestIdx(idx), val);
416 BaseDynInst<Impl>::setCCRegOperand(si, idx, val);
420 #endif // __CPU_O3_ALPHA_DYN_INST_HH__