Path: blob/21.2-virgl/src/gallium/drivers/nouveau/codegen/nv50_ir_target_nvc0.cpp
4574 views
/*1* Copyright 2011 Christoph Bumiller2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice shall be included in11* all copies or substantial portions of the Software.12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL16* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR17* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,18* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR19* OTHER DEALINGS IN THE SOFTWARE.20*/2122#include "codegen/nv50_ir_target_nvc0.h"2324namespace nv50_ir {2526Target *getTargetNVC0(unsigned int chipset)27{28return new TargetNVC0(chipset);29}3031TargetNVC0::TargetNVC0(unsigned int card) :32Target(card < 0x110, false, card >= 0xe4 && card < 0x140)33{34chipset = card;35initOpInfo();36}3738// BULTINS / LIBRARY FUNCTIONS:3940// lazyness -> will just hardcode everything for the time being4142#include "lib/gf100.asm.h"43#include "lib/gk104.asm.h"44#include "lib/gk110.asm.h"4546void47TargetNVC0::getBuiltinCode(const uint32_t **code, uint32_t *size) const48{49switch (chipset & ~0xf) {50case 0xe0:51if (chipset < NVISA_GK20A_CHIPSET) {52*code = (const uint32_t *)&gk104_builtin_code[0];53*size = sizeof(gk104_builtin_code);54break;55}56FALLTHROUGH; /* for GK20A */57case 0xf0:58case 0x100:59*code = (const uint32_t *)&gk110_builtin_code[0];60*size = sizeof(gk110_builtin_code);61break;62default:63*code = (const uint32_t *)&gf100_builtin_code[0];64*size = sizeof(gf100_builtin_code);65break;66}67}6869uint32_t70TargetNVC0::getBuiltinOffset(int builtin) const71{72assert(builtin < NVC0_BUILTIN_COUNT);7374switch (chipset & ~0xf) {75case 0xe0:76if (chipset < NVISA_GK20A_CHIPSET)77return gk104_builtin_offsets[builtin];78FALLTHROUGH; /* for GK20A */79case 0xf0:80case 0x100:81return gk110_builtin_offsets[builtin];82default:83return gf100_builtin_offsets[builtin];84}85}8687struct nvc0_opProperties88{89operation op;90unsigned int mNeg : 4;91unsigned int mAbs : 4;92unsigned int mNot : 4;93unsigned int mSat : 4;94unsigned int fConst : 3;95unsigned int fImmd : 4; // last bit indicates if full immediate is suppoted96};9798static const struct nvc0_opProperties _initProps[] =99{100// neg abs not sat c[] imm101{ OP_ADD, 0x3, 0x3, 0x0, 0x8, 0x2, 0x2 | 0x8 },102{ OP_SUB, 0x3, 0x3, 0x0, 0x0, 0x2, 0x2 | 0x8 },103{ OP_MUL, 0x3, 0x0, 0x0, 0x8, 0x2, 0x2 | 0x8 },104{ OP_MAX, 0x3, 0x3, 0x0, 0x0, 0x2, 0x2 },105{ OP_MIN, 0x3, 0x3, 0x0, 0x0, 0x2, 0x2 },106{ OP_MAD, 0x7, 0x0, 0x0, 0x8, 0x6, 0x2 }, // special c[] constraint107{ OP_FMA, 0x7, 0x0, 0x0, 0x8, 0x6, 0x2 }, // keep the same as OP_MAD108{ OP_SHLADD, 0x5, 0x0, 0x0, 0x0, 0x4, 0x6 },109{ OP_MADSP, 0x0, 0x0, 0x0, 0x0, 0x6, 0x2 },110{ OP_ABS, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0 },111{ OP_NEG, 0x0, 0x1, 0x0, 0x0, 0x1, 0x0 },112{ OP_CVT, 0x1, 0x1, 0x0, 0x8, 0x1, 0x0 },113{ OP_CEIL, 0x1, 0x1, 0x0, 0x8, 0x1, 0x0 },114{ OP_FLOOR, 0x1, 0x1, 0x0, 0x8, 0x1, 0x0 },115{ OP_TRUNC, 0x1, 0x1, 0x0, 0x8, 0x1, 0x0 },116{ OP_AND, 0x0, 0x0, 0x3, 0x0, 0x2, 0x2 | 0x8 },117{ OP_OR, 0x0, 0x0, 0x3, 0x0, 0x2, 0x2 | 0x8 },118{ OP_XOR, 0x0, 0x0, 0x3, 0x0, 0x2, 0x2 | 0x8 },119{ OP_SHL, 0x0, 0x0, 0x0, 0x0, 0x2, 0x2 },120{ OP_SHR, 0x0, 0x0, 0x0, 0x0, 0x2, 0x2 },121{ OP_SET, 0x3, 0x3, 0x0, 0x0, 0x2, 0x2 },122{ OP_SLCT, 0x4, 0x0, 0x0, 0x0, 0x6, 0x2 }, // special c[] constraint123{ OP_PREEX2, 0x1, 0x1, 0x0, 0x0, 0x1, 0x1 },124{ OP_PRESIN, 0x1, 0x1, 0x0, 0x0, 0x1, 0x1 },125{ OP_COS, 0x1, 0x1, 0x0, 0x8, 0x0, 0x0 },126{ OP_SIN, 0x1, 0x1, 0x0, 0x8, 0x0, 0x0 },127{ OP_EX2, 0x1, 0x1, 0x0, 0x8, 0x0, 0x0 },128{ OP_LG2, 0x1, 0x1, 0x0, 0x8, 0x0, 0x0 },129{ OP_RCP, 0x1, 0x1, 0x0, 0x8, 0x0, 0x0 },130{ OP_RSQ, 0x1, 0x1, 0x0, 0x8, 0x0, 0x0 },131{ OP_SQRT, 0x1, 0x1, 0x0, 0x8, 0x0, 0x0 },132{ OP_DFDX, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0 },133{ OP_DFDY, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0 },134{ OP_CALL, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0 },135{ OP_POPCNT, 0x0, 0x0, 0x3, 0x0, 0x2, 0x2 },136{ OP_INSBF, 0x0, 0x0, 0x0, 0x0, 0x6, 0x2 },137{ OP_EXTBF, 0x0, 0x0, 0x0, 0x0, 0x2, 0x2 },138{ OP_BFIND, 0x0, 0x0, 0x1, 0x0, 0x1, 0x1 },139{ OP_PERMT, 0x0, 0x0, 0x0, 0x0, 0x6, 0x2 },140{ OP_SET_AND, 0x3, 0x3, 0x0, 0x0, 0x2, 0x2 },141{ OP_SET_OR, 0x3, 0x3, 0x0, 0x0, 0x2, 0x2 },142{ OP_SET_XOR, 0x3, 0x3, 0x0, 0x0, 0x2, 0x2 },143// saturate only:144{ OP_LINTERP, 0x0, 0x0, 0x0, 0x8, 0x0, 0x0 },145{ OP_PINTERP, 0x0, 0x0, 0x0, 0x8, 0x0, 0x0 },146};147148static const struct nvc0_opProperties _initPropsNVE4[] = {149{ OP_SULDB, 0x0, 0x0, 0x0, 0x0, 0x2, 0x0 },150{ OP_SUSTB, 0x0, 0x0, 0x0, 0x0, 0x2, 0x0 },151{ OP_SUSTP, 0x0, 0x0, 0x0, 0x0, 0x2, 0x0 },152{ OP_SUCLAMP, 0x0, 0x0, 0x0, 0x0, 0x2, 0x2 },153{ OP_SUBFM, 0x0, 0x0, 0x0, 0x0, 0x6, 0x2 },154{ OP_SUEAU, 0x0, 0x0, 0x0, 0x0, 0x6, 0x2 }155};156157static const struct nvc0_opProperties _initPropsGM107[] = {158{ OP_SULDB, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2 },159{ OP_SULDP, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2 },160{ OP_SUSTB, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4 },161{ OP_SUSTP, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4 },162{ OP_SUREDB, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4 },163{ OP_SUREDP, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4 },164{ OP_XMAD, 0x0, 0x0, 0x0, 0x0, 0x6, 0x2 },165};166167void TargetNVC0::initProps(const struct nvc0_opProperties *props, int size)168{169for (int i = 0; i < size; ++i) {170const struct nvc0_opProperties *prop = &props[i];171172for (int s = 0; s < 3; ++s) {173if (prop->mNeg & (1 << s))174opInfo[prop->op].srcMods[s] |= NV50_IR_MOD_NEG;175if (prop->mAbs & (1 << s))176opInfo[prop->op].srcMods[s] |= NV50_IR_MOD_ABS;177if (prop->mNot & (1 << s))178opInfo[prop->op].srcMods[s] |= NV50_IR_MOD_NOT;179if (prop->fConst & (1 << s))180opInfo[prop->op].srcFiles[s] |= 1 << (int)FILE_MEMORY_CONST;181if (prop->fImmd & (1 << s))182opInfo[prop->op].srcFiles[s] |= 1 << (int)FILE_IMMEDIATE;183if (prop->fImmd & 8)184opInfo[prop->op].immdBits = 0xffffffff;185}186if (prop->mSat & 8)187opInfo[prop->op].dstMods = NV50_IR_MOD_SAT;188}189}190191void TargetNVC0::initOpInfo()192{193unsigned int i, j;194195static const operation commutative[] =196{197OP_ADD, OP_MUL, OP_MAD, OP_FMA, OP_AND, OP_OR, OP_XOR, OP_MAX, OP_MIN,198OP_SET_AND, OP_SET_OR, OP_SET_XOR, OP_SET, OP_SELP, OP_SLCT199};200201static const operation shortForm[] =202{203OP_ADD, OP_MUL, OP_MAD, OP_FMA, OP_AND, OP_OR, OP_XOR, OP_MAX, OP_MIN204};205206static const operation noDest[] =207{208OP_STORE, OP_WRSV, OP_EXPORT, OP_BRA, OP_CALL, OP_RET, OP_EXIT,209OP_DISCARD, OP_CONT, OP_BREAK, OP_PRECONT, OP_PREBREAK, OP_PRERET,210OP_JOIN, OP_JOINAT, OP_BRKPT, OP_MEMBAR, OP_EMIT, OP_RESTART,211OP_QUADON, OP_QUADPOP, OP_TEXBAR, OP_SUSTB, OP_SUSTP, OP_SUREDP,212OP_SUREDB, OP_BAR213};214215static const operation noPred[] =216{217OP_CALL, OP_PRERET, OP_QUADON, OP_QUADPOP,218OP_JOINAT, OP_PREBREAK, OP_PRECONT, OP_BRKPT219};220221for (i = 0; i < DATA_FILE_COUNT; ++i)222nativeFileMap[i] = (DataFile)i;223nativeFileMap[FILE_ADDRESS] = FILE_GPR;224225for (i = 0; i < OP_LAST; ++i) {226opInfo[i].variants = NULL;227opInfo[i].op = (operation)i;228opInfo[i].srcTypes = 1 << (int)TYPE_F32;229opInfo[i].dstTypes = 1 << (int)TYPE_F32;230opInfo[i].immdBits = 0;231opInfo[i].srcNr = operationSrcNr[i];232233for (j = 0; j < opInfo[i].srcNr; ++j) {234opInfo[i].srcMods[j] = 0;235opInfo[i].srcFiles[j] = 1 << (int)FILE_GPR;236}237opInfo[i].dstMods = 0;238opInfo[i].dstFiles = 1 << (int)FILE_GPR;239240opInfo[i].hasDest = 1;241opInfo[i].vector = (i >= OP_TEX && i <= OP_TEXCSAA);242opInfo[i].commutative = false; /* set below */243opInfo[i].pseudo = (i < OP_MOV);244opInfo[i].predicate = !opInfo[i].pseudo;245opInfo[i].flow = (i >= OP_BRA && i <= OP_JOIN);246opInfo[i].minEncSize = 8; /* set below */247}248for (i = 0; i < ARRAY_SIZE(commutative); ++i)249opInfo[commutative[i]].commutative = true;250for (i = 0; i < ARRAY_SIZE(shortForm); ++i)251opInfo[shortForm[i]].minEncSize = 4;252for (i = 0; i < ARRAY_SIZE(noDest); ++i)253opInfo[noDest[i]].hasDest = 0;254for (i = 0; i < ARRAY_SIZE(noPred); ++i)255opInfo[noPred[i]].predicate = 0;256257initProps(_initProps, ARRAY_SIZE(_initProps));258if (chipset >= NVISA_GM107_CHIPSET)259initProps(_initPropsGM107, ARRAY_SIZE(_initPropsGM107));260else if (chipset >= NVISA_GK104_CHIPSET)261initProps(_initPropsNVE4, ARRAY_SIZE(_initPropsNVE4));262}263264unsigned int265TargetNVC0::getFileSize(DataFile file) const266{267const unsigned int gprs = (chipset >= NVISA_GK20A_CHIPSET) ? 255 : 63;268const unsigned int smregs = (chipset >= NVISA_GK104_CHIPSET) ? 65536 : 32768;269const unsigned int bs = (chipset >= NVISA_GV100_CHIPSET) ? 16 : 0;270switch (file) {271case FILE_NULL: return 0;272case FILE_GPR: return MIN2(gprs, smregs / threads);273case FILE_PREDICATE: return 7;274case FILE_FLAGS: return 1;275case FILE_ADDRESS: return 0;276case FILE_BARRIER: return bs;277case FILE_IMMEDIATE: return 0;278case FILE_MEMORY_CONST: return 65536;279case FILE_SHADER_INPUT: return 0x400;280case FILE_SHADER_OUTPUT: return 0x400;281case FILE_MEMORY_BUFFER: return 0xffffffff;282case FILE_MEMORY_GLOBAL: return 0xffffffff;283case FILE_MEMORY_SHARED: return 16 << 10;284case FILE_MEMORY_LOCAL: return 48 << 10;285case FILE_SYSTEM_VALUE: return 32;286case FILE_THREAD_STATE: return bs;287default:288assert(!"invalid file");289return 0;290}291}292293unsigned int294TargetNVC0::getFileUnit(DataFile file) const295{296if (file == FILE_GPR || file == FILE_ADDRESS || file == FILE_SYSTEM_VALUE ||297file == FILE_BARRIER || file == FILE_THREAD_STATE)298return 2;299return 0;300}301302uint32_t303TargetNVC0::getSVAddress(DataFile shaderFile, const Symbol *sym) const304{305const int idx = sym->reg.data.sv.index;306const SVSemantic sv = sym->reg.data.sv.sv;307308const bool isInput = shaderFile == FILE_SHADER_INPUT;309const bool kepler = getChipset() >= NVISA_GK104_CHIPSET;310311switch (sv) {312case SV_POSITION: return 0x070 + idx * 4;313case SV_INSTANCE_ID: return 0x2f8;314case SV_VERTEX_ID: return 0x2fc;315case SV_PRIMITIVE_ID: return isInput ? 0x060 : 0x040;316case SV_LAYER: return 0x064;317case SV_VIEWPORT_INDEX: return 0x068;318case SV_POINT_SIZE: return 0x06c;319case SV_CLIP_DISTANCE: return 0x2c0 + idx * 4;320case SV_POINT_COORD: return 0x2e0 + idx * 4;321case SV_FACE: return 0x3fc;322case SV_TESS_OUTER: return 0x000 + idx * 4;323case SV_TESS_INNER: return 0x010 + idx * 4;324case SV_TESS_COORD: return 0x2f0 + idx * 4;325case SV_NTID: return kepler ? (0x00 + idx * 4) : ~0;326case SV_NCTAID: return kepler ? (0x0c + idx * 4) : ~0;327case SV_GRIDID: return kepler ? 0x18 : ~0;328case SV_WORK_DIM: return 0x1c;329case SV_SAMPLE_INDEX: return 0;330case SV_SAMPLE_POS: return 0;331case SV_SAMPLE_MASK: return 0;332case SV_BASEVERTEX: return 0;333case SV_BASEINSTANCE: return 0;334case SV_DRAWID: return 0;335default:336return 0xffffffff;337}338}339340bool341TargetNVC0::insnCanLoad(const Instruction *i, int s,342const Instruction *ld) const343{344DataFile sf = ld->src(0).getFile();345346// immediate 0 can be represented by GPR $r63/$r255347if (sf == FILE_IMMEDIATE && ld->getSrc(0)->reg.data.u64 == 0)348return (!i->isPseudo() &&349!i->asTex() &&350i->op != OP_EXPORT && i->op != OP_STORE);351352if (s >= opInfo[i->op].srcNr)353return false;354if (!(opInfo[i->op].srcFiles[s] & (1 << (int)sf)))355return false;356357// indirect loads can only be done by OP_LOAD/VFETCH/INTERP on nvc0358if (ld->src(0).isIndirect(0))359return false;360// these are implemented using shf.r and shf.l which can't load consts361if ((i->op == OP_SHL || i->op == OP_SHR) && typeSizeof(i->sType) == 8 &&362sf == FILE_MEMORY_CONST)363return false;364// constant buffer loads can't be used with cbcc xmads365if (i->op == OP_XMAD && sf == FILE_MEMORY_CONST &&366(i->subOp & NV50_IR_SUBOP_XMAD_CMODE_MASK) == NV50_IR_SUBOP_XMAD_CBCC)367return false;368// constant buffer loads for the third operand can't be used with psl/mrg xmads369if (i->op == OP_XMAD && sf == FILE_MEMORY_CONST && s == 2 &&370(i->subOp & (NV50_IR_SUBOP_XMAD_PSL | NV50_IR_SUBOP_XMAD_MRG)))371return false;372// for xmads, immediates can't have the h1 flag set373if (i->op == OP_XMAD && sf == FILE_IMMEDIATE && s < 2 &&374i->subOp & NV50_IR_SUBOP_XMAD_H1(s))375return false;376377for (int k = 0; i->srcExists(k); ++k) {378if (i->src(k).getFile() == FILE_IMMEDIATE) {379if (k == 2 && i->op == OP_SUCLAMP) // special case380continue;381if (k == 1 && i->op == OP_SHLADD) // special case382continue;383if (i->getSrc(k)->reg.data.u64 != 0)384return false;385} else386if (i->src(k).getFile() != FILE_GPR &&387i->src(k).getFile() != FILE_PREDICATE &&388i->src(k).getFile() != FILE_FLAGS) {389return false;390}391}392393// only loads can do sub 4 byte addressing394if (sf == FILE_MEMORY_CONST &&395(ld->getSrc(0)->reg.data.offset & 0x3)396&& i->op != OP_LOAD)397return false;398399// not all instructions support full 32 bit immediates400if (sf == FILE_IMMEDIATE) {401Storage ® = ld->getSrc(0)->asImm()->reg;402403if (opInfo[i->op].immdBits != 0xffffffff || typeSizeof(i->sType) > 4) {404switch (i->sType) {405case TYPE_F64:406if (reg.data.u64 & 0x00000fffffffffffULL)407return false;408break;409case TYPE_F32:410if (reg.data.u32 & 0xfff)411return false;412break;413case TYPE_S32:414case TYPE_U32:415// with u32, 0xfffff counts as 0xffffffff as well416if (reg.data.s32 > 0x7ffff || reg.data.s32 < -0x80000)417return false;418// XMADs can only have 16-bit immediates419if (i->op == OP_XMAD && reg.data.u32 > 0xffff)420return false;421break;422case TYPE_U8:423case TYPE_S8:424case TYPE_U16:425case TYPE_S16:426case TYPE_F16:427break;428default:429return false;430}431} else432if (i->op == OP_ADD && i->sType == TYPE_F32) {433// add f32 LIMM cannot saturate434if (i->saturate && (reg.data.u32 & 0xfff))435return false;436}437}438439return true;440}441442bool443TargetNVC0::insnCanLoadOffset(const Instruction *insn, int s, int offset) const444{445const ValueRef& ref = insn->src(s);446offset += insn->src(s).get()->reg.data.offset;447if (ref.getFile() == FILE_MEMORY_CONST &&448(insn->op != OP_LOAD || insn->subOp != NV50_IR_SUBOP_LDC_IS))449return offset >= -0x8000 && offset < 0x8000;450return true;451}452453bool454TargetNVC0::isAccessSupported(DataFile file, DataType ty) const455{456if (ty == TYPE_NONE)457return false;458if (file == FILE_MEMORY_CONST) {459if (getChipset() >= NVISA_GM107_CHIPSET)460return typeSizeof(ty) <= 4;461else462if (getChipset() >= NVISA_GK104_CHIPSET) // wrong encoding ?463return typeSizeof(ty) <= 8;464}465if (ty == TYPE_B96)466return false;467return true;468}469470bool471TargetNVC0::isOpSupported(operation op, DataType ty) const472{473if (op == OP_SAD && ty != TYPE_S32 && ty != TYPE_U32)474return false;475if (op == OP_POW || op == OP_SQRT || op == OP_DIV || op == OP_MOD)476return false;477if (op == OP_XMAD)478return false;479return true;480}481482bool483TargetNVC0::isModSupported(const Instruction *insn, int s, Modifier mod) const484{485if (!isFloatType(insn->dType)) {486switch (insn->op) {487case OP_ABS:488case OP_NEG:489case OP_CVT:490case OP_CEIL:491case OP_FLOOR:492case OP_TRUNC:493case OP_AND:494case OP_OR:495case OP_XOR:496case OP_POPCNT:497case OP_BFIND:498case OP_XMAD:499break;500case OP_SET:501if (insn->sType != TYPE_F32)502return false;503break;504case OP_ADD:505if (mod.abs())506return false;507if (insn->src(s ? 0 : 1).mod.neg())508return false;509break;510case OP_SUB:511if (s == 0)512return insn->src(1).mod.neg() ? false : true;513break;514case OP_SHLADD:515if (s == 1)516return false;517if (insn->src(s ? 0 : 2).mod.neg())518return false;519break;520default:521return false;522}523}524if (s >= opInfo[insn->op].srcNr || s >= 3)525return false;526return (mod & Modifier(opInfo[insn->op].srcMods[s])) == mod;527}528529bool530TargetNVC0::mayPredicate(const Instruction *insn, const Value *pred) const531{532if (insn->getPredicate())533return false;534return opInfo[insn->op].predicate;535}536537bool538TargetNVC0::isSatSupported(const Instruction *insn) const539{540if (insn->op == OP_CVT)541return true;542if (!(opInfo[insn->op].dstMods & NV50_IR_MOD_SAT))543return false;544545if (insn->dType == TYPE_U32)546return (insn->op == OP_ADD) || (insn->op == OP_MAD);547548// add f32 LIMM cannot saturate549if (insn->op == OP_ADD && insn->sType == TYPE_F32) {550if (insn->getSrc(1)->asImm() &&551insn->getSrc(1)->reg.data.u32 & 0xfff)552return false;553}554555return insn->dType == TYPE_F32;556}557558bool559TargetNVC0::isPostMultiplySupported(operation op, float f, int& e) const560{561if (op != OP_MUL)562return false;563f = fabsf(f);564e = static_cast<int>(log2f(f));565if (e < -3 || e > 3)566return false;567return f == exp2f(static_cast<float>(e));568}569570// TODO: better values571// this could be more precise, e.g. depending on the issue-to-read/write delay572// of the depending instruction, but it's good enough573int TargetNVC0::getLatency(const Instruction *i) const574{575if (chipset >= 0xe4) {576if (i->dType == TYPE_F64 || i->sType == TYPE_F64)577return 20;578switch (i->op) {579case OP_LINTERP:580case OP_PINTERP:581return 15;582case OP_LOAD:583if (i->src(0).getFile() == FILE_MEMORY_CONST)584return 9;585FALLTHROUGH;586case OP_VFETCH:587return 24;588default:589if (Target::getOpClass(i->op) == OPCLASS_TEXTURE)590return 17;591if (i->op == OP_MUL && i->dType != TYPE_F32)592return 15;593return 9;594}595} else {596if (i->op == OP_LOAD) {597if (i->cache == CACHE_CV)598return 700;599return 48;600}601return 24;602}603return 32;604}605606// These are "inverse" throughput values, i.e. the number of cycles required607// to issue a specific instruction for a full warp (32 threads).608//609// Assuming we have more than 1 warp in flight, a higher issue latency results610// in a lower result latency since the MP will have spent more time with other611// warps.612// This also helps to determine the number of cycles between instructions in613// a single warp.614//615int TargetNVC0::getThroughput(const Instruction *i) const616{617// TODO: better values618if (i->dType == TYPE_F32) {619switch (i->op) {620case OP_ADD:621case OP_MUL:622case OP_MAD:623case OP_FMA:624return 1;625case OP_CVT:626case OP_CEIL:627case OP_FLOOR:628case OP_TRUNC:629case OP_SET:630case OP_SLCT:631case OP_MIN:632case OP_MAX:633return 2;634case OP_RCP:635case OP_RSQ:636case OP_LG2:637case OP_SIN:638case OP_COS:639case OP_PRESIN:640case OP_PREEX2:641default:642return 8;643}644} else645if (i->dType == TYPE_U32 || i->dType == TYPE_S32) {646switch (i->op) {647case OP_ADD:648case OP_AND:649case OP_OR:650case OP_XOR:651case OP_NOT:652return 1;653case OP_MUL:654case OP_MAD:655case OP_CVT:656case OP_SET:657case OP_SLCT:658case OP_SHL:659case OP_SHR:660case OP_NEG:661case OP_ABS:662case OP_MIN:663case OP_MAX:664default:665return 2;666}667} else668if (i->dType == TYPE_F64) {669return 2;670} else {671return 1;672}673}674675bool TargetNVC0::canDualIssue(const Instruction *a, const Instruction *b) const676{677const OpClass clA = operationClass[a->op];678const OpClass clB = operationClass[b->op];679680if (getChipset() >= 0xe4) {681// not texturing682// not if the 2nd instruction isn't necessarily executed683if (clA == OPCLASS_TEXTURE || clA == OPCLASS_FLOW)684return false;685686// Check that a and b don't write to the same sources, nor that b reads687// anything that a writes.688if (!a->canCommuteDefDef(b) || !a->canCommuteDefSrc(b))689return false;690691// anything with MOV692if (a->op == OP_MOV || b->op == OP_MOV)693return true;694if (clA == clB) {695switch (clA) {696// there might be more697case OPCLASS_COMPARE:698if ((a->op == OP_MIN || a->op == OP_MAX) &&699(b->op == OP_MIN || b->op == OP_MAX))700break;701return false;702case OPCLASS_ARITH:703break;704default:705return false;706}707// only F32 arith or integer additions708return (a->dType == TYPE_F32 || a->op == OP_ADD ||709b->dType == TYPE_F32 || b->op == OP_ADD);710}711// nothing with TEXBAR712if (a->op == OP_TEXBAR || b->op == OP_TEXBAR)713return false;714// no loads and stores accessing the same space715if ((clA == OPCLASS_LOAD && clB == OPCLASS_STORE) ||716(clB == OPCLASS_LOAD && clA == OPCLASS_STORE))717if (a->src(0).getFile() == b->src(0).getFile())718return false;719// no > 32-bit ops720if (typeSizeof(a->dType) > 4 || typeSizeof(b->dType) > 4 ||721typeSizeof(a->sType) > 4 || typeSizeof(b->sType) > 4)722return false;723return true;724} else {725return false; // info not needed (yet)726}727}728729} // namespace nv50_ir730731732