Skip to content

Commit

Permalink
setcc supports apx
Browse files Browse the repository at this point in the history
  • Loading branch information
herumi committed Nov 22, 2023
1 parent 25ceea2 commit ff01b1e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 33 deletions.
2 changes: 1 addition & 1 deletion gen/gen_code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ void put()
printf("void j%s(const Label& label, LabelType type = T_AUTO) { opJmp(label, type, 0x%02X, 0x%02X, 0x%02X); }%s\n", p->name, p->ext | 0x70, p->ext | 0x80, 0x0F, msg);
printf("void j%s(const char *label, LabelType type = T_AUTO) { j%s(std::string(label), type); }%s\n", p->name, p->name, msg);
printf("void j%s(const void *addr) { opJmpAbs(addr, T_NEAR, 0x%02X, 0x%02X, 0x%02X); }%s\n", p->name, p->ext | 0x70, p->ext | 0x80, 0x0F, msg);
printf("void set%s(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | %d); }%s\n", p->name, p->ext, msg);
printf("void set%s(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | %d)) return; opRext(op, 8, 0, T_0F, 0x90 | %d); }%s\n", p->name, p->ext, p->ext, msg);
}
}
{
Expand Down
11 changes: 11 additions & 0 deletions test/apx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,11 @@ CYBOZU_TEST_AUTO(mov_misc)

cmovb(r8, r9, r10);
cmovb(r8d, r9d, r10d);

setb(r31b);
setb(r31b|T_zu);
setb(r15b|T_zu);
setb(ptr [r30]);
}
} c;
const uint8_t tbl[] = {
Expand All @@ -1091,6 +1096,12 @@ CYBOZU_TEST_AUTO(mov_misc)
// cmovb
0x62, 0x54, 0xbc, 0x18, 0x42, 0xca,
0x62, 0x54, 0x3c, 0x18, 0x42, 0xca,
// setb
0x62, 0xdc, 0x7f, 0x08, 0x42, 0xc7,
0x62, 0xdc, 0x7f, 0x18, 0x42, 0xc7,
0x62, 0xd4, 0x7f, 0x18, 0x42, 0xc7,
0x62, 0xdc, 0x7f, 0x08, 0x42, 0x06,

};
const size_t n = sizeof(tbl);
CYBOZU_TEST_EQUAL(c.getSize(), n);
Expand Down
8 changes: 6 additions & 2 deletions xbyak/xbyak.h
Original file line number Diff line number Diff line change
Expand Up @@ -1932,7 +1932,7 @@ class CodeGenerator : public CodeArray {
int X4 = x.isExtIdx2() ? 0 : 0x04;
int pp = (type & (T_F2|T_F3|T_66)) ? getPP(type) : (r.isBit(16) || v.isBit(16));
int V4 = !v.isExtIdx2();
int ND = (type & T_ZU) ? r.getZU() : (type & T_ND1) ? 1 : (type & T_VEX) ? 0 : v.isREG();
int ND = (type & T_ZU) ? (r.getZU() || b.getZU()) : (type & T_ND1) ? 1 : (type & T_VEX) ? 0 : v.isREG();
int NF = r.getNF() | b.getNF() | x.getNF() | v.getNF();
int L = 0;
if ((type & T_NF) == 0 && NF) XBYAK_THROW(ERR_INVALID_NF)
Expand Down Expand Up @@ -2203,7 +2203,7 @@ class CodeGenerator : public CodeArray {
int opBit = op.getBit();
if (disableRex && opBit == 64) opBit = 32;
const Reg r(ext, Operand::REG, opBit);
if ((type & T_VEX) && op.hasRex2NF() && opROO(d ? *d : Reg(0, Operand::REG, opBit), op, r, type, code)) return;
if ((type & T_VEX) && op.hasRex2NFZU() && opROO(d ? *d : Reg(0, Operand::REG, opBit), op, r, type, code)) return;
if (op.isMEM()) {
opMR(op.getAddress(), r, type, code, immSize);
} else if (op.isREG(bit)) {
Expand Down Expand Up @@ -3040,6 +3040,10 @@ class CodeGenerator : public CodeArray {
// set default encoding to select Vex or Evex
void setDefaultEncoding(PreferredEncoding encoding) { defaultEncoding_ = encoding; }

void setb2(const Operand& op)
{
opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x42);
}
/*
use single byte nop if useMultiByteNop = false
*/
Expand Down
60 changes: 30 additions & 30 deletions xbyak/xbyak_mnemonic.h
Original file line number Diff line number Diff line change
Expand Up @@ -813,36 +813,36 @@ void scasb() { db(0xAE); }
void scasd() { db(0xAF); }
void scasw() { db(0x66); db(0xAF); }
void serialize() { db(0x0F); db(0x01); db(0xE8); }
void seta(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 7); }//-V524
void setae(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 3); }//-V524
void setb(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 2); }//-V524
void setbe(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 6); }//-V524
void setc(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 2); }//-V524
void sete(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 4); }//-V524
void setg(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 15); }//-V524
void setge(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 13); }//-V524
void setl(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 12); }//-V524
void setle(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 14); }//-V524
void setna(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 6); }//-V524
void setnae(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 2); }//-V524
void setnb(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 3); }//-V524
void setnbe(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 7); }//-V524
void setnc(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 3); }//-V524
void setne(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 5); }//-V524
void setng(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 14); }//-V524
void setnge(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 12); }//-V524
void setnl(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 13); }//-V524
void setnle(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 15); }//-V524
void setno(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 1); }//-V524
void setnp(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 11); }//-V524
void setns(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 9); }//-V524
void setnz(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 5); }//-V524
void seto(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 0); }//-V524
void setp(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 10); }//-V524
void setpe(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 10); }//-V524
void setpo(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 11); }//-V524
void sets(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 8); }//-V524
void setz(const Operand& op) { opRext(op, 8, 0, T_0F, 0x90 | 4); }//-V524
void seta(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 7)) return; opRext(op, 8, 0, T_0F, 0x90 | 7); }//-V524
void setae(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 3)) return; opRext(op, 8, 0, T_0F, 0x90 | 3); }//-V524
void setb(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 2)) return; opRext(op, 8, 0, T_0F, 0x90 | 2); }//-V524
void setbe(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 6)) return; opRext(op, 8, 0, T_0F, 0x90 | 6); }//-V524
void setc(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 2)) return; opRext(op, 8, 0, T_0F, 0x90 | 2); }//-V524
void sete(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 4)) return; opRext(op, 8, 0, T_0F, 0x90 | 4); }//-V524
void setg(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 15)) return; opRext(op, 8, 0, T_0F, 0x90 | 15); }//-V524
void setge(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 13)) return; opRext(op, 8, 0, T_0F, 0x90 | 13); }//-V524
void setl(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 12)) return; opRext(op, 8, 0, T_0F, 0x90 | 12); }//-V524
void setle(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 14)) return; opRext(op, 8, 0, T_0F, 0x90 | 14); }//-V524
void setna(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 6)) return; opRext(op, 8, 0, T_0F, 0x90 | 6); }//-V524
void setnae(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 2)) return; opRext(op, 8, 0, T_0F, 0x90 | 2); }//-V524
void setnb(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 3)) return; opRext(op, 8, 0, T_0F, 0x90 | 3); }//-V524
void setnbe(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 7)) return; opRext(op, 8, 0, T_0F, 0x90 | 7); }//-V524
void setnc(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 3)) return; opRext(op, 8, 0, T_0F, 0x90 | 3); }//-V524
void setne(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 5)) return; opRext(op, 8, 0, T_0F, 0x90 | 5); }//-V524
void setng(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 14)) return; opRext(op, 8, 0, T_0F, 0x90 | 14); }//-V524
void setnge(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 12)) return; opRext(op, 8, 0, T_0F, 0x90 | 12); }//-V524
void setnl(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 13)) return; opRext(op, 8, 0, T_0F, 0x90 | 13); }//-V524
void setnle(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 15)) return; opRext(op, 8, 0, T_0F, 0x90 | 15); }//-V524
void setno(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 1)) return; opRext(op, 8, 0, T_0F, 0x90 | 1); }//-V524
void setnp(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 11)) return; opRext(op, 8, 0, T_0F, 0x90 | 11); }//-V524
void setns(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 9)) return; opRext(op, 8, 0, T_0F, 0x90 | 9); }//-V524
void setnz(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 5)) return; opRext(op, 8, 0, T_0F, 0x90 | 5); }//-V524
void seto(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 0)) return; opRext(op, 8, 0, T_0F, 0x90 | 0); }//-V524
void setp(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 10)) return; opRext(op, 8, 0, T_0F, 0x90 | 10); }//-V524
void setpe(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 10)) return; opRext(op, 8, 0, T_0F, 0x90 | 10); }//-V524
void setpo(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 11)) return; opRext(op, 8, 0, T_0F, 0x90 | 11); }//-V524
void sets(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 8)) return; opRext(op, 8, 0, T_0F, 0x90 | 8); }//-V524
void setz(const Operand& op) { if (opROO(Reg(), op, Reg(), T_VEX|T_ZU|T_F2, 0x40 | 4)) return; opRext(op, 8, 0, T_0F, 0x90 | 4); }//-V524
void sfence() { db(0x0F); db(0xAE); db(0xF8); }
void sha1msg1(const Xmm& xmm, const Operand& op) { opSSE(xmm, op, T_0F38, 0xC9, isXMM_XMMorMEM, NONE); }
void sha1msg2(const Xmm& xmm, const Operand& op) { opSSE(xmm, op, T_0F38, 0xCA, isXMM_XMMorMEM, NONE); }
Expand Down

0 comments on commit ff01b1e

Please sign in to comment.