| 1 |
/* |
| 2 |
* Copyright 2011 Christoph Bumiller |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included in |
| 12 |
* all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
*/ |
| 22 |
|
| 23 |
#include "nv50_ir_target_nv50.h" |
| 24 |
#include "pipe/p_shader_tokens.h" |
| 25 |
|
| 26 |
namespace nv50_ir { |
| 27 |
|
| 28 |
Target *getTargetNV50(unsigned int chipset) |
| 29 |
{ |
| 30 |
return new TargetNV50(chipset); |
| 31 |
} |
| 32 |
|
| 33 |
TargetNV50::TargetNV50(unsigned int card) : Target(true, true, false) |
| 34 |
{ |
| 35 |
chipset = card; |
| 36 |
|
| 37 |
wposMask = 0; |
| 38 |
for (unsigned int i = 0; i <= SV_LAST; ++i) |
| 39 |
sysvalLocation[i] = ~0; |
| 40 |
|
| 41 |
initOpInfo(); |
| 42 |
} |
| 43 |
|
| 44 |
#if 0 |
| 45 |
// BULTINS / LIBRARY FUNCTIONS: |
| 46 |
|
| 47 |
// TODO |
| 48 |
static const uint32_t nvc0_builtin_code[] = |
| 49 |
{ |
| 50 |
}; |
| 51 |
|
| 52 |
static const uint16_t nvc0_builtin_offsets[NV50_BUILTIN_COUNT] = |
| 53 |
{ |
| 54 |
}; |
| 55 |
#endif |
| 56 |
|
| 57 |
void |
| 58 |
TargetNV50::getBuiltinCode(const uint32_t **code, uint32_t *size) const |
| 59 |
{ |
| 60 |
*code = NULL; |
| 61 |
*size = 0; |
| 62 |
} |
| 63 |
|
| 64 |
uint32_t |
| 65 |
TargetNV50::getBuiltinOffset(int builtin) const |
| 66 |
{ |
| 67 |
return 0; |
| 68 |
} |
| 69 |
|
| 70 |
struct nv50_opProperties |
| 71 |
{ |
| 72 |
operation op; |
| 73 |
unsigned int mNeg : 4; |
| 74 |
unsigned int mAbs : 4; |
| 75 |
unsigned int mNot : 4; |
| 76 |
unsigned int mSat : 4; |
| 77 |
unsigned int fConst : 3; |
| 78 |
unsigned int fShared : 3; |
| 79 |
unsigned int fAttrib : 3; |
| 80 |
unsigned int fImm : 3; |
| 81 |
}; |
| 82 |
|
| 83 |
static const struct nv50_opProperties _initProps[] = |
| 84 |
{ |
| 85 |
// neg abs not sat c[] s[], a[], imm |
| 86 |
{ OP_ADD, 0x3, 0x0, 0x0, 0x8, 0x2, 0x1, 0x1, 0x2 }, |
| 87 |
{ OP_SUB, 0x3, 0x0, 0x0, 0x8, 0x2, 0x1, 0x1, 0x2 }, |
| 88 |
{ OP_MUL, 0x3, 0x0, 0x0, 0x0, 0x2, 0x1, 0x1, 0x2 }, |
| 89 |
{ OP_MAX, 0x3, 0x3, 0x0, 0x0, 0x2, 0x1, 0x1, 0x0 }, |
| 90 |
{ OP_MIN, 0x3, 0x3, 0x0, 0x0, 0x2, 0x1, 0x1, 0x0 }, |
| 91 |
{ OP_MAD, 0x7, 0x0, 0x0, 0x8, 0x6, 0x1, 0x1, 0x0 }, // special constraint |
| 92 |
{ OP_ABS, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x0 }, |
| 93 |
{ OP_NEG, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x1, 0x0 }, |
| 94 |
{ OP_CVT, 0x1, 0x1, 0x0, 0x8, 0x0, 0x1, 0x1, 0x0 }, |
| 95 |
{ OP_AND, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x0, 0x2 }, |
| 96 |
{ OP_OR, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x0, 0x2 }, |
| 97 |
{ OP_XOR, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x0, 0x2 }, |
| 98 |
{ OP_SHL, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2 }, |
| 99 |
{ OP_SHR, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2 }, |
| 100 |
{ OP_SET, 0x3, 0x3, 0x0, 0x0, 0x2, 0x1, 0x1, 0x0 }, |
| 101 |
{ OP_PREEX2, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }, |
| 102 |
{ OP_PRESIN, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }, |
| 103 |
{ OP_EX2, 0x0, 0x0, 0x0, 0x8, 0x0, 0x0, 0x0, 0x0 }, |
| 104 |
{ OP_LG2, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }, |
| 105 |
{ OP_RCP, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }, |
| 106 |
{ OP_RSQ, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }, |
| 107 |
{ OP_DFDX, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }, |
| 108 |
{ OP_DFDY, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }, |
| 109 |
}; |
| 110 |
|
| 111 |
void TargetNV50::initOpInfo() |
| 112 |
{ |
| 113 |
unsigned int i, j; |
| 114 |
|
| 115 |
static const operation commutativeList[] = |
| 116 |
{ |
| 117 |
OP_ADD, OP_MUL, OP_MAD, OP_FMA, OP_AND, OP_OR, OP_XOR, OP_MAX, OP_MIN, |
| 118 |
OP_SET_AND, OP_SET_OR, OP_SET_XOR, OP_SET, OP_SELP, OP_SLCT |
| 119 |
}; |
| 120 |
static const operation shortFormList[] = |
| 121 |
{ |
| 122 |
OP_MOV, OP_ADD, OP_SUB, OP_MUL, OP_MAD, OP_SAD, OP_RCP, OP_LINTERP, |
| 123 |
OP_PINTERP, OP_TEX, OP_TXF |
| 124 |
}; |
| 125 |
static const operation noDestList[] = |
| 126 |
{ |
| 127 |
OP_STORE, OP_EXPORT, OP_BRA, OP_CALL, OP_RET, OP_EXIT, |
| 128 |
OP_DISCARD, OP_CONT, OP_BREAK, OP_PRECONT, OP_PREBREAK, OP_PRERET, |
| 129 |
OP_JOIN, OP_JOINAT, OP_BRKPT, OP_MEMBAR, OP_EMIT, OP_RESTART, |
| 130 |
OP_QUADON, OP_QUADPOP, OP_TEXBAR, OP_SUSTB, OP_SUSTP, OP_SUREDP, |
| 131 |
OP_SUREDB, OP_BAR |
| 132 |
}; |
| 133 |
static const operation noPredList[] = |
| 134 |
{ |
| 135 |
OP_CALL, OP_PREBREAK, OP_PRERET, OP_QUADON, OP_QUADPOP, OP_JOINAT, |
| 136 |
OP_EMIT, OP_RESTART |
| 137 |
}; |
| 138 |
|
| 139 |
for (i = 0; i < DATA_FILE_COUNT; ++i) |
| 140 |
nativeFileMap[i] = (DataFile)i; |
| 141 |
nativeFileMap[FILE_PREDICATE] = FILE_FLAGS; |
| 142 |
|
| 143 |
for (i = 0; i < OP_LAST; ++i) { |
| 144 |
opInfo[i].variants = NULL; |
| 145 |
opInfo[i].op = (operation)i; |
| 146 |
opInfo[i].srcTypes = 1 << (int)TYPE_F32; |
| 147 |
opInfo[i].dstTypes = 1 << (int)TYPE_F32; |
| 148 |
opInfo[i].immdBits = 0xffffffff; |
| 149 |
opInfo[i].srcNr = operationSrcNr[i]; |
| 150 |
|
| 151 |
for (j = 0; j < opInfo[i].srcNr; ++j) { |
| 152 |
opInfo[i].srcMods[j] = 0; |
| 153 |
opInfo[i].srcFiles[j] = 1 << (int)FILE_GPR; |
| 154 |
} |
| 155 |
opInfo[i].dstMods = 0; |
| 156 |
opInfo[i].dstFiles = 1 << (int)FILE_GPR; |
| 157 |
|
| 158 |
opInfo[i].hasDest = 1; |
| 159 |
opInfo[i].vector = (i >= OP_TEX && i <= OP_TEXCSAA); |
| 160 |
opInfo[i].commutative = false; /* set below */ |
| 161 |
opInfo[i].pseudo = (i < OP_MOV); |
| 162 |
opInfo[i].predicate = !opInfo[i].pseudo; |
| 163 |
opInfo[i].flow = (i >= OP_BRA && i <= OP_JOIN); |
| 164 |
opInfo[i].minEncSize = 8; /* set below */ |
| 165 |
} |
| 166 |
for (i = 0; i < ARRAY_SIZE(commutativeList); ++i) |
| 167 |
opInfo[commutativeList[i]].commutative = true; |
| 168 |
for (i = 0; i < ARRAY_SIZE(shortFormList); ++i) |
| 169 |
opInfo[shortFormList[i]].minEncSize = 4; |
| 170 |
for (i = 0; i < ARRAY_SIZE(noDestList); ++i) |
| 171 |
opInfo[noDestList[i]].hasDest = 0; |
| 172 |
for (i = 0; i < ARRAY_SIZE(noPredList); ++i) |
| 173 |
opInfo[noPredList[i]].predicate = 0; |
| 174 |
|
| 175 |
for (i = 0; i < ARRAY_SIZE(_initProps); ++i) { |
| 176 |
const struct nv50_opProperties *prop = &_initProps[i]; |
| 177 |
|
| 178 |
for (int s = 0; s < 3; ++s) { |
| 179 |
if (prop->mNeg & (1 << s)) |
| 180 |
opInfo[prop->op].srcMods[s] |= NV50_IR_MOD_NEG; |
| 181 |
if (prop->mAbs & (1 << s)) |
| 182 |
opInfo[prop->op].srcMods[s] |= NV50_IR_MOD_ABS; |
| 183 |
if (prop->mNot & (1 << s)) |
| 184 |
opInfo[prop->op].srcMods[s] |= NV50_IR_MOD_NOT; |
| 185 |
if (prop->fConst & (1 << s)) |
| 186 |
opInfo[prop->op].srcFiles[s] |= 1 << (int)FILE_MEMORY_CONST; |
| 187 |
if (prop->fShared & (1 << s)) |
| 188 |
opInfo[prop->op].srcFiles[s] |= 1 << (int)FILE_MEMORY_SHARED; |
| 189 |
if (prop->fAttrib & (1 << s)) |
| 190 |
opInfo[prop->op].srcFiles[s] |= 1 << (int)FILE_SHADER_INPUT; |
| 191 |
if (prop->fImm & (1 << s)) |
| 192 |
opInfo[prop->op].srcFiles[s] |= 1 << (int)FILE_IMMEDIATE; |
| 193 |
} |
| 194 |
if (prop->mSat & 8) |
| 195 |
opInfo[prop->op].dstMods = NV50_IR_MOD_SAT; |
| 196 |
} |
| 197 |
|
| 198 |
if (chipset >= 0xa0) |
| 199 |
opInfo[OP_MUL].dstMods = NV50_IR_MOD_SAT; |
| 200 |
} |
| 201 |
|
| 202 |
unsigned int |
| 203 |
TargetNV50::getFileSize(DataFile file) const |
| 204 |
{ |
| 205 |
switch (file) { |
| 206 |
case FILE_NULL: return 0; |
| 207 |
case FILE_GPR: return 254; // in 16-bit units ** |
| 208 |
case FILE_PREDICATE: return 0; |
| 209 |
case FILE_FLAGS: return 4; |
| 210 |
case FILE_ADDRESS: return 4; |
| 211 |
case FILE_BARRIER: return 0; |
| 212 |
case FILE_IMMEDIATE: return 0; |
| 213 |
case FILE_MEMORY_CONST: return 65536; |
| 214 |
case FILE_SHADER_INPUT: return 0x200; |
| 215 |
case FILE_SHADER_OUTPUT: return 0x200; |
| 216 |
case FILE_MEMORY_BUFFER: return 0xffffffff; |
| 217 |
case FILE_MEMORY_GLOBAL: return 0xffffffff; |
| 218 |
case FILE_MEMORY_SHARED: return 16 << 10; |
| 219 |
case FILE_MEMORY_LOCAL: return 48 << 10; |
| 220 |
case FILE_SYSTEM_VALUE: return 16; |
| 221 |
default: |
| 222 |
assert(!"invalid file"); |
| 223 |
return 0; |
| 224 |
} |
| 225 |
// ** only first 128 units encodable for 16-bit regs |
| 226 |
} |
| 227 |
|
| 228 |
unsigned int |
| 229 |
TargetNV50::getFileUnit(DataFile file) const |
| 230 |
{ |
| 231 |
if (file == FILE_GPR || file == FILE_ADDRESS) |
| 232 |
return 1; |
| 233 |
if (file == FILE_SYSTEM_VALUE) |
| 234 |
return 2; |
| 235 |
return 0; |
| 236 |
} |
| 237 |
|
| 238 |
uint32_t |
| 239 |
TargetNV50::getSVAddress(DataFile shaderFile, const Symbol *sym) const |
| 240 |
{ |
| 241 |
switch (sym->reg.data.sv.sv) { |
| 242 |
case SV_FACE: |
| 243 |
return 0x3fc; |
| 244 |
case SV_POSITION: |
| 245 |
{ |
| 246 |
uint32_t addr = sysvalLocation[sym->reg.data.sv.sv]; |
| 247 |
for (int c = 0; c < sym->reg.data.sv.index; ++c) |
| 248 |
if (wposMask & (1 << c)) |
| 249 |
addr += 4; |
| 250 |
return addr; |
| 251 |
} |
| 252 |
case SV_PRIMITIVE_ID: |
| 253 |
return shaderFile == FILE_SHADER_INPUT ? 0x18 : |
| 254 |
sysvalLocation[sym->reg.data.sv.sv]; |
| 255 |
case SV_NCTAID: |
| 256 |
return sym->reg.data.sv.index >= 2 ? 0x10 : 0x8 + 2 * sym->reg.data.sv.index; |
| 257 |
case SV_CTAID: |
| 258 |
return sym->reg.data.sv.index >= 2 ? 0x12 : 0xc + 2 * sym->reg.data.sv.index; |
| 259 |
case SV_NTID: |
| 260 |
return 0x2 + 2 * sym->reg.data.sv.index; |
| 261 |
case SV_TID: |
| 262 |
case SV_COMBINED_TID: |
| 263 |
return 0; |
| 264 |
case SV_SAMPLE_POS: |
| 265 |
return 0; /* sample position is handled differently */ |
| 266 |
case SV_THREAD_KILL: |
| 267 |
return 0; |
| 268 |
default: |
| 269 |
return sysvalLocation[sym->reg.data.sv.sv]; |
| 270 |
} |
| 271 |
} |
| 272 |
|
| 273 |
// long: rrr, arr, rcr, acr, rrc, arc, gcr, grr |
| 274 |
// short: rr, ar, rc, gr |
| 275 |
// immd: ri, gi |
| 276 |
bool |
| 277 |
TargetNV50::insnCanLoad(const Instruction *i, int s, |
| 278 |
const Instruction *ld) const |
| 279 |
{ |
| 280 |
DataFile sf = ld->src(0).getFile(); |
| 281 |
|
| 282 |
// immediate 0 can be represented by GPR $r63/$r127 |
| 283 |
// this does not work with global memory ld/st/atom |
| 284 |
if (sf == FILE_IMMEDIATE && ld->getSrc(0)->reg.data.u64 == 0) |
| 285 |
return (!i->isPseudo() && |
| 286 |
!i->asTex() && |
| 287 |
i->op != OP_EXPORT && |
| 288 |
i->op != OP_STORE && |
| 289 |
((i->op != OP_ATOM && i->op != OP_LOAD) || |
| 290 |
i->src(0).getFile() != FILE_MEMORY_GLOBAL)); |
| 291 |
|
| 292 |
if (sf == FILE_IMMEDIATE && (i->predSrc >= 0 || i->flagsDef >= 0)) |
| 293 |
return false; |
| 294 |
if (s >= opInfo[i->op].srcNr) |
| 295 |
return false; |
| 296 |
if (!(opInfo[i->op].srcFiles[s] & (1 << (int)sf))) |
| 297 |
return false; |
| 298 |
if (s == 2 && i->src(1).getFile() != FILE_GPR) |
| 299 |
return false; |
| 300 |
|
| 301 |
// NOTE: don't rely on flagsDef |
| 302 |
if (sf == FILE_IMMEDIATE) |
| 303 |
for (int d = 0; i->defExists(d); ++d) |
| 304 |
if (i->def(d).getFile() == FILE_FLAGS) |
| 305 |
return false; |
| 306 |
|
| 307 |
unsigned mode = 0; |
| 308 |
|
| 309 |
for (int z = 0; z < Target::operationSrcNr[i->op]; ++z) { |
| 310 |
DataFile zf = (z == s) ? sf : i->src(z).getFile(); |
| 311 |
switch (zf) { |
| 312 |
case FILE_GPR: |
| 313 |
break; |
| 314 |
case FILE_MEMORY_SHARED: |
| 315 |
case FILE_SHADER_INPUT: |
| 316 |
mode |= 1 << (z * 2); |
| 317 |
break; |
| 318 |
case FILE_MEMORY_CONST: |
| 319 |
mode |= 2 << (z * 2); |
| 320 |
break; |
| 321 |
case FILE_IMMEDIATE: |
| 322 |
mode |= 3 << (z * 2); |
| 323 |
default: |
| 324 |
break; |
| 325 |
} |
| 326 |
} |
| 327 |
|
| 328 |
switch (mode) { |
| 329 |
case 0x00: |
| 330 |
case 0x01: |
| 331 |
case 0x03: |
| 332 |
case 0x08: |
| 333 |
case 0x0c: |
| 334 |
case 0x20: |
| 335 |
case 0x21: |
| 336 |
break; |
| 337 |
case 0x09: |
| 338 |
// Shader inputs get transformed to p[] in geometry shaders, and those |
| 339 |
// aren't allowed to be used at the same time as c[]. |
| 340 |
if (ld->bb->getProgram()->getType() == Program::TYPE_GEOMETRY) |
| 341 |
return false; |
| 342 |
break; |
| 343 |
case 0x0d: |
| 344 |
if (ld->bb->getProgram()->getType() != Program::TYPE_GEOMETRY) |
| 345 |
return false; |
| 346 |
break; |
| 347 |
default: |
| 348 |
return false; |
| 349 |
} |
| 350 |
|
| 351 |
uint8_t ldSize; |
| 352 |
|
| 353 |
if ((i->op == OP_MUL || i->op == OP_MAD) && !isFloatType(i->dType)) { |
| 354 |
// 32-bit MUL will be split into 16-bit MULs |
| 355 |
if (ld->src(0).isIndirect(0)) |
| 356 |
return false; |
| 357 |
if (sf == FILE_IMMEDIATE) |
| 358 |
return false; |
| 359 |
if (i->subOp == NV50_IR_SUBOP_MUL_HIGH && sf == FILE_MEMORY_CONST) |
| 360 |
return false; |
| 361 |
ldSize = 2; |
| 362 |
} else { |
| 363 |
ldSize = typeSizeof(ld->dType); |
| 364 |
} |
| 365 |
|
| 366 |
if (sf == FILE_IMMEDIATE) { |
| 367 |
if (ldSize == 2 && (i->op == OP_AND || i->op == OP_OR || i->op == OP_XOR)) |
| 368 |
return false; |
| 369 |
return ldSize <= 4; |
| 370 |
} |
| 371 |
|
| 372 |
|
| 373 |
// Check if memory access is encodable: |
| 374 |
|
| 375 |
if (ldSize < 4 && sf == FILE_SHADER_INPUT) // no < 4-byte aligned a[] access |
| 376 |
return false; |
| 377 |
if (ld->getSrc(0)->reg.data.offset > (int32_t)(127 * ldSize)) |
| 378 |
return false; |
| 379 |
|
| 380 |
if (ld->src(0).isIndirect(0)) { |
| 381 |
for (int z = 0; i->srcExists(z); ++z) |
| 382 |
if (i->src(z).isIndirect(0)) |
| 383 |
return false; |
| 384 |
|
| 385 |
// s[] access only possible in CP, $aX always applies |
| 386 |
if (sf == FILE_MEMORY_SHARED) |
| 387 |
return true; |
| 388 |
if (!ld->bb) // can't check type ... |
| 389 |
return false; |
| 390 |
Program::Type pt = ld->bb->getProgram()->getType(); |
| 391 |
|
| 392 |
// $aX applies to c[] only in VP, FP, GP if p[] is not accessed |
| 393 |
if (pt == Program::TYPE_COMPUTE) |
| 394 |
return false; |
| 395 |
if (pt == Program::TYPE_GEOMETRY) { |
| 396 |
if (sf == FILE_MEMORY_CONST) |
| 397 |
return i->src(s).getFile() != FILE_SHADER_INPUT; |
| 398 |
return sf == FILE_SHADER_INPUT; |
| 399 |
} |
| 400 |
return sf == FILE_MEMORY_CONST; |
| 401 |
} |
| 402 |
return true; |
| 403 |
} |
| 404 |
|
| 405 |
bool |
| 406 |
TargetNV50::insnCanLoadOffset(const Instruction *i, int s, int offset) const |
| 407 |
{ |
| 408 |
if (!i->src(s).isIndirect(0)) |
| 409 |
return true; |
| 410 |
offset += i->src(s).get()->reg.data.offset; |
| 411 |
if (i->op == OP_LOAD || i->op == OP_STORE || i->op == OP_ATOM) { |
| 412 |
// There are some restrictions in theory, but in practice they're never |
| 413 |
// going to be hit. However offsets on global/shared memory are just |
| 414 |
// plain not supported. |
| 415 |
return i->src(s).getFile() != FILE_MEMORY_GLOBAL && |
| 416 |
i->src(s).getFile() != FILE_MEMORY_SHARED; |
| 417 |
} |
| 418 |
return offset >= 0 && offset <= (int32_t)(127 * i->src(s).get()->reg.size); |
| 419 |
} |
| 420 |
|
| 421 |
bool |
| 422 |
TargetNV50::isAccessSupported(DataFile file, DataType ty) const |
| 423 |
{ |
| 424 |
if (ty == TYPE_B96 || ty == TYPE_NONE) |
| 425 |
return false; |
| 426 |
if (typeSizeof(ty) > 4) |
| 427 |
return (file == FILE_MEMORY_LOCAL) || (file == FILE_MEMORY_GLOBAL) || |
| 428 |
(file == FILE_MEMORY_BUFFER); |
| 429 |
return true; |
| 430 |
} |
| 431 |
|
| 432 |
bool |
| 433 |
TargetNV50::isOpSupported(operation op, DataType ty) const |
| 434 |
{ |
| 435 |
if (ty == TYPE_F64 && chipset < 0xa0) |
| 436 |
return false; |
| 437 |
|
| 438 |
switch (op) { |
| 439 |
case OP_PRERET: |
| 440 |
return chipset >= 0xa0; |
| 441 |
case OP_TXG: |
| 442 |
return chipset >= 0xa3 && chipset != 0xaa && chipset != 0xac; |
| 443 |
case OP_SQRT: |
| 444 |
case OP_DIV: |
| 445 |
case OP_MOD: |
| 446 |
case OP_SET_AND: |
| 447 |
case OP_SET_OR: |
| 448 |
case OP_SET_XOR: |
| 449 |
case OP_SLCT: |
| 450 |
case OP_SELP: |
| 451 |
case OP_POPCNT: |
| 452 |
case OP_INSBF: |
| 453 |
case OP_EXTBF: |
| 454 |
case OP_EXIT: // want exit modifier instead (on NOP if required) |
| 455 |
case OP_MEMBAR: |
| 456 |
case OP_SHLADD: |
| 457 |
case OP_XMAD: |
| 458 |
return false; |
| 459 |
case OP_SAD: |
| 460 |
return ty == TYPE_S32; |
| 461 |
case OP_SET: |
| 462 |
return !isFloatType(ty); |
| 463 |
default: |
| 464 |
return true; |
| 465 |
} |
| 466 |
} |
| 467 |
|
| 468 |
bool |
| 469 |
TargetNV50::isModSupported(const Instruction *insn, int s, Modifier mod) const |
| 470 |
{ |
| 471 |
if (!isFloatType(insn->dType)) { |
| 472 |
switch (insn->op) { |
| 473 |
case OP_ABS: |
| 474 |
case OP_NEG: |
| 475 |
case OP_CVT: |
| 476 |
case OP_CEIL: |
| 477 |
case OP_FLOOR: |
| 478 |
case OP_TRUNC: |
| 479 |
case OP_AND: |
| 480 |
case OP_OR: |
| 481 |
case OP_XOR: |
| 482 |
break; |
| 483 |
case OP_ADD: |
| 484 |
if (insn->src(s ? 0 : 1).mod.neg()) |
| 485 |
return false; |
| 486 |
break; |
| 487 |
case OP_SUB: |
| 488 |
if (s == 0) |
| 489 |
return insn->src(1).mod.neg() ? false : true; |
| 490 |
break; |
| 491 |
case OP_SET: |
| 492 |
if (insn->sType != TYPE_F32) |
| 493 |
return false; |
| 494 |
break; |
| 495 |
default: |
| 496 |
return false; |
| 497 |
} |
| 498 |
} |
| 499 |
if (s >= opInfo[insn->op].srcNr || s >= 3) |
| 500 |
return false; |
| 501 |
return (mod & Modifier(opInfo[insn->op].srcMods[s])) == mod; |
| 502 |
} |
| 503 |
|
| 504 |
bool |
| 505 |
TargetNV50::mayPredicate(const Instruction *insn, const Value *pred) const |
| 506 |
{ |
| 507 |
if (insn->getPredicate() || insn->flagsSrc >= 0) |
| 508 |
return false; |
| 509 |
for (int s = 0; insn->srcExists(s); ++s) |
| 510 |
if (insn->src(s).getFile() == FILE_IMMEDIATE) |
| 511 |
return false; |
| 512 |
return opInfo[insn->op].predicate; |
| 513 |
} |
| 514 |
|
| 515 |
bool |
| 516 |
TargetNV50::isSatSupported(const Instruction *insn) const |
| 517 |
{ |
| 518 |
if (insn->op == OP_CVT) |
| 519 |
return true; |
| 520 |
if (insn->dType != TYPE_F32) |
| 521 |
return false; |
| 522 |
return opInfo[insn->op].dstMods & NV50_IR_MOD_SAT; |
| 523 |
} |
| 524 |
|
| 525 |
int TargetNV50::getLatency(const Instruction *i) const |
| 526 |
{ |
| 527 |
// TODO: tune these values |
| 528 |
if (i->op == OP_LOAD) { |
| 529 |
switch (i->src(0).getFile()) { |
| 530 |
case FILE_MEMORY_LOCAL: |
| 531 |
case FILE_MEMORY_GLOBAL: |
| 532 |
case FILE_MEMORY_BUFFER: |
| 533 |
return 100; // really 400 to 800 |
| 534 |
default: |
| 535 |
return 22; |
| 536 |
} |
| 537 |
} |
| 538 |
return 22; |
| 539 |
} |
| 540 |
|
| 541 |
// These are "inverse" throughput values, i.e. the number of cycles required |
| 542 |
// to issue a specific instruction for a full warp (32 threads). |
| 543 |
// |
| 544 |
// Assuming we have more than 1 warp in flight, a higher issue latency results |
| 545 |
// in a lower result latency since the MP will have spent more time with other |
| 546 |
// warps. |
| 547 |
// This also helps to determine the number of cycles between instructions in |
| 548 |
// a single warp. |
| 549 |
// |
| 550 |
int TargetNV50::getThroughput(const Instruction *i) const |
| 551 |
{ |
| 552 |
// TODO: tune these values |
| 553 |
if (i->dType == TYPE_F32) { |
| 554 |
switch (i->op) { |
| 555 |
case OP_RCP: |
| 556 |
case OP_RSQ: |
| 557 |
case OP_LG2: |
| 558 |
case OP_SIN: |
| 559 |
case OP_COS: |
| 560 |
case OP_PRESIN: |
| 561 |
case OP_PREEX2: |
| 562 |
return 16; |
| 563 |
default: |
| 564 |
return 4; |
| 565 |
} |
| 566 |
} else |
| 567 |
if (i->dType == TYPE_U32 || i->dType == TYPE_S32) { |
| 568 |
return 4; |
| 569 |
} else |
| 570 |
if (i->dType == TYPE_F64) { |
| 571 |
return 32; |
| 572 |
} else { |
| 573 |
return 1; |
| 574 |
} |
| 575 |
} |
| 576 |
|
| 577 |
static void |
| 578 |
recordLocation(uint16_t *locs, uint8_t *masks, |
| 579 |
const struct nv50_ir_varying *var) |
| 580 |
{ |
| 581 |
uint16_t addr = var->slot[0] * 4; |
| 582 |
|
| 583 |
switch (var->sn) { |
| 584 |
case TGSI_SEMANTIC_POSITION: locs[SV_POSITION] = addr; break; |
| 585 |
case TGSI_SEMANTIC_INSTANCEID: locs[SV_INSTANCE_ID] = addr; break; |
| 586 |
case TGSI_SEMANTIC_VERTEXID: locs[SV_VERTEX_ID] = addr; break; |
| 587 |
case TGSI_SEMANTIC_PRIMID: locs[SV_PRIMITIVE_ID] = addr; break; |
| 588 |
case TGSI_SEMANTIC_LAYER: locs[SV_LAYER] = addr; break; |
| 589 |
case TGSI_SEMANTIC_VIEWPORT_INDEX: locs[SV_VIEWPORT_INDEX] = addr; break; |
| 590 |
default: |
| 591 |
break; |
| 592 |
} |
| 593 |
if (var->sn == TGSI_SEMANTIC_POSITION && masks) |
| 594 |
masks[0] = var->mask; |
| 595 |
} |
| 596 |
|
| 597 |
static void |
| 598 |
recordLocationSysVal(uint16_t *locs, uint8_t *masks, |
| 599 |
const struct nv50_ir_sysval *var) |
| 600 |
{ |
| 601 |
uint16_t addr = var->slot[0] * 4; |
| 602 |
|
| 603 |
switch (var->sn) { |
| 604 |
case SYSTEM_VALUE_FRAG_COORD: locs[SV_POSITION] = addr; break; |
| 605 |
case SYSTEM_VALUE_INSTANCE_ID: locs[SV_INSTANCE_ID] = addr; break; |
| 606 |
case SYSTEM_VALUE_VERTEX_ID: locs[SV_VERTEX_ID] = addr; break; |
| 607 |
case SYSTEM_VALUE_PRIMITIVE_ID: locs[SV_PRIMITIVE_ID] = addr; break; |
| 608 |
default: |
| 609 |
break; |
| 610 |
} |
| 611 |
// TODO is this even hit? |
| 612 |
if (var->sn == SYSTEM_VALUE_FRAG_COORD && masks) |
| 613 |
masks[0] = 0; |
| 614 |
} |
| 615 |
|
| 616 |
void |
| 617 |
TargetNV50::parseDriverInfo(const struct nv50_ir_prog_info *info, |
| 618 |
const struct nv50_ir_prog_info_out *info_out) |
| 619 |
{ |
| 620 |
unsigned int i; |
| 621 |
for (i = 0; i < info_out->numOutputs; ++i) |
| 622 |
recordLocation(sysvalLocation, NULL, &info_out->out[i]); |
| 623 |
for (i = 0; i < info_out->numInputs; ++i) |
| 624 |
recordLocation(sysvalLocation, &wposMask, &info_out->in[i]); |
| 625 |
for (i = 0; i < info_out->numSysVals; ++i) |
| 626 |
recordLocationSysVal(sysvalLocation, NULL, &info_out->sv[i]); |
| 627 |
|
| 628 |
if (sysvalLocation[SV_POSITION] >= 0x200) { |
| 629 |
// not assigned by driver, but we need it internally |
| 630 |
wposMask = 0x8; |
| 631 |
sysvalLocation[SV_POSITION] = 0; |
| 632 |
} |
| 633 |
|
| 634 |
Target::parseDriverInfo(info, info_out); |
| 635 |
} |
| 636 |
|
| 637 |
} // namespace nv50_ir |