void
Instruction::setDef(int i, Value *val)
{
- int size = def.size();
+ int size = defs.size();
if (i >= size) {
- def.resize(i + 1);
+ defs.resize(i + 1);
while (size <= i)
- def[size++].setInsn(this);
+ defs[size++].setInsn(this);
}
- def[i].set(val);
+ defs[i].set(val);
}
void
Instruction::setSrc(int s, Value *val)
{
- int size = src.size();
+ int size = srcs.size();
if (s >= size) {
- src.resize(s + 1);
+ srcs.resize(s + 1);
while (size <= s)
- src[size++].setInsn(this);
+ srcs[size++].setInsn(this);
}
- src[s].set(val);
+ srcs[s].set(val);
}
void
Instruction::setSrc(int s, const ValueRef& ref)
{
setSrc(s, ref.get());
- src[s].mod = ref.mod;
+ srcs[s].mod = ref.mod;
}
void
Instruction::swapSources(int a, int b)
{
- Value *value = src[a].get();
- Modifier m = src[a].mod;
+ Value *value = srcs[a].get();
+ Modifier m = srcs[a].mod;
- setSrc(a, src[b]);
+ setSrc(a, srcs[b]);
- src[b].set(value);
- src[b].mod = m;
+ srcs[b].set(value);
+ srcs[b].mod = m;
}
void
}
for (int s = 0; this->srcExists(s); ++s)
- insn->setSrc(s, this->src[s]);
+ insn->setSrc(s, this->srcs[s]);
insn->predSrc = this->predSrc;
insn->flagsDef = this->flagsDef;
{
assert(this->srcExists(s));
- int p = src[s].indirect[dim];
+ int p = srcs[s].indirect[dim];
if (p < 0) {
if (!value)
return true;
- p = src.size();
+ p = srcs.size();
+ while (p > 0 && !srcExists(p - 1))
+ --p;
}
setSrc(p, value);
- src[p].usedAsPtr = (value != 0);
- src[s].indirect[dim] = value ? p : -1;
+ srcs[p].usedAsPtr = (value != 0);
+ srcs[s].indirect[dim] = value ? p : -1;
return true;
}
if (!value) {
if (predSrc >= 0) {
- src[predSrc] = 0;
+ srcs[predSrc].set(NULL);
predSrc = -1;
}
return true;
}
- if (predSrc < 0)
- predSrc = src.size();
+ if (predSrc < 0) {
+ predSrc = srcs.size();
+ while (predSrc > 0 && !srcExists(predSrc - 1))
+ --predSrc;
+ }
setSrc(predSrc, value);
return true;
ValueRef(const ValueRef&);
~ValueRef();
- inline ValueRef& operator=(Value *val) { this->set(val); return *this; }
-
inline bool exists() const { return value != NULL; }
void set(Value *);
public:
Modifier mod;
- int8_t indirect[2]; // >= 0 if relative to lvalue in insn->src[indirect[i]]
+ int8_t indirect[2]; // >= 0 if relative to lvalue in insn->src(indirect[i])
uint8_t swizzle;
bool usedAsPtr; // for printing
ValueDef(const ValueDef&);
~ValueDef();
- inline ValueDef& operator=(Value *val) { this->set(val); return *this; }
-
inline bool exists() const { return value != NULL; }
inline Value *get() const { return value; }
virtual bool equals(const Value *, bool strict = false) const;
virtual bool interfers(const Value *) const;
+ inline Value *rep() const { return join; }
+
inline Instruction *getUniqueInsn() const;
inline Instruction *getInsn() const; // use when uniqueness is certain
void swapSources(int a, int b);
bool setIndirect(int s, int dim, Value *);
- inline Value *getDef(int d) const { return def[d].get(); }
- inline Value *getSrc(int s) const { return src[s].get(); }
+ inline ValueRef& src(int s) { return srcs[s]; }
+ inline ValueDef& def(int s) { return defs[s]; }
+ inline const ValueRef& src(int s) const { return srcs[s]; }
+ inline const ValueDef& def(int s) const { return defs[s]; }
+
+ inline Value *getDef(int d) const { return defs[d].get(); }
+ inline Value *getSrc(int s) const { return srcs[s].get(); }
inline Value *getIndirect(int s, int dim) const;
inline bool defExists(unsigned d) const
{
- return d < def.size() && def[d].exists();
+ return d < defs.size() && defs[d].exists();
}
inline bool srcExists(unsigned s) const
{
- return s < src.size() && src[s].exists();
+ return s < srcs.size() && srcs[s].exists();
}
inline bool constrainedDefs() const { return defExists(1); }
inline void setFlagsSrc(int s, Value *);
inline void setFlagsDef(int d, Value *);
+ unsigned int defCount() const { return defs.size(); };
unsigned int defCount(unsigned int mask) const;
+ unsigned int srcCount() const { return srcs.size(); };
unsigned int srcCount(unsigned int mask) const;
// save & remove / set indirect[0,1] and predicate source
int8_t flagsDef;
int8_t flagsSrc;
- std::deque<ValueDef> def; // no gaps !
- std::deque<ValueRef> src; // no gaps !
-
BasicBlock *bb;
+protected:
+ std::deque<ValueDef> defs; // no gaps !
+ std::deque<ValueRef> srcs; // no gaps !
+
// instruction specific methods:
// (don't want to subclass, would need more constructors and memory pools)
public:
if (texi->op == OP_TXD) {
for (c = 0; c < tgt.getDim(); ++c) {
- texi->dPdx[c] = fetchSrc(Dx >> 4, (Dx & 3) + c);
- texi->dPdy[c] = fetchSrc(Dy >> 4, (Dy & 3) + c);
+ texi->dPdx[c].set(fetchSrc(Dx >> 4, (Dx & 3) + c));
+ texi->dPdy[c].set(fetchSrc(Dy >> 4, (Dy & 3) + c));
}
}
const ValueRef *ValueRef::getIndirect(int dim) const
{
- return isIndirect(dim) ? &insn->src[indirect[dim]] : NULL;
+ return isIndirect(dim) ? &insn->src(indirect[dim]) : NULL;
}
DataFile ValueRef::getFile() const
Value *Instruction::getIndirect(int s, int dim) const
{
- return src[s].isIndirect(dim) ? getSrc(src[s].indirect[dim]) : NULL;
+ return srcs[s].isIndirect(dim) ? getSrc(srcs[s].indirect[dim]) : NULL;
}
Value *Instruction::getPredicate() const
if (!fixed && op == OP_NOP)
return true;
- if (defExists(0) && def[0].rep()->reg.data.id < 0) {
+ if (defExists(0) && def(0).rep()->reg.data.id < 0) {
for (int d = 1; defExists(d); ++d)
- if (def[d].rep()->reg.data.id >= 0)
+ if (def(d).rep()->reg.data.id >= 0)
WARN("part of vector result is unused !\n");
return true;
}
if (op == OP_MOV || op == OP_UNION) {
- if (!def[0].rep()->equals(getSrc(0)))
+ if (!def(0).rep()->equals(getSrc(0)))
return false;
if (op == OP_UNION)
- if (!def[0].rep()->equals(getSrc(1)))
+ if (!def(0).rep()->equals(getSrc(1)))
return false;
return true;
}
si = mov->getSrc(0)->getInsn();
if (mov->getDef(0)->reg.data.id < 0 && si && si->op != OP_PHI) {
// propagate
- mov->def[0].replace(mov->getSrc(0), false);
+ mov->def(0).replace(mov->getSrc(0), false);
delete_Instruction(prog, mov);
}
}
bool
LoadPropagation::isCSpaceLoad(Instruction *ld)
{
- return ld && ld->op == OP_LOAD && ld->src[0].getFile() == FILE_MEMORY_CONST;
+ return ld && ld->op == OP_LOAD && ld->src(0).getFile() == FILE_MEMORY_CONST;
}
bool
{
if (!ld || (ld->op != OP_MOV) || (typeSizeof(ld->dType) != 4))
return false;
- return ld->src[0].getFile() == FILE_IMMEDIATE;
+ return ld->src(0).getFile() == FILE_IMMEDIATE;
}
void
if (!prog->getTarget()->getOpInfo(insn).commutative)
if (insn->op != OP_SET && insn->op != OP_SLCT)
return;
- if (insn->src[1].getFile() != FILE_GPR)
+ if (insn->src(1).getFile() != FILE_GPR)
return;
Instruction *i0 = insn->getSrc(0)->getInsn();
// propagate !
i->setSrc(s, ld->getSrc(0));
- if (ld->src[0].isIndirect(0))
+ if (ld->src(0).isIndirect(0))
i->setIndirect(s, 0, ld->getIndirect(0, 0));
if (ld->getDef(0)->refCount() == 0)
if (i->op == OP_MOV) // continue early, MOV appears frequently
continue;
- ImmediateValue *src0 = i->srcExists(0) ? i->src[0].getImmediate() : NULL;
- ImmediateValue *src1 = i->srcExists(1) ? i->src[1].getImmediate() : NULL;
+ ImmediateValue *src0 = i->srcExists(0) ? i->src(0).getImmediate() : NULL;
+ ImmediateValue *src1 = i->srcExists(1) ? i->src(1).getImmediate() : NULL;
if (src0 && src1)
expr(i, src0, src1);
struct Storage res;
struct Storage *const a = &imm0.reg, *const b = &imm1.reg;
- i->src[0].mod.applyTo(imm0);
- i->src[1].mod.applyTo(imm1);
+ i->src(0).mod.applyTo(imm0);
+ i->src(1).mod.applyTo(imm1);
switch (i->op) {
case OP_MAD:
}
++foldCount;
- i->src[0].mod = Modifier(0);
- i->src[1].mod = Modifier(0);
+ i->src(0).mod = Modifier(0);
+ i->src(1).mod = Modifier(0);
i->setSrc(0, new_ImmediateValue(i->bb->getProgram(), res.data.u32));
i->setSrc(1, NULL);
i->op = OP_ADD;
i->setSrc(1, i->getSrc(0));
+ i->src(1).mod = i->src(2).mod;
i->setSrc(0, i->getSrc(2));
i->setSrc(2, NULL);
- i->src[1].mod = i->src[2].mod;
-
- src0 = i->src[0].getImmediate();
+ src0 = i->src(0).getImmediate();
if (src0)
expr(i, src0, i->getSrc(1)->asImm());
} else {
}
i->op = OP_MOV;
i->setSrc(0, new_ImmediateValue(i->bb->getProgram(), res.data.f32));
- i->src[0].mod = Modifier(0);
+ i->src(0).mod = Modifier(0);
}
void
mul1 = insn;
if (mul1) {
int s1 = 0;
- ImmediateValue *imm = mul1->src[s1].getImmediate();
+ ImmediateValue *imm = mul1->src(s1).getImmediate();
if (!imm) {
s1 = 1;
- imm = mul1->src[s1].getImmediate();
+ imm = mul1->src(s1).getImmediate();
}
if (imm) {
bld.setPosition(mul1, false);
// a = mul r, imm1
// d = mul a, imm2 -> d = mul r, (imm1 * imm2)
- ImmediateValue imm1(mul1->src[s1].getImmediate(), TYPE_F32);
- mul1->src[s1].mod.applyTo(imm1);
- mul1->src[s1].mod = Modifier(0);
+ ImmediateValue imm1(mul1->src(s1).getImmediate(), TYPE_F32);
+ mul1->src(s1).mod.applyTo(imm1);
+ mul1->src(s1).mod = Modifier(0);
mul1->setSrc(s1, bld.loadImm(NULL, f * imm1.reg.data.f32));
- mul2->def[0].replace(mul1->getDef(0), false);
+ mul2->def(0).replace(mul1->getDef(0), false);
} else
if (prog->getTarget()->isPostMultiplySupported(OP_MUL, f, e)) {
// c = mul a, b
// d = mul c, imm -> d = mul_x_imm a, b
mul1->postFactor = e;
- mul2->def[0].replace(mul1->getDef(0), false);
+ mul2->def(0).replace(mul1->getDef(0), false);
if (f < 0)
- mul1->src[0].mod = mul1->src[0].mod ^ Modifier(NV50_IR_MOD_NEG);
+ mul1->src(0).mod = mul1->src(0).mod ^ Modifier(NV50_IR_MOD_NEG);
}
return;
}
s2 = insn->getSrc(0) == mul1->getDef(0) ? 0 : 1;
t2 = s2 ? 0 : 1;
if (insn->op == OP_MUL && insn->dType == TYPE_F32)
- if (!insn->src[t2].getImmediate())
+ if (!insn->src(t2).getImmediate())
mul2 = insn;
if (mul2 && prog->getTarget()->isPostMultiplySupported(OP_MUL, f, e)) {
mul2->postFactor = e;
- mul2->setSrc(s2, mul1->src[t]);
+ mul2->setSrc(s2, mul1->src(t));
if (f < 0)
- mul2->src[s2].mod = mul2->src[s2].mod ^ Modifier(NV50_IR_MOD_NEG);
+ mul2->src(s2).mod = mul2->src(s2).mod ^ Modifier(NV50_IR_MOD_NEG);
}
}
}
ImmediateValue imm(src, i->sType);
- i->src[s].mod.applyTo(imm);
+ i->src(s).mod.applyTo(imm);
switch (i->op) {
case OP_MUL:
} else
if (imm.isInteger(1) || imm.isInteger(-1)) {
if (imm.isNegative())
- i->src[t].mod = i->src[t].mod ^ Modifier(NV50_IR_MOD_NEG);
- i->op = i->src[t].mod.getOp();
+ i->src(t).mod = i->src(t).mod ^ Modifier(NV50_IR_MOD_NEG);
+ i->op = i->src(t).mod.getOp();
if (s == 0) {
i->setSrc(0, i->getSrc(1));
- i->src[0].mod = i->src[1].mod;
- i->src[1].mod = 0;
+ i->src(0).mod = i->src(1).mod;
+ i->src(1).mod = 0;
}
if (i->op != OP_CVT)
- i->src[0].mod = 0;
+ i->src(0).mod = 0;
i->setSrc(1, NULL);
} else
if (imm.isInteger(2) || imm.isInteger(-2)) {
if (imm.isNegative())
- i->src[t].mod = i->src[t].mod ^ Modifier(NV50_IR_MOD_NEG);
+ i->src(t).mod = i->src(t).mod ^ Modifier(NV50_IR_MOD_NEG);
i->op = OP_ADD;
i->setSrc(s, i->getSrc(t));
- i->src[s].mod = i->src[t].mod;
+ i->src(s).mod = i->src(t).mod;
} else
if (!isFloatType(i->sType) && !imm.isNegative() && imm.isPow2()) {
i->op = OP_SHL;
if (imm.isInteger(0)) {
if (s == 0) {
i->setSrc(0, i->getSrc(1));
- i->src[0].mod = i->src[1].mod;
+ i->src(0).mod = i->src(1).mod;
}
i->setSrc(1, NULL);
- i->op = i->src[0].mod.getOp();
+ i->op = i->src(0).mod.getOp();
if (i->op != OP_CVT)
- i->src[0].mod = Modifier(0);
+ i->src(0).mod = Modifier(0);
}
break;
{
CmpInstruction *si = findOriginForTestWithZero(i->getSrc(t));
CondCode cc, ccZ;
- if (i->src[t].mod != Modifier(0))
+ if (i->src(t).mod != Modifier(0))
return;
if (imm.reg.data.u32 != 0 || !si || si->op != OP_SET)
return;
return;
}
i->asCmp()->setCond = cc;
- i->setSrc(0, si->src[0]);
- i->setSrc(1, si->src[1]);
+ i->setSrc(0, si->src(0));
+ i->setSrc(1, si->src(1));
i->sType = si->sType;
}
break;
case OP_SHL:
{
- if (s != 1 || i->src[0].mod != Modifier(0))
+ if (s != 1 || i->src(0).mod != Modifier(0))
break;
// try to concatenate shifts
Instruction *si = i->getSrc(0)->getInsn();
if (!si ||
- si->op != OP_SHL || si->src[1].mod != Modifier(0))
+ si->op != OP_SHL || si->src(1).mod != Modifier(0))
break;
- ImmediateValue *siImm = si->src[1].getImmediate();
+ ImmediateValue *siImm = si->src(1).getImmediate();
if (siImm) {
bld.setPosition(i, false);
i->setSrc(0, si->getSrc(0));
if (0 && i->op == OP_SUB) {
// turn "sub" into "add neg" (do we really want this ?)
i->op = OP_ADD;
- i->src[0].mod = i->src[0].mod ^ Modifier(NV50_IR_MOD_NEG);
+ i->src(0).mod = i->src(0).mod ^ Modifier(NV50_IR_MOD_NEG);
}
for (int s = 0; s < 3 && i->srcExists(s); ++s) {
}
if ((mod = Modifier(mi->op)) == Modifier(0))
continue;
- mod = mod * mi->src[0].mod;
+ mod = mod * mi->src(0).mod;
- if ((i->op == OP_ABS) || i->src[s].mod.abs()) {
+ if ((i->op == OP_ABS) || i->src(s).mod.abs()) {
// abs neg [abs] = abs
mod = mod & Modifier(~(NV50_IR_MOD_NEG | NV50_IR_MOD_ABS));
} else
if (target->isModSupported(i, s, mod)) {
i->setSrc(s, mi->getSrc(0));
- i->src[s].mod = i->src[s].mod * mod;
+ i->src(s).mod = i->src(s).mod * mod;
}
}
if (src->getInsn()->postFactor)
return;
- mod[0] = add->src[0].mod;
- mod[1] = add->src[1].mod;
- mod[2] = src->getUniqueInsn()->src[0].mod;
- mod[3] = src->getUniqueInsn()->src[1].mod;
+ mod[0] = add->src(0).mod;
+ mod[1] = add->src(1).mod;
+ mod[2] = src->getUniqueInsn()->src(0).mod;
+ mod[3] = src->getUniqueInsn()->src(1).mod;
if (((mod[0] | mod[1]) | (mod[2] | mod[3])) & Modifier(~NV50_IR_MOD_NEG))
return;
add->op = OP_MAD;
add->subOp = src->getInsn()->subOp; // potentially mul-high
- add->setSrc(2, add->src[s ? 0 : 1]);
+ add->setSrc(2, add->src(s ? 0 : 1));
add->setSrc(0, src->getInsn()->getSrc(0));
- add->src[0].mod = mod[2] ^ mod[s];
+ add->src(0).mod = mod[2] ^ mod[s];
add->setSrc(1, src->getInsn()->getSrc(1));
- add->src[1].mod = mod[3];
+ add->src(1).mod = mod[3];
}
void
if (src0 != src1 || src0->reg.file != FILE_GPR)
return;
- if (minmax->src[0].mod == minmax->src[1].mod) {
- if (minmax->src[0].mod) {
+ if (minmax->src(0).mod == minmax->src(1).mod) {
+ if (minmax->src(0).mod) {
minmax->op = OP_CVT;
minmax->setSrc(1, NULL);
} else {
- minmax->def[0].replace(minmax->getSrc(0), false);
+ minmax->def(0).replace(minmax->getSrc(0), false);
minmax->bb->remove(minmax);
}
} else {
Instruction *si = rcp->getSrc(0)->getUniqueInsn();
if (si && si->op == OP_RCP) {
- Modifier mod = rcp->src[0].mod * si->src[0].mod;
+ Modifier mod = rcp->src(0).mod * si->src(0).mod;
rcp->op = mod.getOp();
rcp->setSrc(0, si->getSrc(0));
}
return;
if (src0 == src1) {
- if (logop->src[0].mod != Modifier(0) ||
- logop->src[1].mod != Modifier(0))
+ if (logop->src(0).mod != Modifier(0) ||
+ logop->src(1).mod != Modifier(0))
return;
if (logop->op == OP_AND || logop->op == OP_OR) {
- logop->def[0].replace(logop->getSrc(0), false);
+ logop->def(0).replace(logop->getSrc(0), false);
delete_Instruction(prog, logop);
}
} else {
AlgebraicOpt::handleCVT(Instruction *cvt)
{
if (cvt->sType != TYPE_F32 ||
- cvt->dType != TYPE_S32 || cvt->src[0].mod != Modifier(0))
+ cvt->dType != TYPE_S32 || cvt->src(0).mod != Modifier(0))
return;
Instruction *insn = cvt->getSrc(0)->getInsn();
if (!insn || insn->op != OP_NEG || insn->dType != TYPE_F32)
return;
- if (insn->src[0].mod != Modifier(0))
+ if (insn->src(0).mod != Modifier(0))
return;
insn = insn->getSrc(0)->getInsn();
if (!insn || insn->op != OP_SET || insn->dType != TYPE_F32)
MemoryOpt::getList(const Instruction *insn)
{
if (insn->op == OP_LOAD || insn->op == OP_VFETCH)
- return &loads[insn->src[0].getFile()];
- return &stores[insn->src[0].getFile()];
+ return &loads[insn->src(0).getFile()];
+ return &stores[insn->src(0).getFile()];
}
void
return false;
if (st->getSrc(s)->reg.file != FILE_GPR)
return false;
- ld->def[d].replace(st->getSrc(s), false);
+ ld->def(d).replace(st->getSrc(s), false);
}
ld->bb->remove(ld);
return true;
for (dE = 0; ldE->defExists(dE) && ldR->defExists(dR); ++dE, ++dR) {
if (ldE->getDef(dE)->reg.size != ldR->getDef(dR)->reg.size)
return false;
- ldE->def[dE].replace(ldR->getDef(dR), false);
+ ldE->def(dE).replace(ldR->getDef(dR), false);
}
delete_Instruction(prog, ldE);
void
MemoryOpt::lockStores(Instruction *const ld)
{
- for (Record *r = stores[ld->src[0].getFile()]; r; r = r->next)
+ for (Record *r = stores[ld->src(0).getFile()]; r; r = r->next)
if (!r->locked && r->overlaps(ld))
r->locked = true;
}
MemoryOpt::purgeRecords(Instruction *const st, DataFile f)
{
if (st)
- f = st->src[0].getFile();
+ f = st->src(0).getFile();
for (Record *r = loads[f]; r; r = r->next)
if (!st || r->overlaps(st))
continue;
if (isLoad) {
- DataFile file = ldst->src[0].getFile();
+ DataFile file = ldst->src(0).getFile();
// if ld l[]/g[] look for previous store to eliminate the reload
if (file == FILE_MEMORY_GLOBAL || file == FILE_MEMORY_LOCAL) {
if (ld) {
if (ld->op != OP_MOV && ld->op != OP_LOAD)
return false;
- if (ld->src[0].isIndirect(0))
+ if (ld->src(0).isIndirect(0))
return false;
- file = ld->src[0].getFile();
+ file = ld->src(0).getFile();
} else {
- file = insn->src[s].getFile();
+ file = insn->src(s).getFile();
// catch $r63 on NVC0
if (file == FILE_GPR && insn->getSrc(s)->reg.data.id > prog->maxGPR)
file = FILE_IMMEDIATE;
for (s = 0; this->srcExists(s); ++s) {
if (!that->srcExists(s))
return false;
- if (this->src[s].mod != that->src[s].mod)
+ if (this->src(s).mod != that->src(s).mod)
return false;
if (!this->getSrc(s)->equals(that->getSrc(s), true))
return false;
return false;
if (op == OP_LOAD || op == OP_VFETCH) {
- switch (src[0].getFile()) {
+ switch (src(0).getFile()) {
case FILE_MEMORY_CONST:
case FILE_SHADER_INPUT:
return true;
if (!old->isResultEqual(i))
return false;
for (int d = 0; old->defExists(d); ++d)
- old->def[d].replace(i->getDef(d), false);
+ old->def(d).replace(i->getDef(d), false);
delete_Instruction(prog, old);
*ptr = NULL;
return true;
}
if (pos > pre + 1)
SPACE();
- pos += src[predSrc].get()->print(&buf[pos], BUFSZ - pos);
+ pos += getSrc(predSrc)->print(&buf[pos], BUFSZ - pos);
PRINT(" %s", colour[TXT_INSN]);
}
PRINT(" {");
for (d = 0; defExists(d); ++d) {
SPACE();
- pos += def[d].get()->print(&buf[pos], size - pos);
+ pos += getDef(d)->print(&buf[pos], size - pos);
}
if (d > 1)
PRINT(" %s}", colour[TXT_INSN]);
PRINT(" %s%s", colour[TXT_INSN], DataTypeStr[sType]);
for (s = 0; srcExists(s); ++s) {
- if (s == predSrc || src[s].usedAsPtr)
+ if (s == predSrc || src(s).usedAsPtr)
continue;
const size_t pre = pos;
SPACE();
- pos += src[s].mod.print(&buf[pos], BUFSZ - pos);
+ pos += src(s).mod.print(&buf[pos], BUFSZ - pos);
if (pos > pre + 1)
SPACE();
- if (src[s].isIndirect(0) || src[s].isIndirect(1))
- pos += src[s].get()->asSym()->print(&buf[pos], BUFSZ - pos,
- getIndirect(s, 0),
- getIndirect(s, 1));
+ if (src(s).isIndirect(0) || src(s).isIndirect(1))
+ pos += getSrc(s)->asSym()->print(&buf[pos], BUFSZ - pos,
+ getIndirect(s, 0),
+ getIndirect(s, 1));
else
- pos += src[s].get()->print(&buf[pos], BUFSZ - pos, sType);
+ pos += getSrc(s)->print(&buf[pos], BUFSZ - pos, sType);
}
PRINT("%s", colour[TXT_DEFAULT]);
}
}
- // insert MOVs (phi->src[j] should stem from j-th in-BB)
+ // insert MOVs (phi->src(j) should stem from j-th in-BB)
int j = 0;
for (Graph::EdgeIterator ei = bb->cfg.incident(); !ei.end(); ei.next()) {
pb = BasicBlock::get(ei.getNode());
bb->liveSet.clr(i->getDef(0)->id);
for (int s = 0; i->srcExists(s); ++s) {
- assert(i->src[s].getInsn());
+ assert(i->src(s).getInsn());
if (i->getSrc(s)->getUniqueInsn()->bb == bb) // XXX: reachableBy ?
bb->liveSet.set(i->getSrc(s)->id);
else
assert(vecSize <= 4);
for (int c = 0; c < vecSize; ++c)
- defs[c] = i->def[c].rep();
+ defs[c] = i->def(c).rep();
if (defs[0]->reg.data.id >= 0) {
for (int c = 1; c < vecSize; ++c) {
addConstraint(i, 1, s - 1);
} else
if (i->op == OP_LOAD) {
- if (i->src[0].isIndirect(0) && typeSizeof(i->dType) >= 8)
- addHazard(i, i->src[0].getIndirect(0));
+ if (i->src(0).isIndirect(0) && typeSizeof(i->dType) >= 8)
+ addHazard(i, i->src(0).getIndirect(0));
}
}
return true;
if (!detectConflict(cst, s))
continue;
Instruction *mov = new_Instruction(func, OP_MOV,
- typeOfSize(cst->src[s].getSize()));
+ typeOfSize(cst->src(s).getSize()));
mov->setSrc(0, cst->getSrc(s));
mov->setDef(0, new_LValue(func, FILE_GPR));
cst->setSrc(s, mov->getDef(0));
}
}
for (d = 0; stmt->defExists(d); ++d) {
- lval = stmt->def[d].get()->asLValue();
+ lval = stmt->def(d).get()->asLValue();
assert(lval);
- stmt->def[d].setSSA(
+ stmt->def(d).setSSA(
new_LValue(func, targ->nativeFile(lval->reg.file)));
- stmt->def[d].get()->reg.size = lval->reg.size;
- stmt->def[d].get()->reg.data.id = lval->reg.data.id;
- stack[lval->id].push(stmt->def[d].get());
+ stmt->def(d).get()->reg.size = lval->reg.size;
+ stmt->def(d).get()->reg.data.id = lval->reg.data.id;
+ stack[lval->id].push(stmt->def(d).get());
}
}
for (Instruction *stmt = bb->getFirst(); stmt; stmt = stmt->next) {
for (d = 0; stmt->defExists(d); ++d)
- stack[stmt->def[d].preSSA()->id].pop();
+ stack[stmt->def(d).preSSA()->id].pop();
}
}
inline void defId(const ValueDef&, const int pos);
inline void srcId(const ValueRef&, const int pos);
+ inline void srcId(const ValueRef *, const int pos);
+ inline void srcId(const Instruction *, int s, const int pos);
inline void srcAddr32(const ValueRef&, const int pos); // address / 4
- inline void srcId(const ValueRef *, const int pos);
-
inline bool isLIMM(const ValueRef&, DataType ty);
};
code[pos / 32] |= (src ? SDATA(*src).id : 63) << (pos % 32);
}
+void CodeEmitterNVC0::srcId(const Instruction *insn, int s, int pos)
+{
+ int r = insn->srcExists(s) ? SDATA(insn->src(s)).id : 63;
+ code[pos / 32] |= r << (pos % 32);
+}
+
void CodeEmitterNVC0::srcAddr32(const ValueRef& src, const int pos)
{
code[pos / 32] |= (SDATA(src).offset >> 2) << (pos % 32);
void
CodeEmitterNVC0::emitNegAbs12(const Instruction *i)
{
- if (i->src[1].mod.abs()) code[0] |= 1 << 6;
- if (i->src[0].mod.abs()) code[0] |= 1 << 7;
- if (i->src[1].mod.neg()) code[0] |= 1 << 8;
- if (i->src[0].mod.neg()) code[0] |= 1 << 9;
+ if (i->src(1).mod.abs()) code[0] |= 1 << 6;
+ if (i->src(0).mod.abs()) code[0] |= 1 << 7;
+ if (i->src(1).mod.neg()) code[0] |= 1 << 8;
+ if (i->src(0).mod.neg()) code[0] |= 1 << 9;
}
void CodeEmitterNVC0::emitCondCode(CondCode cc, int pos)
{
if (i->predSrc >= 0) {
assert(i->getPredicate()->reg.file == FILE_PREDICATE);
- srcId(i->src[i->predSrc], 10);
+ srcId(i->src(i->predSrc), 10);
if (i->cc == CC_NOT_P)
code[0] |= 0x2000; // negate
} else {
void
CodeEmitterNVC0::setImmediate(const Instruction *i, const int s)
{
- const ImmediateValue *imm = i->src[s].get()->asImm();
+ const ImmediateValue *imm = i->src(s).get()->asImm();
uint32_t u32;
assert(imm);
emitPredicate(i);
- defId(i->def[0], 14);
+ defId(i->def(0), 14);
int s1 = 26;
if (i->srcExists(2) && i->getSrc(2)->reg.file == FILE_MEMORY_CONST)
assert(!(code[1] & 0xc000));
code[1] |= (s == 2) ? 0x8000 : 0x4000;
code[1] |= i->getSrc(s)->reg.fileIndex << 10;
- setAddress16(i->src[s]);
+ setAddress16(i->src(s));
break;
case FILE_IMMEDIATE:
assert(s == 1 ||
case FILE_GPR:
if ((s == 2) && ((code[0] & 0x7) == 2)) // LIMM: 3rd src == dst
break;
- srcId(i->src[s], s ? ((s == 2) ? 49 : s1) : 20);
+ srcId(i->src(s), s ? ((s == 2) ? 49 : s1) : 20);
break;
default:
// ignore here, can be predicate or flags, but must not be address
emitPredicate(i);
- defId(i->def[0], 14);
+ defId(i->def(0), 14);
- switch (i->src[0].getFile()) {
+ switch (i->src(0).getFile()) {
case FILE_MEMORY_CONST:
assert(!(code[1] & 0xc000));
- code[1] |= 0x4000 | (i->src[0].get()->reg.fileIndex << 10);
- setAddress16(i->src[0]);
+ code[1] |= 0x4000 | (i->src(0).get()->reg.fileIndex << 10);
+ setAddress16(i->src(0));
break;
case FILE_IMMEDIATE:
assert(!(code[1] & 0xc000));
setImmediate(i, 0);
break;
case FILE_GPR:
- srcId(i->src[0], 26);
+ srcId(i->src(0), 26);
break;
default:
// ignore here, can be predicate or flags, but must not be address
if (opc == 0x0d || opc == 0x0e)
ss2a = 2;
- defId(i->def[0], 14);
- srcId(i->src[0], 20);
+ defId(i->def(0), 14);
+ srcId(i->src(0), 20);
assert(pred || (i->predSrc < 0));
if (pred)
emitPredicate(i);
for (int s = 1; s < 3 && i->srcExists(s); ++s) {
- if (i->src[s].get()->reg.file == FILE_MEMORY_CONST) {
+ if (i->src(s).get()->reg.file == FILE_MEMORY_CONST) {
assert(!(code[0] & (0x300 >> ss2a)));
- switch (i->src[s].get()->reg.fileIndex) {
+ switch (i->src(s).get()->reg.fileIndex) {
case 0: code[0] |= 0x100 >> ss2a; break;
case 1: code[0] |= 0x200 >> ss2a; break;
case 16: code[0] |= 0x300 >> ss2a; break;
else
code[0] |= i->getSrc(s)->reg.data.offset << 6;
} else
- if (i->src[s].getFile() == FILE_IMMEDIATE) {
+ if (i->src(s).getFile() == FILE_IMMEDIATE) {
assert(s == 1);
- setImmediateS8(i->src[s]);
+ setImmediateS8(i->src(s));
} else
- if (i->src[s].getFile() == FILE_GPR) {
- srcId(i->src[s], (s == 1) ? 26 : 8);
+ if (i->src(s).getFile() == FILE_GPR) {
+ srcId(i->src(s), (s == 1) ? 26 : 8);
}
}
}
void
CodeEmitterNVC0::emitFMAD(const Instruction *i)
{
- bool neg1 = (i->src[0].mod ^ i->src[1].mod).neg();
+ bool neg1 = (i->src(0).mod ^ i->src(1).mod).neg();
if (i->encSize == 8) {
- if (isLIMM(i->src[1], TYPE_F32)) {
+ if (isLIMM(i->src(1), TYPE_F32)) {
emitForm_A(i, HEX64(20000000, 00000002));
} else {
emitForm_A(i, HEX64(30000000, 00000000));
- if (i->src[2].mod.neg())
+ if (i->src(2).mod.neg())
code[0] |= 1 << 8;
}
roundMode_A(i);
if (i->ftz)
code[0] |= 1 << 6;
} else {
- assert(!i->saturate && !i->src[2].mod.neg());
- emitForm_S(i, (i->src[2].getFile() == FILE_MEMORY_CONST) ? 0x2e : 0x0e,
+ assert(!i->saturate && !i->src(2).mod.neg());
+ emitForm_S(i, (i->src(2).getFile() == FILE_MEMORY_CONST) ? 0x2e : 0x0e,
false);
if (neg1)
code[0] |= 1 << 4;
void
CodeEmitterNVC0::emitFMUL(const Instruction *i)
{
- bool neg = (i->src[0].mod ^ i->src[1].mod).neg();
+ bool neg = (i->src(0).mod ^ i->src(1).mod).neg();
assert(i->postFactor >= -3 && i->postFactor <= 3);
if (i->encSize == 8) {
- if (isLIMM(i->src[1], TYPE_F32)) {
+ if (isLIMM(i->src(1), TYPE_F32)) {
assert(i->postFactor == 0); // constant folded, hopefully
emitForm_A(i, HEX64(30000000, 00000002));
} else {
CodeEmitterNVC0::emitUMUL(const Instruction *i)
{
if (i->encSize == 8) {
- if (i->src[1].getFile() == FILE_IMMEDIATE) {
+ if (i->src(1).getFile() == FILE_IMMEDIATE) {
emitForm_A(i, HEX64(10000000, 00000002));
} else {
emitForm_A(i, HEX64(50000000, 00000003));
if (i->dType == TYPE_S32)
code[0] |= 1 << 7;
} else {
- emitForm_S(i, i->src[1].getFile() == FILE_IMMEDIATE ? 0xaa : 0x2a, true);
+ emitForm_S(i, i->src(1).getFile() == FILE_IMMEDIATE ? 0xaa : 0x2a, true);
if (i->sType == TYPE_S32)
code[0] |= 1 << 6;
CodeEmitterNVC0::emitFADD(const Instruction *i)
{
if (i->encSize == 8) {
- if (isLIMM(i->src[1], TYPE_F32)) {
+ if (isLIMM(i->src(1), TYPE_F32)) {
assert(!i->saturate);
emitForm_A(i, HEX64(28000000, 00000002));
- code[0] |= i->src[0].mod.abs() << 7;
- code[0] |= i->src[0].mod.neg() << 9;
+ code[0] |= i->src(0).mod.abs() << 7;
+ code[0] |= i->src(0).mod.neg() << 9;
- if (i->src[1].mod.abs())
+ if (i->src(1).mod.abs())
code[1] &= 0xfdffffff;
- if ((i->op == OP_SUB) != static_cast<bool>(i->src[1].mod.neg()))
+ if ((i->op == OP_SUB) != static_cast<bool>(i->src(1).mod.neg()))
code[1] ^= 0x02000000;
} else {
emitForm_A(i, HEX64(50000000, 00000000));
code[0] |= 1 << 5;
} else {
assert(!i->saturate && i->op != OP_SUB &&
- !i->src[0].mod.abs() &&
- !i->src[1].mod.neg() && !i->src[1].mod.abs());
+ !i->src(0).mod.abs() &&
+ !i->src(1).mod.neg() && !i->src(1).mod.abs());
emitForm_S(i, 0x49, true);
- if (i->src[0].mod.neg())
+ if (i->src(0).mod.neg())
code[0] |= 1 << 7;
}
}
{
uint32_t addOp = 0;
- assert(!i->src[0].mod.abs() && !i->src[1].mod.abs());
- assert(!i->src[0].mod.neg() || !i->src[1].mod.neg());
+ assert(!i->src(0).mod.abs() && !i->src(1).mod.abs());
+ assert(!i->src(0).mod.neg() || !i->src(1).mod.neg());
- if (i->src[0].mod.neg())
+ if (i->src(0).mod.neg())
addOp |= 0x200;
- if (i->src[1].mod.neg())
+ if (i->src(1).mod.neg())
addOp |= 0x100;
if (i->op == OP_SUB) {
addOp ^= 0x100;
}
if (i->encSize == 8) {
- if (isLIMM(i->src[1], TYPE_U32)) {
+ if (isLIMM(i->src(1), TYPE_U32)) {
emitForm_A(i, HEX64(08000000, 00000002));
- if (i->def[1].exists())
+ if (i->defExists(1))
code[1] |= 1 << 26; // write carry
} else {
emitForm_A(i, HEX64(48000000, 00000003));
- if (i->def[1].exists())
+ if (i->defExists(1))
code[1] |= 1 << 16; // write carry
}
code[0] |= addOp;
} else {
assert(!(addOp & 0x100));
emitForm_S(i, (addOp >> 3) |
- ((i->src[1].getFile() == FILE_IMMEDIATE) ? 0xac : 0x2c), true);
+ ((i->src(1).getFile() == FILE_IMMEDIATE) ? 0xac : 0x2c), true);
}
}
if (i->flagsDef >= 0) code[1] |= 1 << 16;
if (i->flagsSrc >= 0) code[1] |= 1 << 23;
- if (i->src[2].mod.neg()) code[0] |= 0x10;
- if (i->src[1].mod.neg() ^
- i->src[0].mod.neg()) code[0] |= 0x20;
+ if (i->src(2).mod.neg()) code[0] |= 0x10;
+ if (i->src(1).mod.neg() ^
+ i->src(0).mod.neg()) code[0] |= 0x20;
if (i->subOp == NV50_IR_SUBOP_MUL_HIGH)
code[0] |= 1 << 6;
CodeEmitterNVC0::emitNOT(Instruction *i)
{
assert(i->encSize == 8);
- i->src[1].set(i->src[0]);
+ i->setSrc(1, i->src(0));
emitForm_A(i, HEX64(68000000, 000001c3));
}
CodeEmitterNVC0::emitLogicOp(const Instruction *i, uint8_t subOp)
{
if (i->encSize == 8) {
- if (isLIMM(i->src[1], TYPE_U32)) {
+ if (isLIMM(i->src(1), TYPE_U32)) {
emitForm_A(i, HEX64(38000000, 00000002));
- if (i->src[2].exists())
+ if (i->srcExists(2))
code[1] |= 1 << 26;
} else {
emitForm_A(i, HEX64(68000000, 00000003));
- if (i->src[2].exists())
+ if (i->srcExists(2))
code[1] |= 1 << 16;
}
code[0] |= subOp << 6;
- if (i->src[2].exists()) // carry
+ if (i->srcExists(2)) // carry
code[0] |= 1 << 5;
- if (i->src[0].mod & Modifier(NV50_IR_MOD_NOT)) code[0] |= 1 << 9;
- if (i->src[1].mod & Modifier(NV50_IR_MOD_NOT)) code[0] |= 1 << 8;
+ if (i->src(0).mod & Modifier(NV50_IR_MOD_NOT)) code[0] |= 1 << 9;
+ if (i->src(1).mod & Modifier(NV50_IR_MOD_NOT)) code[0] |= 1 << 8;
} else {
emitForm_S(i, (subOp << 5) |
- ((i->src[1].getFile() == FILE_IMMEDIATE) ? 0x1d : 0x8d), true);
+ ((i->src(1).getFile() == FILE_IMMEDIATE) ? 0x1d : 0x8d), true);
}
}
{
emitForm_A(i, HEX64(54000000, 00000004));
- if (i->src[0].mod & Modifier(NV50_IR_MOD_NOT)) code[0] |= 1 << 9;
- if (i->src[1].mod & Modifier(NV50_IR_MOD_NOT)) code[0] |= 1 << 8;
+ if (i->src(0).mod & Modifier(NV50_IR_MOD_NOT)) code[0] |= 1 << 9;
+ if (i->src(1).mod & Modifier(NV50_IR_MOD_NOT)) code[0] |= 1 << 8;
}
void
if (i->op == OP_PREEX2)
code[0] |= 0x20;
- if (i->src[0].mod.abs()) code[0] |= 1 << 6;
- if (i->src[0].mod.neg()) code[0] |= 1 << 8;
+ if (i->src(0).mod.abs()) code[0] |= 1 << 6;
+ if (i->src(0).mod.neg()) code[0] |= 1 << 8;
} else {
emitForm_S(i, i->op == OP_PREEX2 ? 0x74000008 : 0x70000008, true);
}
emitPredicate(i);
- defId(i->def[0], 14);
- srcId(i->src[0], 20);
+ defId(i->def(0), 14);
+ srcId(i->src(0), 20);
- assert(i->src[0].getFile() == FILE_GPR);
+ assert(i->src(0).getFile() == FILE_GPR);
if (i->saturate) code[0] |= 1 << 5;
- if (i->src[0].mod.abs()) code[0] |= 1 << 7;
- if (i->src[0].mod.neg()) code[0] |= 1 << 9;
+ if (i->src(0).mod.abs()) code[0] |= 1 << 7;
+ if (i->src(0).mod.neg()) code[0] |= 1 << 9;
} else {
emitForm_S(i, 0x80000008 | (subOp << 26), true);
- assert(!i->src[0].mod.neg());
- if (i->src[0].mod.abs()) code[0] |= 1 << 30;
+ assert(!i->src(0).mod.neg());
+ if (i->src(0).mod.abs()) code[0] |= 1 << 30;
}
}
}
const bool sat = (i->op == OP_SAT) || i->saturate;
- const bool abs = (i->op == OP_ABS) || i->src[0].mod.abs();
- const bool neg = (i->op == OP_NEG) || i->src[0].mod.neg();
+ const bool abs = (i->op == OP_ABS) || i->src(0).mod.abs();
+ const bool neg = (i->op == OP_NEG) || i->src(0).mod.neg();
if (i->encSize == 8) {
emitForm_B(i, HEX64(10000000, 00000004));
}
emitForm_A(i, (static_cast<uint64_t>(hi) << 32) | lo);
- if (i->def[0].getFile() == FILE_PREDICATE) {
+ if (i->def(0).getFile() == FILE_PREDICATE) {
if (i->sType == TYPE_F32)
code[1] += 0x10000000;
else
code[1] += 0x08000000;
code[0] &= ~0xfc000;
- defId(i->def[0], 17);
+ defId(i->def(0), 17);
if (i->defExists(1))
- defId(i->def[1], 14);
+ defId(i->def(1), 14);
else
code[0] |= 0x1c000;
}
CondCode cc = i->setCond;
- if (i->src[2].mod.neg())
+ if (i->src(2).mod.neg())
cc = reverseCondCode(cc);
emitCondCode(cc, 32 + 23);
{
emitForm_A(i, HEX64(20000000, 00000004));
- if (i->cc == CC_NOT_P || i->src[2].mod & Modifier(NV50_IR_MOD_NOT))
+ if (i->cc == CC_NOT_P || i->src(2).mod & Modifier(NV50_IR_MOD_NOT))
code[1] |= 1 << 20;
}
if (i->tex.liveOnly)
code[0] |= 1 << 9;
- defId(i->def[0], 14);
- srcId(i->src[0], 20);
+ defId(i->def(0), 14);
+ srcId(i->src(0), 20);
}
void
if (i->tex.derivAll)
code[1] |= 1 << 13;
- defId(i->def[0], 14);
- srcId(i->src[0], 20);
+ defId(i->def(0), 14);
+ srcId(i->src(0), 20);
emitPredicate(i);
if (i->op == OP_TXD && i->tex.useOffsets)
++src1;
- if (i->src[src1].getFile() == FILE_IMMEDIATE) { // lzero
+ if (i->srcExists(src1) && i->src(src1).getFile() == FILE_IMMEDIATE) {
+ // lzero
if (i->op == OP_TXL)
code[1] &= ~(1 << 26);
else
if (i->tex.useOffsets) // in vecSrc0.w
code[1] |= 1 << 22;
- srcId(i->src[src1], 26);
+ srcId(i, src1, 26);
}
void
if (i->tex.sIndirectSrc >= 0 || i->tex.rIndirectSrc >= 0)
code[1] |= 1 << 18;
- defId(i->def[0], 14);
- srcId(i->src[0], 20);
- srcId(i->src[1], 26);
+ defId(i->def(0), 14);
+ srcId(i->src(0), 20);
+ srcId(i->src(1), 26);
emitPredicate(i);
}
code[0] = 0x00000000 | (laneMask << 6);
code[1] = 0x48000000 | qOp;
- defId(i->def[0], 14);
- srcId(i->src[0], 20);
- srcId(i->srcExists(1) ? i->src[1] : i->src[0], 26);
+ defId(i->def(0), 14);
+ srcId(i->src(0), 20);
+ srcId(i->srcExists(1) ? i->src(1) : i->src(0), 26);
if (i->op == OP_QUADOP && progType != Program::TYPE_FRAGMENT)
code[0] |= 1 << 9; // dall
switch (i->op) {
case OP_BRA:
code[1] = f->absolute ? 0x00000000 : 0x40000000;
- if (i->src[0].getFile() == FILE_MEMORY_CONST ||
- i->src[1].getFile() == FILE_MEMORY_CONST)
- code[1] |= 0x4000;
+ if (i->srcExists(0) && i->src(0).getFile() == FILE_MEMORY_CONST)
+ code[0] |= 0x4000;
mask = 3;
break;
case OP_CALL:
code[1] = f->absolute ? 0x10000000 : 0x50000000;
- if (i->src[0].getFile() == FILE_MEMORY_CONST)
- code[1] |= 0x4000;
+ if (i->srcExists(0) && i->src(0).getFile() == FILE_MEMORY_CONST)
+ code[0] |= 0x4000;
mask = 2;
break;
void
CodeEmitterNVC0::emitPFETCH(const Instruction *i)
{
- uint32_t prim = i->src[0].get()->reg.data.u32;
+ uint32_t prim = i->src(0).get()->reg.data.u32;
code[0] = 0x00000006 | ((prim & 0x3f) << 26);
code[1] = 0x00000000 | (prim >> 6);
emitPredicate(i);
- defId(i->def[0], 14);
- srcId(i->src[1], 20);
+ defId(i->def(0), 14);
+ srcId(i->src(1), 20);
}
void
CodeEmitterNVC0::emitVFETCH(const Instruction *i)
{
code[0] = 0x00000006;
- code[1] = 0x06000000 | i->src[0].get()->reg.data.offset;
+ code[1] = 0x06000000 | i->src(0).get()->reg.data.offset;
if (i->perPatch)
code[0] |= 0x100;
code[0] |= (i->defCount(0xf) - 1) << 5;
- defId(i->def[0], 14);
- srcId(i->src[0].getIndirect(0), 20);
- srcId(i->src[0].getIndirect(1), 26); // vertex address
+ defId(i->def(0), 14);
+ srcId(i->src(0).getIndirect(0), 20);
+ srcId(i->src(0).getIndirect(1), 26); // vertex address
}
void
unsigned int size = typeSizeof(i->dType);
code[0] = 0x00000006 | ((size / 4 - 1) << 5);
- code[1] = 0x0a000000 | i->src[0].get()->reg.data.offset;
+ code[1] = 0x0a000000 | i->src(0).get()->reg.data.offset;
assert(!(code[1] & ((size == 12) ? 15 : (size - 1))));
emitPredicate(i);
- assert(i->src[1].getFile() == FILE_GPR);
+ assert(i->src(1).getFile() == FILE_GPR);
- srcId(i->src[0].getIndirect(0), 20);
- srcId(i->src[0].getIndirect(1), 32 + 17); // vertex base address
- srcId(i->src[1], 26);
+ srcId(i->src(0).getIndirect(0), 20);
+ srcId(i->src(0).getIndirect(1), 32 + 17); // vertex base address
+ srcId(i->src(1), 26);
}
void
emitPredicate(i);
- defId(i->def[0], 14); // new secret address
- srcId(i->src[0], 20); // old secret address, should be 0 initially
+ defId(i->def(0), 14); // new secret address
+ srcId(i->src(0), 20); // old secret address, should be 0 initially
- assert(i->src[0].getFile() == FILE_GPR);
+ assert(i->src(0).getFile() == FILE_GPR);
if (i->op == OP_EMIT)
code[0] |= 1 << 5;
code[0] |= 1 << 6;
// vertex stream
- if (i->src[1].getFile() == FILE_IMMEDIATE) {
+ if (i->src(1).getFile() == FILE_IMMEDIATE) {
code[1] |= 0xc000;
- code[0] |= SDATA(i->src[1]).u32 << 26;
+ code[0] |= SDATA(i->src(1)).u32 << 26;
} else {
- srcId(i->src[1], 26);
+ srcId(i->src(1), 26);
}
}
code[0] |= 1 << 5;
if (i->op == OP_PINTERP)
- srcId(i->src[1], 26);
+ srcId(i->src(1), 26);
else
code[0] |= 0x3f << 26;
- srcId(i->src[0].getIndirect(0), 20);
+ srcId(i->src(0).getIndirect(0), 20);
} else {
assert(i->op == OP_PINTERP);
code[0] = 0x00000009 | ((base & 0xc) << 6) | ((base >> 4) << 26);
- srcId(i->src[1], 20);
+ srcId(i->src(1), 20);
}
emitInterpMode(i);
emitPredicate(i);
- defId(i->def[0], 14);
+ defId(i->def(0), 14);
if (i->getSampleMode() == NV50_IR_INTERP_OFFSET)
- srcId(i->src[i->op == OP_PINTERP ? 2 : 1], 17);
+ srcId(i->src(i->op == OP_PINTERP ? 2 : 1), 17);
else
code[1] |= 0x3f << 17;
}
{
uint32_t opc;
- switch (i->src[0].getFile()) {
+ switch (i->src(0).getFile()) {
case FILE_MEMORY_GLOBAL: opc = 0x90000000; break;
case FILE_MEMORY_LOCAL: opc = 0xc8000000; break;
case FILE_MEMORY_SHARED: opc = 0xc9000000; break;
code[0] = 0x00000005;
code[1] = opc;
- setAddress16(i->src[0]);
- srcId(i->src[1], 14);
- srcId(i->src[0].getIndirect(0), 20);
+ setAddress16(i->src(0));
+ srcId(i->src(1), 14);
+ srcId(i->src(0).getIndirect(0), 20);
emitPredicate(i);
code[0] = 0x00000005;
- switch (i->src[0].getFile()) {
+ switch (i->src(0).getFile()) {
case FILE_MEMORY_GLOBAL: opc = 0x80000000; break;
case FILE_MEMORY_LOCAL: opc = 0xc0000000; break;
case FILE_MEMORY_SHARED: opc = 0xc1000000; break;
case FILE_MEMORY_CONST:
- if (!i->src[0].isIndirect(0) && typeSizeof(i->dType) == 4) {
+ if (!i->src(0).isIndirect(0) && typeSizeof(i->dType) == 4) {
emitMOV(i); // not sure if this is any better
return;
}
- opc = 0x14000000 | (i->src[0].get()->reg.fileIndex << 10);
+ opc = 0x14000000 | (i->src(0).get()->reg.fileIndex << 10);
code[0] = 0x00000006 | (i->subOp << 8);
break;
default:
}
code[1] = opc;
- defId(i->def[0], 14);
+ defId(i->def(0), 14);
- setAddress16(i->src[0]);
- srcId(i->src[0].getIndirect(0), 20);
+ setAddress16(i->src(0));
+ srcId(i->src(0).getIndirect(0), 20);
emitPredicate(i);
void
CodeEmitterNVC0::emitMOV(const Instruction *i)
{
- if (i->src[0].getFile() == FILE_SYSTEM_VALUE) {
- uint8_t sr = getSRegEncoding(i->src[0]);
+ if (i->src(0).getFile() == FILE_SYSTEM_VALUE) {
+ uint8_t sr = getSRegEncoding(i->src(0));
if (i->encSize == 8) {
code[0] = 0x00000004 | (sr << 26);
} else {
code[0] = 0x40000008 | (sr << 20);
}
- defId(i->def[0], 14);
+ defId(i->def(0), 14);
emitPredicate(i);
} else
if (i->encSize == 8) {
uint64_t opc;
- if (i->src[0].getFile() == FILE_IMMEDIATE)
+ if (i->src(0).getFile() == FILE_IMMEDIATE)
opc = HEX64(18000000, 000001e2);
else
- if (i->src[0].getFile() == FILE_PREDICATE)
+ if (i->src(0).getFile() == FILE_PREDICATE)
opc = HEX64(080e0000, 1c000004);
else
opc = HEX64(28000000, 00000004);
} else {
uint32_t imm;
- if (i->src[0].getFile() == FILE_IMMEDIATE) {
- imm = SDATA(i->src[0]).u32;
+ if (i->src(0).getFile() == FILE_IMMEDIATE) {
+ imm = SDATA(i->src(0)).u32;
if (imm & 0xfff00000) {
assert(!(imm & 0x000fffff));
code[0] = 0x00000318 | imm;
}
} else {
code[0] = 0x0028;
- emitShortSrc2(i->src[0]);
+ emitShortSrc2(i->src(0));
}
- defId(i->def[0], 14);
+ defId(i->def(0), 14);
emitPredicate(i);
}
// assert that instructions with multiple defs don't corrupt registers
for (int d = 0; insn->defExists(d); ++d)
- assert(insn->asTex() || insn->def[d].rep()->reg.data.id >= 0);
+ assert(insn->asTex() || insn->def(d).rep()->reg.data.id >= 0);
switch (insn->op) {
case OP_MOV:
emitQUADOP(insn, insn->subOp, insn->lanes);
break;
case OP_DFDX:
- emitQUADOP(insn, insn->src[0].mod.neg() ? 0x66 : 0x99, 0x4);
+ emitQUADOP(insn, insn->src(0).mod.neg() ? 0x66 : 0x99, 0x4);
break;
case OP_DFDY:
- emitQUADOP(insn, insn->src[0].mod.neg() ? 0x5a : 0xa5, 0x5);
+ emitQUADOP(insn, insn->src(0).mod.neg() ? 0x5a : 0xa5, 0x5);
break;
case OP_POPCNT:
emitPOPC(insn);
}
for (int s = 0; i->srcExists(s); ++s) {
- if (i->src[s].isIndirect(0))
+ if (i->src(s).isIndirect(0))
return 8;
- if (i->src[s].getFile() == FILE_MEMORY_CONST) {
- if (SDATA(i->src[s]).offset >= 0x100)
+ if (i->src(s).getFile() == FILE_MEMORY_CONST) {
+ if (SDATA(i->src(s)).offset >= 0x100)
return 8;
if (i->getSrc(s)->reg.fileIndex > 1 &&
i->getSrc(s)->reg.fileIndex != 16)
return 8;
} else
- if (i->src[s].getFile() == FILE_IMMEDIATE) {
+ if (i->src(s).getFile() == FILE_IMMEDIATE) {
if (i->dType == TYPE_F32) {
- if (SDATA(i->src[s]).u32 >= 0x100)
+ if (SDATA(i->src(s)).u32 >= 0x100)
return 8;
} else {
- if (SDATA(i->src[s]).u32 > 0xff)
+ if (SDATA(i->src(s)).u32 > 0xff)
return 8;
}
}
if (i->op == OP_CVT)
continue;
- if (i->src[s].mod != Modifier(0)) {
- if (i->src[s].mod == Modifier(NV50_IR_MOD_ABS))
+ if (i->src(s).mod != Modifier(0)) {
+ if (i->src(s).mod == Modifier(NV50_IR_MOD_ABS))
if (i->op != OP_RSQ)
return 8;
- if (i->src[s].mod == Modifier(NV50_IR_MOD_NEG))
+ if (i->src(s).mod == Modifier(NV50_IR_MOD_NEG))
if (i->op != OP_ADD || s != 0)
return 8;
}
if (i->op == OP_EMIT || i->op == OP_RESTART) {
if (!i->getDef(0)->refCount())
i->setDef(0, NULL);
- if (i->src[0].getFile() == FILE_IMMEDIATE)
+ if (i->src(0).getFile() == FILE_IMMEDIATE)
i->setSrc(0, r63); // initial value must be 0
} else
if (i->isNop()) {
int arg = txd->tex.target.getDim() + txd->tex.target.isArray();
handleTEX(txd);
- while (txd->src[arg].exists())
+ while (txd->src(arg).exists())
++arg;
txd->tex.derivAll = true;
assert(arg <= 4); // at most s/t/array, x, y, offset
for (int c = 0; c < dim; ++c) {
- txd->src[arg + c * 2 + 0].set(txd->dPdx[c]);
- txd->src[arg + c * 2 + 1].set(txd->dPdy[c]);
- txd->dPdx[c] = NULL;
- txd->dPdy[c] = NULL;
+ txd->src(arg + c * 2 + 0).set(txd->dPdx[c]);
+ txd->src(arg + c * 2 + 1).set(txd->dPdy[c]);
+ txd->dPdx[c].set(NULL);
+ txd->dPdy[c].set(NULL);
}
return true;
}
if (prog->getType() == Program::TYPE_FRAGMENT) {
int id = i->getSrc(0)->reg.data.offset / 4;
- if (i->src[0].isIndirect(0)) // TODO, ugly
+ if (i->src(0).isIndirect(0)) // TODO, ugly
return false;
i->op = OP_MOV;
- i->src[0].set(i->src[1]);
+ i->src(0).set(i->src(1));
i->setSrc(1, NULL);
i->setDef(0, new_LValue(func, FILE_GPR));
i->getDef(0)->reg.data.id = id;
case OP_WRSV:
return handleWRSV(i);
case OP_LOAD:
- if (i->src[0].getFile() == FILE_SHADER_INPUT) {
+ if (i->src(0).getFile() == FILE_SHADER_INPUT) {
i->op = OP_VFETCH;
assert(prog->getType() != Program::TYPE_FRAGMENT);
}
TargetNVC0::insnCanLoad(const Instruction *i, int s,
const Instruction *ld) const
{
- DataFile sf = ld->src[0].getFile();
+ DataFile sf = ld->src(0).getFile();
// immediate 0 can be represented by GPR $r63
if (sf == FILE_IMMEDIATE && ld->getSrc(0)->reg.data.u64 == 0)
return false;
// indirect loads can only be done by OP_LOAD/VFETCH/INTERP on nvc0
- if (ld->src[0].isIndirect(0))
+ if (ld->src(0).isIndirect(0))
return false;
for (int k = 0; i->srcExists(k); ++k) {
- if (i->src[k].getFile() == FILE_IMMEDIATE) {
+ if (i->src(k).getFile() == FILE_IMMEDIATE) {
if (i->getSrc(k)->reg.data.u64 != 0)
return false;
} else
- if (i->src[k].getFile() != FILE_GPR &&
- i->src[k].getFile() != FILE_PREDICATE) {
+ if (i->src(k).getFile() != FILE_GPR &&
+ i->src(k).getFile() != FILE_PREDICATE) {
return false;
}
}
case OP_XOR:
break;
case OP_ADD:
- if (insn->src[s ? 0 : 1].mod.neg())
+ if (insn->src(s ? 0 : 1).mod.neg())
return false;
break;
case OP_SUB:
if (s == 0)
- return insn->src[1].mod.neg() ? false : true;
+ return insn->src(1).mod.neg() ? false : true;
break;
default:
return false;