gem5  v22.1.0.0
operand_info.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-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 
32 #ifndef __GPU_COMPUTE_OPERAND_INFO_HH__
33 #define __GPU_COMPUTE_OPERAND_INFO_HH__
34 
35 #include "arch/gpu_registers.hh"
36 #include "base/flags.hh"
37 #include "config/the_gpu_isa.hh"
38 
39 namespace gem5
40 {
41 
43 {
44  public:
45  OperandInfo() = delete;
46  OperandInfo(int opSelectorVal, int size, bool src, bool scalar_reg,
47  bool vector_reg, bool imm)
48  : _opSelectorVal(opSelectorVal), _size(size),
49  _numDWords(size <= 4 ? 1 : size / 4)
50  {
51  if (src)
52  flags.set(SRC);
53  if (scalar_reg)
55  if (vector_reg)
57  if (imm)
59  if (TheGpuISA::isVccReg(opSelectorVal))
60  flags.set(VCC);
61  if (TheGpuISA::isExecMask(opSelectorVal))
62  flags.set(EXEC);
63  if (TheGpuISA::isFlatScratchReg(opSelectorVal))
64  flags.set(FLAT);
65  if (TheGpuISA::isLiteral(opSelectorVal))
66  flags.set(LITERAL);
67  if (TheGpuISA::isConstVal(opSelectorVal))
69  if (TheGpuISA::isPosConstVal(opSelectorVal))
71  }
72 
74  int sizeInDWords() const { return _numDWords; }
75 
76  int size() const { return _size; }
77  // Certain opIdx's get changed in calls to opSelectorToRegIdx
78  // This avoids that by returning the exact value
79  int rawRegisterIndex() const { return _opSelectorVal; }
80 
81  int
82  registerIndex(int numScalarRegs) const
83  {
84  // Some regs (i.e. VSRC, VDST) are explicitly declared as vectors
85  // as opposed to checking if it's a vector through a function call, so
86  // they don't have an offset applied and can be returned immediately
88  return _opSelectorVal;
89  return TheGpuISA::opSelectorToRegIdx(_opSelectorVal, numScalarRegs);
90  }
91  bool isSrc() const { return flags.isSet(SRC); }
92  bool isDst() const { return !flags.isSet(SRC); }
93  bool isImm() const { return flags.isSet(IMMEDIATE); }
94  bool isScalarReg() const { return flags.isSet(SCALAR_REG); }
95  bool isVectorReg() const { return flags.isSet(VECTOR_REG); }
96  bool isVcc() const { return flags.isSet(VCC); }
97  bool isExec() const { return flags.isSet(EXEC); }
98  bool isFlatScratch() const { return flags.isSet(FLAT); }
99 
100  void
102  {
103  _virtIndices = v;
104  _physIndices = p;
105 
106  assert(_virtIndices.size() == _physIndices.size());
107  assert(_numDWords == _physIndices.size());
108  }
109 
114  int virtIdx(int reg_num=0) const { return _virtIndices.at(reg_num); }
115  int physIdx(int reg_num=0) const { return _physIndices.at(reg_num); }
116 
117  const std::vector<int>&
118  virtIndices() const
119  {
120  return _virtIndices;
121  }
122 
123  const std::vector<int>&
124  physIndices() const
125  {
126  return _physIndices;
127  }
128 
131  {
132  return _bankReadCounts;
133  }
134 
135  typedef uint32_t FlagsType;
137 
138  private:
139 
140  enum : FlagsType {
141  // If the operand is a src or not
142  SRC = 0x00000001,
143 
144  // If the operand is a scalar or not
145  SCALAR_REG = 0x00000002,
146 
147  // If the operand is a vector or not
148  VECTOR_REG = 0x00000004,
149 
150  // If the operand is an immediate or not
151  IMMEDIATE = 0x00000008,
152 
153  // If the operand is a VCC register
154  VCC = 0x00000010,
155 
156  // If the operand is an EXEC register
157  EXEC = 0x00000020,
158 
159  // If the operand is a FLAT/SCRATCH register
160  FLAT = 0x00000040,
161 
162  // If the operand is a literal
163  LITERAL = 0x00000080,
164 
165  // If the operand is a constant value
166  CONSTANT = 0x00000100,
167 
168  // If the constant is positive or negative
169  POS_CONST = 0x00000200
170  };
171 
173 
177  const int _opSelectorVal;
178 
182  const int _size;
183 
187  const int _numDWords;
188 
191 
196 };
197 
198 } // namespace gem5
199 
200 #endif // __GPU_COMPUTE_OPERAND_INFO_H__
bool isExec() const
Definition: operand_info.hh:97
const int _size
Size of the operand in bytes.
bool isScalarReg() const
Definition: operand_info.hh:94
bool isImm() const
Definition: operand_info.hh:93
int size() const
Definition: operand_info.hh:76
const std::vector< int > & physIndices() const
std::vector< int > _physIndices
bool isFlatScratch() const
Definition: operand_info.hh:98
std::vector< int > & bankReadCounts() const
int physIdx(int reg_num=0) const
void setVirtToPhysMapping(std::vector< int > v, std::vector< int > p)
int sizeInDWords() const
Definition: operand_info.hh:74
bool isDst() const
Definition: operand_info.hh:92
const int _numDWords
Size of operand in DWords.
bool isSrc() const
Definition: operand_info.hh:91
int registerIndex(int numScalarRegs) const
Definition: operand_info.hh:82
std::vector< int > _virtIndices
OperandInfo(int opSelectorVal, int size, bool src, bool scalar_reg, bool vector_reg, bool imm)
Definition: operand_info.hh:46
bool isVectorReg() const
Definition: operand_info.hh:95
const int _opSelectorVal
Value of the operand as used in registers.cc functions.
std::vector< int > _bankReadCounts
The number of reads this operand will make to each bank.
const std::vector< int > & virtIndices() const
int rawRegisterIndex() const
Definition: operand_info.hh:79
OperandInfo()=delete
gem5::Flags< FlagsType > Flags
bool isVcc() const
Definition: operand_info.hh:96
int virtIdx(int reg_num=0) const
We typically only need the first virtual register for the operand regardless of its size.
int numRegisters() const
Definition: operand_info.hh:73
void set(Type mask)
Set all flag's bits matching the given mask.
Definition: flags.hh:116
bool isSet(Type mask) const
Verifies whether any bit matching the given mask is set.
Definition: flags.hh:83
Bitfield< 7, 0 > imm
Definition: types.hh:132
bool isFlatScratchReg(int opIdx)
Definition: registers.cc:213
int opSelectorToRegIdx(int opIdx, int numScalarRegs)
Definition: registers.cc:125
bool isExecMask(int opIdx)
Definition: registers.cc:201
bool isPosConstVal(int opIdx)
Definition: registers.cc:170
bool isConstVal(int opIdx)
Definition: registers.cc:188
bool isVccReg(int opIdx)
Definition: registers.cc:207
bool isLiteral(int opIdx)
Definition: registers.cc:195
const int RegSizeDWords
Size of a single-precision register in DWords.
Bitfield< 0 > v
Definition: pagetable.hh:65
Bitfield< 54 > p
Definition: pagetable.hh:70
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....

Generated on Wed Dec 21 2022 10:22:35 for gem5 by doxygen 1.9.1