gem5 v24.0.0.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_ZERO:
90 reg_sym = "0";
91 break;
92 case REG_SHARED_BASE:
93 reg_sym = "src_shared_base";
94 break;
96 reg_sym = "src_shared_limit";
97 break;
99 reg_sym = "src_private_base";
100 break;
102 reg_sym = "src_private_limit";
103 break;
104 case REG_POS_HALF:
105 reg_sym = "0.5";
106 break;
107 case REG_NEG_HALF:
108 reg_sym = "-0.5";
109 break;
110 case REG_POS_ONE:
111 reg_sym = "1";
112 break;
113 case REG_NEG_ONE:
114 reg_sym = "-1";
115 break;
116 case REG_POS_TWO:
117 reg_sym = "2";
118 break;
119 case REG_NEG_TWO:
120 reg_sym = "-2";
121 break;
122 case REG_POS_FOUR:
123 reg_sym = "4";
124 break;
125 case REG_NEG_FOUR:
126 reg_sym = "-4";
127 break;
128 default:
129 fatal("VEGA ISA instruction has unknown register index %u\n", idx);
130 break;
131 }
132
133 return reg_sym;
134 }
135
136 int
137 opSelectorToRegIdx(int idx, int numScalarRegs)
138 {
139 int regIdx = -1;
140
141 if (idx <= REG_SGPR_MAX) {
142 regIdx = idx;
143 } else if (idx >= REG_VGPR_MIN && idx <= REG_VGPR_MAX) {
144 regIdx = idx - REG_VGPR_MIN;
145 } else if (idx == REG_VCC_LO) {
157 regIdx = numScalarRegs - 2;
158 } else if (idx == REG_VCC_HI) {
159 regIdx = numScalarRegs - 1;
160 } else if (idx == REG_FLAT_SCRATCH_LO) {
173 regIdx = numScalarRegs - 4;
174 } else if (idx == REG_FLAT_SCRATCH_HI) {
175 regIdx = numScalarRegs - 3;
176 } else if (idx == REG_EXEC_LO || idx == REG_EXEC_HI) {
184 return idx;
185 }
186
187 return regIdx;
188 }
189
190 bool
191 isPosConstVal(int opIdx)
192 {
193 bool is_pos_const_val = (opIdx >= REG_INT_CONST_POS_MIN
194 && opIdx <= REG_INT_CONST_POS_MAX);
195
196 return is_pos_const_val;
197 }
198
199 bool
200 isNegConstVal(int opIdx)
201 {
202 bool is_neg_const_val = (opIdx >= REG_INT_CONST_NEG_MIN
203 && opIdx <= REG_INT_CONST_NEG_MAX);
204
205 return is_neg_const_val;
206 }
207
208 bool
209 isConstVal(int opIdx)
210 {
211 bool is_const_val = isPosConstVal(opIdx) || isNegConstVal(opIdx);
212 return is_const_val;
213 }
214
215 bool
216 isLiteral(int opIdx)
217 {
218 return opIdx == REG_SRC_LITERAL;
219 }
220
221 bool
222 isExecMask(int opIdx)
223 {
224 return opIdx == REG_EXEC_LO || opIdx == REG_EXEC_HI;
225 }
226
227 bool
228 isVccReg(int opIdx)
229 {
230 return opIdx == REG_VCC_LO || opIdx == REG_VCC_HI;
231 }
232
233 bool
235 {
236 return opIdx == REG_FLAT_SCRATCH_LO || opIdx == REG_FLAT_SCRATCH_HI;
237 }
238
239 bool
240 isScalarReg(int opIdx)
241 {
242 // FLAT_SCRATCH and VCC are stored in an SGPR pair
243 if (opIdx <= REG_SGPR_MAX || opIdx == REG_FLAT_SCRATCH_LO ||
244 opIdx == REG_FLAT_SCRATCH_HI || opIdx == REG_VCC_LO ||
245 opIdx == REG_VCC_HI) {
246 return true;
247 }
248
249 return false;
250 }
251
252 bool
253 isVectorReg(int opIdx)
254 {
255 if (opIdx >= REG_VGPR_MIN && opIdx <= REG_VGPR_MAX)
256 return true;
257
258 return false;
259 }
260
261} // namespace VegaISA
262} // namespace gem5
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:200
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 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36

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