gem5  v21.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
registers.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2017 Advanced Micro Devices, Inc.
3  * All rights reserved.
4  *
5  * For use for simulation and test purposes only
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived from this
19  * software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include "arch/gcn3/registers.hh"
35 
36 namespace Gcn3ISA
37 {
38  std::string
39  opSelectorToRegSym(int idx, int numRegs)
40  {
41  std::string reg_sym;
42 
43  // we have an SGPR
44  if (idx <= REG_SGPR_MAX) {
45  if (numRegs > 1)
46  reg_sym = "s[" + std::to_string(idx) + ":" +
47  std::to_string(idx + numRegs - 1) + "]";
48  else
49  reg_sym = "s" + std::to_string(idx);
50  return reg_sym;
51  } else if (idx >= REG_VGPR_MIN && idx <= REG_VGPR_MAX) {
52  if (numRegs > 1)
53  reg_sym = "v[" + std::to_string(idx - REG_VGPR_MIN) + ":" +
54  std::to_string(idx - REG_VGPR_MIN + numRegs - 1) + "]";
55  else
56  reg_sym = "v" + std::to_string(idx - REG_VGPR_MIN);
57  return reg_sym;
58  } else if (idx >= REG_INT_CONST_POS_MIN &&
59  idx <= REG_INT_CONST_POS_MAX) {
60  reg_sym = std::to_string(idx - REG_INT_CONST_POS_MIN + 1);
61  return reg_sym;
62  } else if (idx >= REG_INT_CONST_NEG_MIN &&
63  idx <= REG_INT_CONST_NEG_MAX) {
64  int inline_val = -1 - (idx - REG_INT_CONST_NEG_MIN);
65  reg_sym = std::to_string(inline_val);
66  return reg_sym;
67  }
68 
69  switch (idx) {
71  reg_sym = "flat_scratch_lo";
72  break;
74  reg_sym = "flat_scratch_hi";
75  break;
76  case REG_VCC_LO:
77  reg_sym = "vcc";
78  break;
79  case REG_M0:
80  reg_sym = "m0";
81  break;
82  case REG_EXEC_LO:
83  reg_sym = "exec";
84  break;
85  case REG_ZERO:
86  reg_sym = "0";
87  break;
88  case REG_POS_HALF:
89  reg_sym = "0.5";
90  break;
91  case REG_NEG_HALF:
92  reg_sym = "-0.5";
93  break;
94  case REG_POS_ONE:
95  reg_sym = "1";
96  break;
97  case REG_NEG_ONE:
98  reg_sym = "-1";
99  break;
100  case REG_POS_TWO:
101  reg_sym = "2";
102  break;
103  case REG_NEG_TWO:
104  reg_sym = "-2";
105  break;
106  case REG_POS_FOUR:
107  reg_sym = "4";
108  break;
109  case REG_NEG_FOUR:
110  reg_sym = "-4";
111  break;
112  default:
113  fatal("GCN3 ISA instruction has unknown register index %u\n", idx);
114  break;
115  }
116 
117  return reg_sym;
118  }
119 
120  int
121  opSelectorToRegIdx(int idx, int numScalarRegs)
122  {
123  int regIdx = -1;
124 
125  if (idx <= REG_SGPR_MAX) {
126  regIdx = idx;
127  } else if (idx >= REG_VGPR_MIN && idx <= REG_VGPR_MAX) {
128  regIdx = idx - REG_VGPR_MIN;
129  } else if (idx == REG_VCC_LO) {
141  regIdx = numScalarRegs - 2;
142  } else if (idx == REG_VCC_HI) {
143  regIdx = numScalarRegs - 1;
144  } else if (idx == REG_FLAT_SCRATCH_LO) {
157  regIdx = numScalarRegs - 4;
158  } else if (idx == REG_FLAT_SCRATCH_HI) {
159  regIdx = numScalarRegs - 3;
160  }
161 
162  return regIdx;
163  }
164 
165  bool
166  isPosConstVal(int opIdx)
167  {
168  bool is_pos_const_val = (opIdx >= REG_INT_CONST_POS_MIN
169  && opIdx <= REG_INT_CONST_POS_MAX);
170 
171  return is_pos_const_val;
172  }
173 
174  bool
175  isNegConstVal(int opIdx)
176  {
177  bool is_neg_const_val = (opIdx >= REG_INT_CONST_NEG_MIN
178  && opIdx <= REG_INT_CONST_NEG_MAX);
179 
180  return is_neg_const_val;
181  }
182 
183  bool
184  isConstVal(int opIdx)
185  {
186  bool is_const_val = isPosConstVal(opIdx) || isNegConstVal(opIdx);
187  return is_const_val;
188  }
189 
190  bool
191  isLiteral(int opIdx)
192  {
193  return opIdx == REG_SRC_LITERAL;
194  }
195 
196  bool
197  isExecMask(int opIdx)
198  {
199  return opIdx == REG_EXEC_LO || opIdx == REG_EXEC_HI;
200  }
201 
202  bool
203  isVccReg(int opIdx)
204  {
205  return opIdx == REG_VCC_LO || opIdx == REG_VCC_HI;
206  }
207 
208  bool
209  isFlatScratchReg(int opIdx)
210  {
211  return opIdx == REG_FLAT_SCRATCH_LO || opIdx == REG_FLAT_SCRATCH_HI;
212  }
213 
214  bool
215  isScalarReg(int opIdx)
216  {
217  // FLAT_SCRATCH and VCC are stored in an SGPR pair
218  if (opIdx <= REG_SGPR_MAX || opIdx == REG_FLAT_SCRATCH_LO ||
219  opIdx == REG_FLAT_SCRATCH_HI || opIdx == REG_VCC_LO ||
220  opIdx == REG_VCC_HI) {
221  return true;
222  }
223 
224  return false;
225  }
226 
227  bool
228  isVectorReg(int opIdx)
229  {
230  if (opIdx >= REG_VGPR_MIN && opIdx <= REG_VGPR_MAX)
231  return true;
232 
233  return false;
234  }
235 
236 } // namespace Gcn3ISA
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:183
Gcn3ISA::REG_POS_FOUR
@ REG_POS_FOUR
Definition: registers.hh:119
Gcn3ISA::REG_VCC_HI
@ REG_VCC_HI
Definition: registers.hh:56
Gcn3ISA::isFlatScratchReg
bool isFlatScratchReg(int opIdx)
Definition: registers.cc:209
Gcn3ISA::REG_INT_CONST_POS_MIN
@ REG_INT_CONST_POS_MIN
Definition: registers.hh:78
Gcn3ISA::isScalarReg
bool isScalarReg(int opIdx)
Definition: registers.cc:215
Gcn3ISA::REG_VGPR_MAX
@ REG_VGPR_MAX
Definition: registers.hh:131
sc_dt::to_string
const std::string to_string(sc_enc enc)
Definition: sc_fxdefs.cc:91
Gcn3ISA::REG_FLAT_SCRATCH_LO
@ REG_FLAT_SCRATCH_LO
Definition: registers.hh:51
Gcn3ISA::REG_POS_HALF
@ REG_POS_HALF
Definition: registers.hh:113
Gcn3ISA::REG_VCC_LO
@ REG_VCC_LO
Definition: registers.hh:55
Gcn3ISA::REG_EXEC_LO
@ REG_EXEC_LO
Definition: registers.hh:75
registers.hh
Gcn3ISA::isExecMask
bool isExecMask(int opIdx)
Definition: registers.cc:197
Gcn3ISA::isVectorReg
bool isVectorReg(int opIdx)
Definition: registers.cc:228
Gcn3ISA::REG_VGPR_MIN
@ REG_VGPR_MIN
Definition: registers.hh:130
Gcn3ISA::REG_INT_CONST_NEG_MIN
@ REG_INT_CONST_NEG_MIN
Definition: registers.hh:80
Gcn3ISA::REG_SRC_LITERAL
@ REG_SRC_LITERAL
Definition: registers.hh:129
Gcn3ISA::REG_ZERO
@ REG_ZERO
Definition: registers.hh:77
Gcn3ISA
classes that represnt vector/scalar operands in GCN3 ISA.
Definition: decoder.cc:41
Gcn3ISA::opSelectorToRegIdx
int opSelectorToRegIdx(int idx, int numScalarRegs)
Definition: registers.cc:121
Gcn3ISA::isPosConstVal
bool isPosConstVal(int opIdx)
Definition: registers.cc:166
Gcn3ISA::isVccReg
bool isVccReg(int opIdx)
Definition: registers.cc:203
Gcn3ISA::REG_M0
@ REG_M0
Definition: registers.hh:73
Gcn3ISA::REG_FLAT_SCRATCH_HI
@ REG_FLAT_SCRATCH_HI
Definition: registers.hh:52
Gcn3ISA::REG_SGPR_MAX
@ REG_SGPR_MAX
Definition: registers.hh:50
Gcn3ISA::REG_POS_TWO
@ REG_POS_TWO
Definition: registers.hh:117
Gcn3ISA::REG_INT_CONST_NEG_MAX
@ REG_INT_CONST_NEG_MAX
Definition: registers.hh:81
Gcn3ISA::REG_NEG_ONE
@ REG_NEG_ONE
Definition: registers.hh:116
Gcn3ISA::isNegConstVal
bool isNegConstVal(int opIdx)
Definition: registers.cc:175
Gcn3ISA::REG_POS_ONE
@ REG_POS_ONE
Definition: registers.hh:115
Gcn3ISA::REG_INT_CONST_POS_MAX
@ REG_INT_CONST_POS_MAX
Definition: registers.hh:79
Gcn3ISA::opSelectorToRegSym
std::string opSelectorToRegSym(int idx, int numRegs)
Definition: registers.cc:39
Gcn3ISA::isLiteral
bool isLiteral(int opIdx)
Definition: registers.cc:191
Gcn3ISA::REG_NEG_TWO
@ REG_NEG_TWO
Definition: registers.hh:118
Gcn3ISA::REG_NEG_HALF
@ REG_NEG_HALF
Definition: registers.hh:114
Gcn3ISA::REG_NEG_FOUR
@ REG_NEG_FOUR
Definition: registers.hh:120
Gcn3ISA::REG_EXEC_HI
@ REG_EXEC_HI
Definition: registers.hh:76
Gcn3ISA::isConstVal
bool isConstVal(int opIdx)
Definition: registers.cc:184

Generated on Tue Mar 23 2021 19:41:23 for gem5 by doxygen 1.8.17