gem5 [DEVELOP-FOR-25.0]
Loading...
Searching...
No Matches
gpu_registers.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015-2021 Advanced Micro Devices, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
33
34namespace gem5
35{
36
37namespace VegaISA
38{
39 std::string
40 opSelectorToRegSym(int idx, int numRegs)
41 {
42 std::string reg_sym;
43
44 // we have an SGPR
45 if (idx <= REG_SGPR_MAX) {
46 if (numRegs > 1)
47 reg_sym = "s[" + std::to_string(idx) + ":" +
48 std::to_string(idx + numRegs - 1) + "]";
49 else
50 reg_sym = "s" + std::to_string(idx);
51 return reg_sym;
52 } else if (idx >= REG_VGPR_MIN && idx <= REG_VGPR_MAX) {
53 if (numRegs > 1)
54 reg_sym = "v[" + std::to_string(idx - REG_VGPR_MIN) + ":" +
55 std::to_string(idx - REG_VGPR_MIN + numRegs - 1) + "]";
56 else
57 reg_sym = "v" + std::to_string(idx - REG_VGPR_MIN);
58 return reg_sym;
59 } else if (idx >= REG_INT_CONST_POS_MIN &&
60 idx <= REG_INT_CONST_POS_MAX) {
61 reg_sym = std::to_string(idx - REG_INT_CONST_POS_MIN + 1);
62 return reg_sym;
63 } else if (idx >= REG_INT_CONST_NEG_MIN &&
64 idx <= REG_INT_CONST_NEG_MAX) {
65 int inline_val = -1 - (idx - REG_INT_CONST_NEG_MIN);
66 reg_sym = std::to_string(inline_val);
67 return reg_sym;
68 }
69
70 switch (idx) {
72 reg_sym = "flat_scratch_lo";
73 break;
75 reg_sym = "flat_scratch_hi";
76 break;
77 case REG_VCC_LO:
78 reg_sym = "vcc_lo";
79 break;
80 case REG_VCC_HI:
81 reg_sym = "vcc_hi";
82 break;
83 case REG_M0:
84 reg_sym = "m0";
85 break;
86 case REG_EXEC_LO:
87 reg_sym = "exec";
88 break;
89 case REG_EXEC_HI:
90 reg_sym = "exec";
91 break;
92 case REG_ZERO:
93 reg_sym = "0";
94 break;
95 case REG_SHARED_BASE:
96 reg_sym = "src_shared_base";
97 break;
99 reg_sym = "src_shared_limit";
100 break;
101 case REG_PRIVATE_BASE:
102 reg_sym = "src_private_base";
103 break;
105 reg_sym = "src_private_limit";
106 break;
107 case REG_POS_HALF:
108 reg_sym = "0.5";
109 break;
110 case REG_NEG_HALF:
111 reg_sym = "-0.5";
112 break;
113 case REG_POS_ONE:
114 reg_sym = "1";
115 break;
116 case REG_NEG_ONE:
117 reg_sym = "-1";
118 break;
119 case REG_POS_TWO:
120 reg_sym = "2";
121 break;
122 case REG_NEG_TWO:
123 reg_sym = "-2";
124 break;
125 case REG_POS_FOUR:
126 reg_sym = "4";
127 break;
128 case REG_NEG_FOUR:
129 reg_sym = "-4";
130 break;
131 default:
132 fatal("VEGA ISA instruction has unknown register index %u\n", idx);
133 break;
134 }
135
136 return reg_sym;
137 }
138
139 int
140 opSelectorToRegIdx(int idx, int numScalarRegs)
141 {
142 int regIdx = -1;
143
144 if (idx <= REG_SGPR_MAX) {
145 regIdx = idx;
146 } else if (idx >= REG_VGPR_MIN && idx <= REG_VGPR_MAX) {
147 regIdx = idx - REG_VGPR_MIN;
148 } else if (idx == REG_VCC_LO) {
160 regIdx = numScalarRegs - 2;
161 } else if (idx == REG_VCC_HI) {
162 regIdx = numScalarRegs - 1;
163 } else if (idx == REG_FLAT_SCRATCH_LO) {
176 regIdx = numScalarRegs - 4;
177 } else if (idx == REG_FLAT_SCRATCH_HI) {
178 regIdx = numScalarRegs - 3;
179 } else if (idx == REG_EXEC_LO || idx == REG_EXEC_HI) {
187 return idx;
188 }
189
190 return regIdx;
191 }
192
193 bool
194 isPosConstVal(int opIdx)
195 {
196 bool is_pos_const_val = (opIdx >= REG_INT_CONST_POS_MIN
197 && opIdx <= REG_INT_CONST_POS_MAX);
198
199 return is_pos_const_val;
200 }
201
202 bool
203 isNegConstVal(int opIdx)
204 {
205 bool is_neg_const_val = (opIdx >= REG_INT_CONST_NEG_MIN
206 && opIdx <= REG_INT_CONST_NEG_MAX);
207
208 return is_neg_const_val;
209 }
210
211 bool
212 isConstVal(int opIdx)
213 {
214 bool is_const_val = isPosConstVal(opIdx) || isNegConstVal(opIdx);
215 return is_const_val;
216 }
217
218 bool
219 isLiteral(int opIdx)
220 {
221 return opIdx == REG_SRC_LITERAL;
222 }
223
224 bool
225 isExecMask(int opIdx)
226 {
227 return opIdx == REG_EXEC_LO || opIdx == REG_EXEC_HI;
228 }
229
230 bool
231 isVccReg(int opIdx)
232 {
233 return opIdx == REG_VCC_LO || opIdx == REG_VCC_HI;
234 }
235
236 bool
238 {
239 return opIdx == REG_FLAT_SCRATCH_LO || opIdx == REG_FLAT_SCRATCH_HI;
240 }
241
242 bool
243 isScalarReg(int opIdx)
244 {
245 // FLAT_SCRATCH and VCC are stored in an SGPR pair
246 if (opIdx <= REG_SGPR_MAX || opIdx == REG_FLAT_SCRATCH_LO ||
247 opIdx == REG_FLAT_SCRATCH_HI || opIdx == REG_VCC_LO ||
248 opIdx == REG_VCC_HI) {
249 return true;
250 }
251
252 return false;
253 }
254
255 bool
256 isVectorReg(int opIdx)
257 {
258 if (opIdx >= REG_VGPR_MIN && opIdx <= REG_VGPR_MAX)
259 return true;
260
261 return false;
262 }
263
264} // namespace VegaISA
265} // namespace gem5
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:232
classes that represnt vector/scalar operands in VEGA ISA.
Definition faults.cc:39
bool isVectorReg(int opIdx)
bool isNegConstVal(int opIdx)
int opSelectorToRegIdx(int idx, int numScalarRegs)
bool isVccReg(int opIdx)
bool isConstVal(int opIdx)
bool isLiteral(int opIdx)
bool isScalarReg(int opIdx)
std::string opSelectorToRegSym(int idx, int numRegs)
bool isFlatScratchReg(int opIdx)
bool isPosConstVal(int opIdx)
bool isExecMask(int opIdx)
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36

Generated on Mon May 26 2025 09:18:28 for gem5 by doxygen 1.13.2