gem5 v24.0.0.0
Loading...
Searching...
No Matches
static_inst.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017, 2020, 2023 Arm Limited
3 * Copyright (c) 2022-2023 The University of Edinburgh
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) 2003-2005 The Regents of The University of Michigan
16 * Copyright (c) 2013 Advanced Micro Devices, Inc.
17 * All rights reserved.
18 *
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions are
21 * met: redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer;
23 * redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution;
26 * neither the name of the copyright holders nor the names of its
27 * contributors may be used to endorse or promote products derived from
28 * this software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 */
42
43#ifndef __CPU_STATIC_INST_HH__
44#define __CPU_STATIC_INST_HH__
45
46#include <array>
47#include <bitset>
48#include <cstdint>
49#include <memory>
50#include <string>
51
53#include "base/logging.hh"
54#include "base/refcnt.hh"
55#include "cpu/op_class.hh"
56#include "cpu/reg_class.hh"
58#include "enums/StaticInstFlags.hh"
59#include "sim/byteswap.hh"
60
61namespace gem5
62{
63
64// forward declarations
65class Packet;
66
67class ExecContext;
68class ThreadContext;
69
70namespace loader
71{
72class SymbolTable;
73} // namespace loader
74
75namespace trace
76{
77class InstRecord;
78} // namespace trace
79
88class StaticInst : public RefCounted, public StaticInstFlags
89{
90 public:
92
93 private:
96
99
100 protected:
101
103 std::bitset<Num_Flags> flags;
104
106 OpClass _opClass;
107
109 uint8_t _numSrcRegs = 0;
110
112 uint8_t _numDestRegs = 0;
113
114 std::array<uint8_t, MiscRegClass + 1> _numTypedDestRegs = {};
115
116 public:
117
121
122
123 uint8_t numSrcRegs() const { return _numSrcRegs; }
125 uint8_t numDestRegs() const { return _numDestRegs; }
127 uint8_t
129 {
130 return _numTypedDestRegs[type];
131 }
133
138
139
140 bool isNop() const { return flags[IsNop]; }
141
142 bool
143 isMemRef() const
144 {
145 return flags[IsLoad] || flags[IsStore] || flags[IsAtomic];
146 }
147 bool isLoad() const { return flags[IsLoad]; }
148 bool isStore() const { return flags[IsStore]; }
149 bool isAtomic() const { return flags[IsAtomic]; }
150 bool isStoreConditional() const { return flags[IsStoreConditional]; }
151 bool isInstPrefetch() const { return flags[IsInstPrefetch]; }
152 bool isDataPrefetch() const { return flags[IsDataPrefetch]; }
153 bool isPrefetch() const { return isInstPrefetch() ||
154 isDataPrefetch(); }
155
156 bool isInteger() const { return flags[IsInteger]; }
157 bool isFloating() const { return flags[IsFloating]; }
158 bool isVector() const { return flags[IsVector]; }
159 bool isMatrix() const { return flags[IsMatrix]; }
160
161 bool isControl() const { return flags[IsControl]; }
162 bool isCall() const { return flags[IsCall]; }
163 bool isReturn() const { return flags[IsReturn]; }
164 bool isDirectCtrl() const { return flags[IsDirectControl]; }
165 bool isIndirectCtrl() const { return flags[IsIndirectControl]; }
166 bool isCondCtrl() const { return flags[IsCondControl]; }
167 bool isUncondCtrl() const { return flags[IsUncondControl]; }
168
169 bool isSerializing() const { return flags[IsSerializing] ||
170 flags[IsSerializeBefore] ||
171 flags[IsSerializeAfter]; }
172 bool isSerializeBefore() const { return flags[IsSerializeBefore]; }
173 bool isSerializeAfter() const { return flags[IsSerializeAfter]; }
174 bool isSquashAfter() const { return flags[IsSquashAfter]; }
175 bool
177 {
178 return flags[IsReadBarrier] && flags[IsWriteBarrier];
179 }
180 bool isReadBarrier() const { return flags[IsReadBarrier]; }
181 bool isWriteBarrier() const { return flags[IsWriteBarrier]; }
182 bool isNonSpeculative() const { return flags[IsNonSpeculative]; }
183 bool isQuiesce() const { return flags[IsQuiesce]; }
184 bool isUnverifiable() const { return flags[IsUnverifiable]; }
185 bool isPseudo() const { return flags[IsPseudo]; }
186 bool isSyscall() const { return flags[IsSyscall]; }
187 bool isMacroop() const { return flags[IsMacroop]; }
188 bool isMicroop() const { return flags[IsMicroop]; }
189 bool isDelayedCommit() const { return flags[IsDelayedCommit]; }
190 bool isLastMicroop() const { return flags[IsLastMicroop]; }
191 bool isFirstMicroop() const { return flags[IsFirstMicroop]; }
192 // hardware transactional memory
193 // HtmCmds must be identified as such in order
194 // to provide them with necessary memory ordering semantics.
195 bool isHtmStart() const { return flags[IsHtmStart]; }
196 bool isHtmStop() const { return flags[IsHtmStop]; }
197 bool isHtmCancel() const { return flags[IsHtmCancel]; }
198
199 bool isInvalid() const { return flags[IsInvalid]; }
200
201 bool
202 isHtmCmd() const
203 {
204 return isHtmStart() || isHtmStop() || isHtmCancel();
205 }
207
208 void setFirstMicroop() { flags[IsFirstMicroop] = true; }
209 void setLastMicroop() { flags[IsLastMicroop] = true; }
210 void setDelayedCommit() { flags[IsDelayedCommit] = true; }
211 void setFlag(Flags f) { flags[f] = true; }
212
214 OpClass opClass() const { return _opClass; }
215
216
219 const RegId &destRegIdx(int i) const { return (this->*_destRegIdxPtr)[i]; }
220
221 void
223 {
224 (this->*_destRegIdxPtr)[i] = val;
225 }
226
229 const RegId &srcRegIdx(int i) const { return (this->*_srcRegIdxPtr)[i]; }
230
231 void
232 setSrcRegIdx(int i, const RegId &val)
233 {
234 (this->*_srcRegIdxPtr)[i] = val;
235 }
236
239
240 virtual uint64_t getEMI() const { return 0; }
241
242 protected:
243
250 void
252 {
253 _srcRegIdxPtr = src;
254 _destRegIdxPtr = dest;
255 }
256
260 size_t _size = 0;
261
268 const char *mnemonic;
269
274 mutable std::unique_ptr<std::string> cachedDisassembly;
275
279 virtual std::string generateDisassembly(
280 Addr pc, const loader::SymbolTable *symtab) const = 0;
281
287 StaticInst(const char *_mnemonic, OpClass op_class)
288 : _opClass(op_class), mnemonic(_mnemonic)
289 {}
290
291 public:
292 virtual ~StaticInst() {};
293
295 trace::InstRecord *traceData) const = 0;
296
297 virtual Fault
299 {
300 panic("initiateAcc not defined!");
301 }
302
303 virtual Fault
305 trace::InstRecord *trace_data) const
306 {
307 panic("completeAcc not defined!");
308 }
309
310 virtual void advancePC(PCStateBase &pc_state) const = 0;
311 virtual void advancePC(ThreadContext *tc) const;
312
313 virtual std::unique_ptr<PCStateBase>
314 buildRetPC(const PCStateBase &cur_pc, const PCStateBase &call_pc) const
315 {
316 panic("buildRetPC not defined!");
317 }
318
319 size_t size() const
320 {
321 if (_size == 0) fatal(
322 "Instruction size for this instruction not set! It's size is "
323 "required for the decoupled front-end. Either use the standard "
324 "front-end or this ISA needs to be extended with the instruction "
325 "size. Refer to the X86, Arm or RiscV decoders for an example.");
326 return _size;
327 }
328 virtual void size(size_t newSize) { _size = newSize; }
329
334 virtual StaticInstPtr fetchMicroop(MicroPC upc) const;
335
341 virtual std::unique_ptr<PCStateBase> branchTarget(
342 const PCStateBase &pc) const;
343
351 virtual std::unique_ptr<PCStateBase> branchTarget(
352 ThreadContext *tc) const;
353
361 virtual const std::string &disassemble(Addr pc,
362 const loader::SymbolTable *symtab=nullptr) const;
363
368 void printFlags(std::ostream &outs, const std::string &separator) const;
369
371 std::string getName() { return mnemonic; }
372
373 protected:
374 template<typename T>
375 size_t
376 simpleAsBytes(void *buf, size_t max_size, const T &t)
377 {
378 size_t size = sizeof(T);
379 if (size <= max_size)
380 *reinterpret_cast<T *>(buf) = htole<T>(t);
381 return size;
382 }
383
384 public:
396 virtual size_t asBytes(void *buf, size_t max_size) { return 0; }
397};
398
399} // namespace gem5
400
401#endif // __CPU_STATIC_INST_HH__
The ExecContext is an abstract base class the provides the interface used by the ISA to manipulate th...
Wrapper that groups a few flag bits under the same undelying container.
Definition flags.hh:45
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Derive from RefCounted if you want to enable reference counting of this class.
Definition refcnt.hh:61
Register ID: describe an architectural register with its class and index.
Definition reg_class.hh:94
Base, ISA-independent static instruction class.
static StaticInstPtr nullStaticInstPtr
Pointer to a statically allocated "null" instruction object.
StaticInst(const char *_mnemonic, OpClass op_class)
Constructor.
bool isInteger() const
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.
bool isQuiesce() const
bool isHtmStop() const
virtual const std::string & disassemble(Addr pc, const loader::SymbolTable *symtab=nullptr) const
Return string representation of disassembled instruction.
bool isUnverifiable() const
virtual ~StaticInst()
RegIdArrayPtr _srcRegIdxPtr
See srcRegIdx().
virtual uint64_t getEMI() const
uint8_t numSrcRegs() const
Number of source registers.
virtual StaticInstPtr fetchMicroop(MicroPC upc) const
Return the microop that goes with a particular micropc.
virtual void size(size_t newSize)
virtual std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const =0
Internal function to generate disassembly string.
void setDestRegIdx(int i, const RegId &val)
OpClass opClass() const
Operation class. Used to select appropriate function unit in issue.
void setRegIdxArrays(RegIdArrayPtr src, RegIdArrayPtr dest)
Set the pointers which point to the arrays of source and destination register indices.
virtual std::unique_ptr< PCStateBase > buildRetPC(const PCStateBase &cur_pc, const PCStateBase &call_pc) const
bool isSyscall() const
bool isPrefetch() const
std::array< uint8_t, MiscRegClass+1 > _numTypedDestRegs
std::unique_ptr< std::string > cachedDisassembly
String representation of disassembly (lazily evaluated via disassemble()).
bool isStoreConditional() const
bool isFirstMicroop() const
bool isDirectCtrl() const
bool isHtmCmd() const
bool isUncondCtrl() const
bool isSerializeBefore() const
bool isLoad() const
virtual std::unique_ptr< PCStateBase > branchTarget(const PCStateBase &pc) const
Return the target address for a PC-relative branch.
size_t simpleAsBytes(void *buf, size_t max_size, const T &t)
bool isPseudo() const
bool isSquashAfter() const
uint8_t numDestRegs() const
Number of destination registers.
bool isMatrix() const
virtual void advancePC(PCStateBase &pc_state) const =0
RegId(StaticInst::*)[] RegIdArrayPtr
bool isHtmCancel() const
bool isFloating() const
bool isWriteBarrier() const
bool isNop() const
size_t size() const
uint8_t _numSrcRegs
See numSrcRegs().
bool isMacroop() const
bool isReturn() const
bool isMemRef() const
virtual Fault execute(ExecContext *xc, trace::InstRecord *traceData) const =0
bool isReadBarrier() const
uint8_t _numDestRegs
See numDestRegs().
bool isInvalid() const
std::string getName()
Return name of machine instruction.
bool isNonSpeculative() const
RegIdArrayPtr _destRegIdxPtr
See destRegIdx().
const RegId & destRegIdx(int i) const
Return logical index (architectural reg num) of i'th destination reg.
bool isDataPrefetch() const
uint8_t numDestRegs(RegClassType type) const
Number of destination registers of a particular type.
bool isIndirectCtrl() const
bool isVector() const
bool isHtmStart() const
bool isLastMicroop() const
void setSrcRegIdx(int i, const RegId &val)
bool isFullMemBarrier() const
size_t _size
Instruction size in bytes.
bool isStore() const
bool isInstPrefetch() const
void setFlag(Flags f)
bool isSerializing() const
const char * mnemonic
Base mnemonic (e.g., "add").
virtual Fault completeAcc(Packet *pkt, ExecContext *xc, trace::InstRecord *trace_data) const
std::bitset< Num_Flags > flags
Flag values for this instruction.
bool isAtomic() const
bool isMicroop() const
bool isCall() const
virtual size_t asBytes(void *buf, size_t max_size)
Instruction classes can override this function to return a a representation of themselves as a blob o...
const RegId & srcRegIdx(int i) const
Return logical index (architectural reg num) of i'th source reg.
virtual Fault initiateAcc(ExecContext *xc, trace::InstRecord *traceData) const
bool isCondCtrl() const
bool isDelayedCommit() const
bool isControl() const
bool isSerializeAfter() const
OpClass _opClass
See opClass().
ThreadContext is the external interface to all thread state for anything outside of the CPU.
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:200
Bitfield< 5 > t
Definition misc_types.hh:71
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 6 > f
Definition misc_types.hh:68
Bitfield< 4 > pc
Bitfield< 63 > val
Definition misc.hh:804
ProbePointArg< PacketInfo > Packet
Packet probe point.
Definition mem.hh:108
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::shared_ptr< FaultBase > Fault
Definition types.hh:249
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
T htole(T value)
Definition byteswap.hh:172
uint16_t MicroPC
Definition types.hh:149
RegClassType
Enumerate the classes of registers.
Definition reg_class.hh:60
Classes for managing reference counted objects.

Generated on Tue Jun 18 2024 16:24:02 for gem5 by doxygen 1.11.0