diff options
Diffstat (limited to 'amd64')
| -rw-r--r-- | amd64/emit.c | 22 | ||||
| -rw-r--r-- | amd64/isel.c | 18 |
2 files changed, 39 insertions, 1 deletions
diff --git a/amd64/emit.c b/amd64/emit.c index a89b021..e1d9463 100644 --- a/amd64/emit.c +++ b/amd64/emit.c @@ -280,11 +280,24 @@ DEFINSTR2(Xadd, {4, PFPR, PMEM, "\xF3\x0F\x58", EN_RM}, /* ADDSS xmm, m32 */ {8, PFPR, PMEM, "\xF2\x0F\x58", EN_RM}, /* ADDSD xmm, m64 */ ) +DEFINSTR2(Xsub, + {4|8, PGPR, PGPR, "\x2B", EN_RR}, /* SUB r32/64, r32/64 */ + {4|8, PGPR, PI8, "\x83", EN_RI8, .ext=5}, /* SUB r32/64, imm8 */ + {4|8, PRAX, PI32, "\x2D", EN_I32}, /* SUB eax/rax, imm */ + {4|8, PGPR, PI32, "\x81", EN_RI32, .ext=5}, /* SUB r32/64, imm */ + { 8, PGPR, PMEM, "\x2B", EN_RM}, /* SUB r64, m64 */ + {4, PFPR, PFPR, "\xF3\x0F\x5C", EN_RR}, /* SUBSS xmm, xmm */ + {8, PFPR, PFPR, "\xF2\x0F\x5C", EN_RR}, /* SUBSD xmm, xmm */ + {4, PFPR, PMEM, "\xF3\x0F\x5C", EN_RM}, /* SUBSS xmm, m32 */ + {8, PFPR, PMEM, "\xF2\x0F\x5C", EN_RM}, /* SUBSD xmm, m64 */ +) DEFINSTR2(Xshl, {4|8, PGPR, P1, "\xD1", EN_R, .ext=4}, /* SHL r32/64, 1 */ {4|8, PGPR, PI32, "\xC1", EN_RI8, .ext=4}, /* SHL r32/64, imm */ {4|8, PGPR, PRCX, "\xD3", EN_R, .ext=4}, /* SHL r32/64, CL */ ) +DEFINSTR1(Xinc, {4|8, PGPR, 0, "\xFF", EN_R, .ext=0} /* INC r32/64 */) +DEFINSTR1(Xdec, {4|8, PGPR, 0, "\xFF", EN_R, .ext=1} /* DEC r32/64 */) DEFINSTR1(Xidiv, {4|8, PGPR, 0, "\xF7", EN_R, .ext=7}, /* IDIV r32/64 */ {4|8, PMEM, 0, "\xF7", EN_M, .ext=7}, /* IDIV m32/64 */ @@ -433,6 +446,7 @@ emitinstr(uchar **pcode, uint *stktop, struct function *fn, struct block *blk, i struct oper dst, src; uchar ksiz = cls2siz[ins->cls]; void (*X)(uchar **, uint, struct oper, struct oper) = NULL; + void (*X1)(uchar **, uint, struct oper) = NULL; if (oisalloca(ins->op)) { uint alignlog2 = ins->op - Oalloca1; @@ -473,12 +487,20 @@ emitinstr(uchar **pcode, uint *stktop, struct function *fn, struct block *blk, i Xlea(pcode, ksiz, dst, mem); } break; + case Osub: X = Xsub; goto ALU2; case Oshl: X = Xshl; goto ALU2; ALU2: dst = mkregoper(ins->l); assert(ins->reg-1 == dst.reg); X(pcode, ksiz, dst, mkimmdatregoper(ins->r)); break; + case Oxinc: X1 = Xinc; goto ALU1; + case Oxdec: X1 = Xdec; goto ALU1; + ALU1: + dst = mkregoper(ins->l); + assert(ins->reg-1 == dst.reg); + X1(pcode, ksiz, dst); + break; case Odiv: case Orem: switch (ins->cls) { case KI8: B(0x48); /* REX.W */ diff --git a/amd64/isel.c b/amd64/isel.c index 8ab11a7..30ad222 100644 --- a/amd64/isel.c +++ b/amd64/isel.c @@ -171,7 +171,11 @@ sel(struct function *fn, struct instr *ins, struct block *blk, int *curi) insertinstr(blk, ++(*curi), temp); break; case Osub: - if (iscon(ins->l)) { + if (ins->r.bits == mkref(RICON, 1).bits) { + /* sub x,1 -> dec x */ + ins->op = Oxdec; + ins->r = NOREF; + } else if (iscon(ins->l)) { /* sub imm, x -> sub x, imm; neg x */ struct instr sub = *ins; rswap(sub.l, sub.r); @@ -181,6 +185,18 @@ sel(struct function *fn, struct instr *ins, struct block *blk, int *curi) } goto ALU; case Oadd: + if (ins->l.bits == mkref(RICON, 1).bits) { + /* add 1,x -> inc x */ + ins->op = Oxinc; + ins->l = ins->r; + ins->r = NOREF; + goto ALU; + } else if (ins->r.bits == mkref(RICON, 1).bits) { + /* add x,1 -> inc x */ + ins->op = Oxinc; + ins->r = NOREF; + goto ALU; + } if (kisint(ins->cls) && (addarg4addrp(ins->l) || addarg4addrp(ins->r))) { temp.op = Ocopy; temp.cls = ins->cls; |