gem5 v24.0.0.0
Loading...
Searching...
No Matches
branch.hh
Go to the documentation of this file.
1/* Copyright (c) 2007-2008 The Florida State University
2 * Copyright (c) 2009 The University of Edinburgh
3 * Copyright (c) 2021 IBM Corporation
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef __ARCH_POWER_INSTS_BRANCH_HH__
31#define __ARCH_POWER_INSTS_BRANCH_HH__
32
34
35namespace gem5
36{
37
38namespace PowerISA
39{
40
51{
52 protected:
54 mutable Addr cachedPC;
57
59 PCDependentDisassembly(const char *mnem, ExtMachInst _machInst,
60 OpClass __opClass)
61 : PowerStaticInst(mnem, _machInst, __opClass),
63 {
64 }
65
66 const std::string &
67 disassemble(Addr pc, const loader::SymbolTable *symtab) const;
68};
69
70
75{
76 protected:
77
78 bool aa;
79 bool lk;
80 int64_t li;
81
83 BranchOp(const char *mnem, MachInst _machInst, OpClass __opClass)
84 : PCDependentDisassembly(mnem, _machInst, __opClass),
85 aa(machInst.aa),
86 lk(machInst.lk),
87 li(sext<26>(machInst.li << 2))
88 {
89 }
90
91 std::unique_ptr<PCStateBase> branchTarget(
92 ThreadContext *tc) const override;
93
96
97 std::string generateDisassembly(
98 Addr pc, const loader::SymbolTable *symtab) const override;
99};
100
101
106{
107 protected:
108
109 bool lk;
110 uint8_t bi;
111 uint8_t bo;
112
114 BranchCondOp(const char *mnem, MachInst _machInst, OpClass __opClass)
115 : PCDependentDisassembly(mnem, _machInst, __opClass),
116 lk(machInst.lk),
117 bi(machInst.bi),
118 bo(machInst.bo)
119 {
120 }
121
122 inline bool
123 ctrOk(uint64_t& ctr) const
124 {
125 if (bits(bo, 2)) {
126 return true;
127 }
128
129 ctr--;
130 return !((ctr != 0) ^ (bits(bo, 1) == 0));
131 }
132
133 inline bool
134 condOk(uint32_t cr) const
135 {
136 if (bits(bo, 4)) {
137 return true;
138 }
139
140 return bits(cr >> (31 - bi), 0) == bits(bo >> 3, 0);
141 }
142};
143
144
149{
150 protected:
151
152 bool aa;
153 int64_t bd;
154
156 BranchDispCondOp(const char *mnem, MachInst _machInst, OpClass __opClass)
157 : BranchCondOp(mnem, _machInst, __opClass),
158 aa(machInst.aa),
159 bd(sext<16>(machInst.bd << 2))
160 {
161 }
162
163 std::unique_ptr<PCStateBase> branchTarget(
164 ThreadContext *tc) const override;
165
168
169 std::string generateDisassembly(
170 Addr pc, const loader::SymbolTable *symtab) const override;
171};
172
173
178{
179 protected:
180
182 uint8_t bh;
183
185 BranchRegCondOp(const char *mnem, MachInst _machInst, OpClass __opClass)
186 : BranchCondOp(mnem, _machInst, __opClass),
187 bh(machInst.bh)
188 {
189 }
190
191 std::unique_ptr<PCStateBase> branchTarget(
192 ThreadContext *tc) const override;
193
196
197 std::string generateDisassembly(
198 Addr pc, const loader::SymbolTable *symtab) const override;
199};
200
201} // namespace PowerISA
202} // namespace gem5
203
204#endif //__ARCH_POWER_INSTS_BRANCH_HH__
Base class for conditional branches.
Definition branch.hh:106
bool ctrOk(uint64_t &ctr) const
Definition branch.hh:123
BranchCondOp(const char *mnem, MachInst _machInst, OpClass __opClass)
Constructor.
Definition branch.hh:114
bool condOk(uint32_t cr) const
Definition branch.hh:134
Base class for conditional, PC-relative or absolute address branches.
Definition branch.hh:149
BranchDispCondOp(const char *mnem, MachInst _machInst, OpClass __opClass)
Constructor.
Definition branch.hh:156
std::unique_ptr< PCStateBase > branchTarget(ThreadContext *tc) const override
Return the target address for an indirect branch (jump).
Definition branch.cc:109
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition branch.cc:125
Base class for unconditional, PC-relative or absolute address branches.
Definition branch.hh:75
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition branch.cc:76
std::unique_ptr< PCStateBase > branchTarget(ThreadContext *tc) const override
Return the target address for an indirect branch (jump).
Definition branch.cc:60
BranchOp(const char *mnem, MachInst _machInst, OpClass __opClass)
Constructor.
Definition branch.hh:83
Base class for conditional, register-based branches.
Definition branch.hh:178
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition branch.cc:171
std::unique_ptr< PCStateBase > branchTarget(ThreadContext *tc) const override
Return the target address for an indirect branch (jump).
Definition branch.cc:161
uint8_t bh
TODO: Branch hints are currently ignored.
Definition branch.hh:182
BranchRegCondOp(const char *mnem, MachInst _machInst, OpClass __opClass)
Constructor.
Definition branch.hh:185
Base class for instructions whose disassembly is not purely a function of the machine instruction (i....
Definition branch.hh:51
PCDependentDisassembly(const char *mnem, ExtMachInst _machInst, OpClass __opClass)
Constructor.
Definition branch.hh:59
const loader::SymbolTable * cachedSymtab
Cached symbol table pointer from last disassembly.
Definition branch.hh:56
Addr cachedPC
Cached program counter from last disassembly.
Definition branch.hh:54
const std::string & disassemble(Addr pc, const loader::SymbolTable *symtab) const
Return string representation of disassembled instruction.
Definition branch.cc:43
virtual std::unique_ptr< PCStateBase > branchTarget(const PCStateBase &pc) const
Return the target address for a PC-relative branch.
ThreadContext is the external interface to all thread state for anything outside of the CPU.
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition bitfield.hh:79
constexpr uint64_t sext(uint64_t val)
Sign-extend an N-bit value to 64 bits.
Definition bitfield.hh:129
Bitfield< 4 > pc
uint32_t MachInst
Definition types.hh:44
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147

Generated on Tue Jun 18 2024 16:23:57 for gem5 by doxygen 1.11.0