Bug 501232 - nanojit: remove LIR_2 (3rd attempt!). r=edwsmith,gal.

This commit is contained in:
Nicholas Nethercote 2009-07-22 10:28:25 +10:00
parent e8a3e752f8
commit c414a79e4f
7 changed files with 145 additions and 54 deletions

View File

@ -270,6 +270,14 @@ namespace nanojit
return ins;
}
LInsp LirBufWriter::ins3(LOpcode op, LInsp o1, LInsp o2, LInsp o3)
{
LInsOp3* insOp3 = (LInsOp3*)_buf->makeRoom(sizeof(LInsOp3));
LIns* ins = insOp3->getLIns();
ins->initLInsOp3(op, o1, o2, o3);
return ins;
}
LInsp LirBufWriter::insLoad(LOpcode op, LInsp base, int32_t d)
{
LInsLd* insLd = (LInsLd*)_buf->makeRoom(sizeof(LInsLd));
@ -405,7 +413,7 @@ namespace nanojit
}
iop = ((LInsp)i)->opcode();
}
while (iop==LIR_skip || iop==LIR_2);
while (LIR_skip == iop);
_i = (LInsp)i;
return cur;
}
@ -441,6 +449,11 @@ namespace nanojit
return LRK_Op2 == repKinds[opcode()];
}
bool LIns::isLInsOp3() const {
NanoAssert(LRK_None != repKinds[opcode()]);
return LRK_Op3 == repKinds[opcode()];
}
bool LIns::isLInsLd() const {
NanoAssert(LRK_None != repKinds[opcode()]);
return LRK_Ld == repKinds[opcode()];
@ -586,8 +599,7 @@ namespace nanojit
return isS16(c);
}
if (i->isop(LIR_cmov) || i->isop(LIR_qcmov)) {
LInsp vals = i->oprnd2();
return insIsS16(vals->oprnd1()) && insIsS16(vals->oprnd2());
return insIsS16(i->oprnd2()) && insIsS16(i->oprnd3());
}
if (i->isCmp())
return true;
@ -647,16 +659,6 @@ namespace nanojit
LIns* ExprFilter::ins2(LOpcode v, LIns* oprnd1, LIns* oprnd2)
{
NanoAssert(oprnd1 && oprnd2);
if (v == LIR_cmov || v == LIR_qcmov) {
if (oprnd2->oprnd1() == oprnd2->oprnd2()) {
// c ? a : a => a
return oprnd2->oprnd1();
}
if (oprnd1->isconst()) {
// const ? x : y => return x or y depending on const
return oprnd1->imm32() ? oprnd2->oprnd1() : oprnd2->oprnd2();
}
}
if (oprnd1 == oprnd2)
{
switch (v) {
@ -890,6 +892,22 @@ namespace nanojit
return out->ins2(v, oprnd1, oprnd2);
}
LIns* ExprFilter::ins3(LOpcode v, LIns* oprnd1, LIns* oprnd2, LIns* oprnd3)
{
NanoAssert(oprnd1 && oprnd2 && oprnd3);
NanoAssert(v == LIR_cmov || v == LIR_qcmov);
if (oprnd2 == oprnd3) {
// c ? a : a => a
return oprnd2;
}
if (oprnd1->isconst()) {
// const ? x : y => return x or y depending on const
return oprnd1->imm32() ? oprnd2 : oprnd3;
}
return out->ins3(v, oprnd1, oprnd2, oprnd3);
}
LIns* ExprFilter::insGuard(LOpcode v, LInsp c, LInsp x)
{
if (v == LIR_xt || v == LIR_xf) {
@ -976,7 +994,7 @@ namespace nanojit
}
if (avmplus::AvmCore::use_cmov())
return ins2((iftrue->isQuad() || iffalse->isQuad()) ? LIR_qcmov : LIR_cmov, cond, ins2(LIR_2, iftrue, iffalse));
return ins3((iftrue->isQuad() || iffalse->isQuad()) ? LIR_qcmov : LIR_cmov, cond, iftrue, iffalse);
LInsp ncond = ins1(LIR_neg, cond); // cond ? -1 : 0
return ins2(LIR_or,
@ -1174,7 +1192,9 @@ namespace nanojit
return hashLoad(op, i->oprnd1(), i->disp());
default:
if (operandCount[op] == 2)
if (operandCount[op] == 3)
return hash3(op, i->oprnd1(), i->oprnd2(), i->oprnd3());
else if (operandCount[op] == 2)
return hash2(op, i->oprnd1(), i->oprnd2());
else
return hash1(op, i->oprnd1());
@ -1227,7 +1247,8 @@ namespace nanojit
{
const uint32_t count = operandCount[op];
if ((count >= 1 && a->oprnd1() != b->oprnd1()) ||
(count >= 2 && a->oprnd2() != b->oprnd2()))
(count >= 2 && a->oprnd2() != b->oprnd2()) ||
(count >= 3 && a->oprnd3() != b->oprnd3()))
return false;
return true;
}
@ -1313,6 +1334,13 @@ namespace nanojit
return _hashfinish(_hashptr(hash, b));
}
uint32_t LInsHashSet::hash3(LOpcode op, LInsp a, LInsp b, LInsp c) {
uint32_t hash = _hash8(0,uint8_t(op));
hash = _hashptr(hash, a);
hash = _hashptr(hash, b);
return _hashfinish(_hashptr(hash, c));
}
uint32_t LInsHashSet::hashLoad(LOpcode op, LInsp a, int32_t d) {
uint32_t hash = _hash8(0,uint8_t(op));
hash = _hashptr(hash, a);
@ -1394,6 +1422,23 @@ namespace nanojit
return k;
}
LInsp LInsHashSet::find3(LOpcode op, LInsp a, LInsp b, LInsp c, uint32_t &i)
{
uint32_t cap = m_cap;
const LInsp *list = m_list;
const uint32_t bitmask = (cap - 1) & ~0x1;
uint32_t hash = hash3(op,a,b,c) & bitmask;
uint32_t n = 7 << 1;
LInsp k;
while ((k = list[hash]) != NULL &&
(k->opcode() != op || k->oprnd1() != a || k->oprnd2() != b || k->oprnd3() != c))
{
hash = (hash + (n += 2)) & bitmask; // quadratic probe
}
i = hash;
return k;
}
LInsp LInsHashSet::findLoad(LOpcode op, LInsp a, int32_t d, uint32_t &i)
{
uint32_t cap = m_cap;
@ -1525,8 +1570,8 @@ namespace nanojit
}
else if (i->isop(LIR_cmov) || i->isop(LIR_qcmov)) {
live.add(i->oprnd1(),i);
live.add(i->oprnd2()->oprnd1(),i);
live.add(i->oprnd2()->oprnd2(),i);
live.add(i->oprnd2(),i);
live.add(i->oprnd3(),i);
}
else if (operandCount[i->opcode()] == 1) {
live.add(i->oprnd1(),i);
@ -1828,8 +1873,8 @@ namespace nanojit
case LIR_cmov:
sprintf(s, "%s = %s %s ? %s : %s", formatRef(i), lirNames[op],
formatRef(i->oprnd1()),
formatRef(i->oprnd2()->oprnd1()),
formatRef(i->oprnd2()->oprnd2()));
formatRef(i->oprnd2()),
formatRef(i->oprnd3()));
break;
case LIR_ld:
@ -1914,6 +1959,17 @@ namespace nanojit
return out->ins2(v,a,b);
}
LIns* CseFilter::ins3(LOpcode v, LInsp a, LInsp b, LInsp c)
{
NanoAssert(isCseOpcode(v));
NanoAssert(operandCount[v]==3);
uint32_t k;
LInsp found = exprs.find3(v, a, b, c, k);
if (found)
return found;
return exprs.add(out->ins3(v,a,b,c), k);
}
LIns* CseFilter::insLoad(LOpcode v, LInsp base, int32_t disp)
{
if (isCseOpcode(v)) {

View File

@ -280,6 +280,7 @@ namespace nanojit
LRK_Op0,
LRK_Op1,
LRK_Op2,
LRK_Op3,
LRK_Ld,
LRK_Sti,
LRK_Sk,
@ -334,6 +335,24 @@ namespace nanojit
LIns* getLIns() { return (LIns*)&ins; };
};
// 3-operand form. Used for conditional moves.
class LInsOp3
{
private:
friend class LIns;
LIns* oprnd_3;
LIns* oprnd_2;
LIns* oprnd_1;
void* ins;
public:
LIns* getLIns() { return (LIns*)&ins; };
};
// Used for all loads.
class LInsLd
{
@ -460,6 +479,7 @@ namespace nanojit
LInsOp0* toLInsOp0() const { return (LInsOp0*)( uintptr_t(this+1) - sizeof(LInsOp0) ); }
LInsOp1* toLInsOp1() const { return (LInsOp1*)( uintptr_t(this+1) - sizeof(LInsOp1) ); }
LInsOp2* toLInsOp2() const { return (LInsOp2*)( uintptr_t(this+1) - sizeof(LInsOp2) ); }
LInsOp3* toLInsOp3() const { return (LInsOp3*)( uintptr_t(this+1) - sizeof(LInsOp3) ); }
LInsLd* toLInsLd() const { return (LInsLd* )( uintptr_t(this+1) - sizeof(LInsLd ) ); }
LInsSti* toLInsSti() const { return (LInsSti*)( uintptr_t(this+1) - sizeof(LInsSti) ); }
LInsSk* toLInsSk() const { return (LInsSk* )( uintptr_t(this+1) - sizeof(LInsSk ) ); }
@ -479,6 +499,7 @@ namespace nanojit
NanoStaticAssert(sizeof(LInsOp0) == 1*sizeof(void*));
NanoStaticAssert(sizeof(LInsOp1) == 2*sizeof(void*));
NanoStaticAssert(sizeof(LInsOp2) == 3*sizeof(void*));
NanoStaticAssert(sizeof(LInsOp3) == 4*sizeof(void*));
NanoStaticAssert(sizeof(LInsLd) == 3*sizeof(void*));
NanoStaticAssert(sizeof(LInsSti) == 4*sizeof(void*));
NanoStaticAssert(sizeof(LInsSk) == 2*sizeof(void*));
@ -491,18 +512,22 @@ namespace nanojit
NanoStaticAssert(sizeof(LInsI64) == 3*sizeof(void*));
#endif
// oprnd_1 must be in the same position in LIns{Op1,Op2,Ld,Sti}
// oprnd_1 must be in the same position in LIns{Op1,Op2,Op3,Ld,Sti}
// because oprnd1() is used for all of them.
NanoStaticAssert( (offsetof(LInsOp1, ins) - offsetof(LInsOp1, oprnd_1)) ==
(offsetof(LInsOp2, ins) - offsetof(LInsOp2, oprnd_1)) );
NanoStaticAssert( (offsetof(LInsOp2, ins) - offsetof(LInsOp2, oprnd_1)) ==
(offsetof(LInsOp3, ins) - offsetof(LInsOp3, oprnd_1)) );
NanoStaticAssert( (offsetof(LInsOp3, ins) - offsetof(LInsOp3, oprnd_1)) ==
(offsetof(LInsLd, ins) - offsetof(LInsLd, oprnd_1)) );
NanoStaticAssert( (offsetof(LInsLd, ins) - offsetof(LInsLd, oprnd_1)) ==
(offsetof(LInsSti, ins) - offsetof(LInsSti, oprnd_1)) );
// oprnd_2 must be in the same position in LIns{Op2,Sti}
// oprnd_2 must be in the same position in LIns{Op2,Op3,Sti}
// because oprnd2() is used for both of them.
NanoStaticAssert( (offsetof(LInsOp2, ins) - offsetof(LInsOp2, oprnd_2)) ==
(offsetof(LInsOp3, ins) - offsetof(LInsOp3, oprnd_2)) );
NanoStaticAssert( (offsetof(LInsOp3, ins) - offsetof(LInsOp3, oprnd_2)) ==
(offsetof(LInsSti, ins) - offsetof(LInsSti, oprnd_2)) );
}
@ -525,6 +550,14 @@ namespace nanojit
toLInsOp2()->oprnd_2 = oprnd2;
NanoAssert(isLInsOp2());
}
void initLInsOp3(LOpcode opcode, LIns* oprnd1, LIns* oprnd2, LIns* oprnd3) {
lastWord.clear();
lastWord.opcode = opcode;
toLInsOp3()->oprnd_1 = oprnd1;
toLInsOp3()->oprnd_2 = oprnd2;
toLInsOp3()->oprnd_3 = oprnd3;
NanoAssert(isLInsOp3());
}
void initLInsLd(LOpcode opcode, LIns* val, int32_t d) {
lastWord.clear();
lastWord.opcode = opcode;
@ -579,13 +612,17 @@ namespace nanojit
}
LIns* oprnd1() const {
NanoAssert(isLInsOp1() || isLInsOp2() || isLInsLd() || isLInsSti());
NanoAssert(isLInsOp1() || isLInsOp2() || isLInsOp3() || isLInsLd() || isLInsSti());
return toLInsOp2()->oprnd_1;
}
LIns* oprnd2() const {
NanoAssert(isLInsOp2() || isLInsSti());
NanoAssert(isLInsOp2() || isLInsOp3() || isLInsSti());
return toLInsOp2()->oprnd_2;
}
LIns* oprnd3() const {
NanoAssert(isLInsOp3());
return toLInsOp3()->oprnd_3;
}
LIns* prevLIns() const {
NanoAssert(isLInsSk());
@ -641,6 +678,7 @@ namespace nanojit
bool isLInsOp0() const;
bool isLInsOp1() const;
bool isLInsOp2() const;
bool isLInsOp3() const;
bool isLInsSti() const;
bool isLInsLd() const;
bool isLInsSk() const;
@ -735,6 +773,9 @@ namespace nanojit
virtual LInsp ins2(LOpcode v, LIns* a, LIns* b) {
return out->ins2(v, a, b);
}
virtual LInsp ins3(LOpcode v, LIns* a, LIns* b, LIns* c) {
return out->ins3(v, a, b, c);
}
virtual LInsp insGuard(LOpcode v, LIns *c, LIns *x) {
return out->insGuard(v, c, x);
}
@ -933,7 +974,10 @@ namespace nanojit
return isRetOpcode(v) ? add_flush(out->ins1(v, a)) : add(out->ins1(v, a));
}
LIns* ins2(LOpcode v, LInsp a, LInsp b) {
return v == LIR_2 ? out->ins2(v,a,b) : add(out->ins2(v, a, b));
return add(out->ins2(v, a, b));
}
LIns* ins3(LOpcode v, LInsp a, LInsp b, LInsp c) {
return add(out->ins3(v, a, b, c));
}
LIns* insCall(const CallInfo *call, LInsp args[]) {
return add_flush(out->insCall(call, args));
@ -966,6 +1010,7 @@ namespace nanojit
ExprFilter(LirWriter *out) : LirWriter(out) {}
LIns* ins1(LOpcode v, LIns* a);
LIns* ins2(LOpcode v, LIns* a, LIns* b);
LIns* ins3(LOpcode v, LIns* a, LIns* b, LIns* c);
LIns* insGuard(LOpcode, LIns *cond, LIns *);
LIns* insBranch(LOpcode, LIns *cond, LIns *target);
};
@ -988,13 +1033,13 @@ namespace nanojit
void FASTCALL grow();
public:
LInsHashSet(GC* gc);
~LInsHashSet();
LInsp find32(int32_t a, uint32_t &i);
LInsp find64(uint64_t a, uint32_t &i);
LInsp find1(LOpcode v, LInsp a, uint32_t &i);
LInsp find2(LOpcode v, LInsp a, LInsp b, uint32_t &i);
LInsp find3(LOpcode v, LInsp a, LInsp b, LInsp c, uint32_t &i);
LInsp findLoad(LOpcode v, LInsp a, int32_t b, uint32_t &i);
LInsp findcall(const CallInfo *call, uint32_t argc, LInsp args[], uint32_t &i);
LInsp add(LInsp i, uint32_t k);
@ -1005,6 +1050,7 @@ namespace nanojit
static uint32_t FASTCALL hashimmq(uint64_t);
static uint32_t FASTCALL hash1(LOpcode v, LInsp);
static uint32_t FASTCALL hash2(LOpcode v, LInsp, LInsp);
static uint32_t FASTCALL hash3(LOpcode v, LInsp, LInsp, LInsp);
static uint32_t FASTCALL hashLoad(LOpcode v, LInsp, int32_t);
static uint32_t FASTCALL hashcall(const CallInfo *call, uint32_t argc, LInsp args[]);
};
@ -1019,6 +1065,7 @@ namespace nanojit
LIns* ins0(LOpcode v);
LIns* ins1(LOpcode v, LInsp);
LIns* ins2(LOpcode v, LInsp, LInsp);
LIns* ins3(LOpcode v, LInsp, LInsp, LInsp);
LIns* insLoad(LOpcode op, LInsp cond, int32_t d);
LIns* insCall(const CallInfo *call, LInsp args[]);
LIns* insGuard(LOpcode op, LInsp cond, LIns *x);
@ -1078,6 +1125,7 @@ namespace nanojit
LInsp ins0(LOpcode op);
LInsp ins1(LOpcode op, LInsp o1);
LInsp ins2(LOpcode op, LInsp o1, LInsp o2);
LInsp ins3(LOpcode op, LInsp o1, LInsp o2, LInsp o3);
LInsp insParam(int32_t i, int32_t kind);
LInsp insImm(int32_t imm);
LInsp insImmq(uint64_t imm);

View File

@ -107,7 +107,7 @@ OPDEF(ji, 23,-1, None) // indirect jump (currently not implemented)
*/
OPDEF(int, 24, 0, I) // constant 32-bit integer
OPDEF(cmov, 25, 2, Op2) // conditional move (op1=cond, op2=LIR_2(iftrue,iffalse))
OPDEF(cmov, 25, 3, Op3) // conditional move
#if defined(NANOJIT_64BIT)
OPDEF(callh, 26,-1, None) // unused on 64-bit machines
#else
@ -179,7 +179,8 @@ OPDEF(ugt, 61, 2, Op2) // unsigned integer greater-than (0x3D
OPDEF(ule, 62, 2, Op2) // unsigned integer less-than-or-equal (0x3E 0011 1110)
OPDEF(uge, 63, 2, Op2) // unsigned integer greater-than-or-equal (0x3F 0011 1111)
OPDEF64(2, 0, 2, Op2) // wraps a pair of refs, for LIR_cmov or LIR_qcmov
OPDEF64(unused0_64, 0,-1, None)
OPDEF64(file, 1, 2, Op1) // source filename for debug symbols
OPDEF64(line, 2, 2, Op1) // source line number for debug symbols
OPDEF64(xbarrier, 3, 1, Op2) // memory barrier; doesn't exit, but flushes all values to the stack
@ -216,7 +217,7 @@ OPDEF64(unused23_64, 23,-1, None)
// this marker are subject to CSE.
OPDEF64(quad, LIR_int, 0, I64) // 64-bit (quad) constant value
OPDEF64(qcmov, LIR_cmov, 2, Op2) // 64-bit conditional move
OPDEF64(qcmov, LIR_cmov, 3, Op3) // 64-bit conditional move
OPDEF64(unused26_64, 26,-1, None)
OPDEF64(unused27_64, 27,-1, None)

View File

@ -2212,14 +2212,10 @@ Assembler::asm_cmov(LInsp ins)
{
NanoAssert(ins->opcode() == LIR_cmov);
LIns* condval = ins->oprnd1();
LIns* iftrue = ins->oprnd2();
LIns* iffalse = ins->oprnd3();
NanoAssert(condval->isCmp());
LIns* values = ins->oprnd2();
NanoAssert(values->opcode() == LIR_2);
LIns* iftrue = values->oprnd1();
LIns* iffalse = values->oprnd2();
NanoAssert(!iftrue->isQuad() && !iffalse->isQuad());
const Register rr = prepResultReg(ins, GpRegs);

View File

@ -1122,10 +1122,8 @@ namespace nanojit
NanoAssert(ins->isop(LIR_cmov) || ins->isop(LIR_qcmov));
LIns* cond = ins->oprnd1();
NanoAssert(cond->isCmp());
LIns* values = ins->oprnd2();
NanoAssert(values->opcode() == LIR_2);
LIns* iftrue = values->oprnd1();
LIns* iffalse = values->oprnd2();
LIns* iftrue = ins->oprnd2();
LIns* iffalse = ins->oprnd3();
NanoAssert(iftrue->isQuad() == iffalse->isQuad());
// fixme: we could handle fpu registers here, too, since we're just branching
Register rr = prepResultReg(ins, GpRegs);

View File

@ -764,14 +764,10 @@ namespace nanojit
underrunProtect(4);
LOpcode op = ins->opcode();
LIns* condval = ins->oprnd1();
LIns* iftrue = ins->oprnd2();
LIns* iffalse = ins->oprnd3();
NanoAssert(condval->isCmp());
LIns* values = ins->oprnd2();
NanoAssert(values->opcode() == LIR_2);
LIns* iftrue = values->oprnd1();
LIns* iffalse = values->oprnd2();
NanoAssert(op == LIR_qcmov || (!iftrue->isQuad() && !iffalse->isQuad()));
const Register rr = prepResultReg(ins, GpRegs);

View File

@ -1059,14 +1059,10 @@ namespace nanojit
{
LOpcode op = ins->opcode();
LIns* condval = ins->oprnd1();
LIns* iftrue = ins->oprnd2();
LIns* iffalse = ins->oprnd3();
NanoAssert(condval->isCmp());
LIns* values = ins->oprnd2();
NanoAssert(values->opcode() == LIR_2);
LIns* iftrue = values->oprnd1();
LIns* iffalse = values->oprnd2();
NanoAssert(op == LIR_qcmov || (!iftrue->isQuad() && !iffalse->isQuad()));
const Register rr = prepResultReg(ins, GpRegs);