GPUOcelot
|
00001 00007 #ifndef IR_PTXOPERAND_H_INCLUDED 00008 #define IR_PTXOPERAND_H_INCLUDED 00009 00010 #include <string> 00011 #include <vector> 00012 #include <functional> 00013 #include <ocelot/ir/interface/Instruction.h> 00014 00015 namespace ir { 00016 00017 typedef unsigned char PTXU8; 00018 typedef unsigned short PTXU16; 00019 typedef unsigned int PTXU32; 00020 typedef unsigned long long PTXU64; 00021 00022 typedef char PTXS8; 00023 typedef short PTXS16; 00024 typedef int PTXS32; 00025 typedef long long PTXS64; 00026 00027 typedef float PTXF32; 00028 typedef double PTXF64; 00029 00030 typedef PTXU8 PTXB8; 00031 typedef PTXU16 PTXB16; 00032 typedef PTXU32 PTXB32; 00033 typedef PTXU64 PTXB64; 00034 00035 class PTXOperand { 00036 public: 00038 enum AddressMode { 00039 Register, 00040 Indirect, 00041 Immediate, 00042 Address, 00043 Label, 00044 Special, 00045 ArgumentList, 00046 FunctionName, 00047 BitBucket, 00048 Invalid 00049 }; 00050 00052 enum DataType { 00053 s8 = 0, 00054 s16, 00055 s32, 00056 s64, 00057 u8 = 4, 00058 u16, 00059 u32, 00060 u64, 00061 f16 = 8, 00062 f32, 00063 f64, 00064 b8, 00065 b16, 00066 b32, 00067 b64, 00068 pred, 00069 TypeSpecifier_invalid 00070 }; 00071 00073 enum SpecialRegister { 00074 tid, 00075 ntid, 00076 laneId, 00077 warpId, 00078 nwarpId, 00079 warpSize, 00080 ctaId, 00081 nctaId, 00082 smId, 00083 nsmId, 00084 gridId, 00085 clock, 00086 clock64, 00087 lanemask_eq, 00088 lanemask_le, 00089 lanemask_lt, 00090 lanemask_ge, 00091 lanemask_gt, 00092 pm0, 00093 pm1, 00094 pm2, 00095 pm3, 00096 envreg0, 00097 envreg1, 00098 envreg2, 00099 envreg3, 00100 envreg4, 00101 envreg5, 00102 envreg6, 00103 envreg7, 00104 envreg8, 00105 envreg9, 00106 envreg10, 00107 envreg11, 00108 envreg12, 00109 envreg13, 00110 envreg14, 00111 envreg15, 00112 envreg16, 00113 envreg17, 00114 envreg18, 00115 envreg19, 00116 envreg20, 00117 envreg21, 00118 envreg22, 00119 envreg23, 00120 envreg24, 00121 envreg25, 00122 envreg26, 00123 envreg27, 00124 envreg28, 00125 envreg29, 00126 envreg30, 00127 envreg31, 00128 SpecialRegister_invalid 00129 }; 00130 00131 enum PredicateCondition { 00132 Pred, //< instruction executes if predicate is true 00133 InvPred, //< instruction executes if predicate is false 00134 PT, //< predicate is always true 00135 nPT //< predicate is always false 00136 }; 00137 00138 enum Vec { 00139 v1 = 1, //< scalar 00140 v2 = 2, //< vector2 00141 v4 = 4 //< vector4 00142 }; 00143 00144 enum VectorIndex { 00145 iAll = 0, 00146 ix = 1, 00147 iy = 2, 00148 iz = 3, 00149 iw = 4 00150 }; 00151 00152 typedef std::vector<PTXOperand> Array; 00153 00154 typedef Instruction::RegisterType RegisterType; 00155 00156 public: 00157 static std::string toString(VectorIndex); 00158 static std::string toString(DataType); 00159 static std::string toString(SpecialRegister); 00160 static std::string toString(AddressMode); 00161 static std::string toString(DataType, RegisterType); 00162 static bool isFloat(DataType); 00163 static bool isInt(DataType); 00164 static bool isSigned(DataType); 00165 static unsigned int bytes(DataType); 00166 static bool valid(DataType, DataType); 00167 static bool relaxedValid(DataType instructionType, DataType); 00168 static long long unsigned int maxInt(DataType type); 00169 static long long unsigned int minInt(DataType type); 00170 00171 public: 00172 PTXOperand(); 00173 PTXOperand(SpecialRegister r, VectorIndex i = iAll, DataType t = u32); 00174 PTXOperand(const std::string& label); 00175 PTXOperand(AddressMode m, DataType t, RegisterType r = 0, 00176 int o = 0, Vec v = v1); 00177 PTXOperand(AddressMode m, DataType t, const std::string& identifier, 00178 int o = 0, Vec v = v1); 00179 PTXOperand(AddressMode m, const std::string& identifier); 00180 PTXOperand(long long unsigned int v, DataType t = u64); 00181 ~PTXOperand(); 00182 00183 std::string toString() const; 00184 std::string registerName() const; 00185 unsigned int bytes() const; 00186 bool isRegister() const; 00187 00189 std::string identifier; 00190 00192 AddressMode addressMode; 00193 00195 DataType type; 00196 00198 union { 00199 int offset; 00200 VectorIndex vIndex; 00201 unsigned int registerCount; 00202 }; 00203 00205 union { 00206 long long unsigned int imm_uint; 00207 long long int imm_int; 00208 double imm_float; 00209 PredicateCondition condition; 00210 SpecialRegister special; 00211 unsigned int localMemorySize; 00212 }; 00213 00214 union { 00216 RegisterType reg; 00217 bool isArgument; 00218 bool isGlobalLocal; 00219 unsigned int sharedMemorySize; 00220 }; 00221 00222 union { 00224 Vec vec; 00225 unsigned int stackMemorySize; 00226 }; 00227 00229 Array array; 00230 00231 }; 00232 00233 } 00234 00235 namespace std 00236 { 00237 template<> 00238 struct hash<ir::PTXOperand::DataType> 00239 { 00240 public: 00241 size_t operator()(const ir::PTXOperand::DataType& t) const 00242 { 00243 return (size_t)t; 00244 } 00245 }; 00246 } 00247 00248 #endif 00249