Skip to content

Commit

Permalink
add tests of imul/mul/neg/not_ with 1-op
Browse files Browse the repository at this point in the history
  • Loading branch information
herumi committed Nov 16, 2023
1 parent 790afb7 commit 95ad592
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 8 deletions.
18 changes: 11 additions & 7 deletions gen/gen_code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,18 +869,22 @@ void put()
uint8_t code;
uint8_t ext;
const char *name;
bool NF;
} tbl[] = {
{ 0xF6, 6, "div" },
{ 0xF6, 7, "idiv" },
{ 0xF6, 5, "imul" },
{ 0xF6, 4, "mul" },
{ 0xF6, 3, "neg" },
{ 0xF6, 2, "not_" },
{ 0xF6, 6, "div", true },
{ 0xF6, 7, "idiv", true },
{ 0xF6, 5, "imul", true },
{ 0xF6, 4, "mul", true },
{ 0xF6, 3, "neg", true },
{ 0xF6, 2, "not_", false },
};
for (size_t i = 0; i < NUM_OF_ARRAY(tbl); i++) {
const Tbl *p = &tbl[i];
const std::string name = p->name;
printf("void %s(const Operand& op) { opRext(op, 0, %d, T_VEX|T_NF|T_CODE1_IF1, 0x%02X); }\n", p->name, p->ext, p->code);
uint64_t type = T_VEX|T_CODE1_IF1;
if (p->NF) type |= T_NF;
std::string s = type2String(type);
printf("void %s(const Operand& op) { opRext(op, 0, %d, %s, 0x%02X); }\n", p->name, p->ext, s.c_str(), p->code);
}
}
{
Expand Down
58 changes: 58 additions & 0 deletions test/apx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,48 @@ CYBOZU_TEST_AUTO(div)
idiv(dword [r20+r30*1]);
idiv(qword [r20+r30*1]);

imul(r20b);
imul(r20d);
imul(r20w);
imul(r20);
imul(r20|T_nf);
imul(eax|T_nf);
imul(byte [r20+r30*1]);
imul(word [r20+r30*1]);
imul(dword [r20+r30*1]);
imul(qword [r20+r30*1]);

mul(r20b);
mul(r20d);
mul(r20w);
mul(r20);
mul(r20|T_nf);
mul(eax|T_nf);
mul(byte [r20+r30*1]);
mul(word [r20+r30*1]);
mul(dword [r20+r30*1]);
mul(qword [r20+r30*1]);

neg(r20b);
neg(r20d);
neg(r20w);
neg(r20);
neg(r20|T_nf);
neg(eax|T_nf);
neg(byte [r20+r30*1]);
neg(word [r20+r30*1]);
neg(dword [r20+r30*1]);
neg(qword [r20+r30*1]);

// not_ does not have NF=1
not_(r20b);
not_(r20d);
not_(r20w);
not_(r20);
not_(byte [r20+r30*1]);
not_(word [r20+r30*1]);
not_(dword [r20+r30*1]);
not_(qword [r20+r30*1]);
}
} c;
const uint8_t tbl[] = {
Expand All @@ -781,6 +823,22 @@ CYBOZU_TEST_AUTO(div)
0x7c, 0x0c, 0xf7, 0xf8, 0x62, 0xbc, 0x78, 0x08, 0xf6, 0x3c, 0x34, 0x62, 0xbc, 0x79, 0x08, 0xf7,
0x3c, 0x34, 0x62, 0xbc, 0x78, 0x08, 0xf7, 0x3c, 0x34, 0x62, 0xbc, 0xf8, 0x08, 0xf7, 0x3c, 0x34,

0x62, 0xfc, 0x7c, 0x08, 0xf6, 0xec, 0x62, 0xfc, 0x7c, 0x08, 0xf7, 0xec, 0x62, 0xfc, 0x7d, 0x08,
0xf7, 0xec, 0x62, 0xfc, 0xfc, 0x08, 0xf7, 0xec, 0x62, 0xfc, 0xfc, 0x0c, 0xf7, 0xec, 0x62, 0xf4,
0x7c, 0x0c, 0xf7, 0xe8, 0x62, 0xbc, 0x78, 0x08, 0xf6, 0x2c, 0x34, 0x62, 0xbc, 0x79, 0x08, 0xf7,
0x2c, 0x34, 0x62, 0xbc, 0x78, 0x08, 0xf7, 0x2c, 0x34, 0x62, 0xbc, 0xf8, 0x08, 0xf7, 0x2c, 0x34,
0x62, 0xfc, 0x7c, 0x08, 0xf6, 0xe4, 0x62, 0xfc, 0x7c, 0x08, 0xf7, 0xe4, 0x62, 0xfc, 0x7d, 0x08,
0xf7, 0xe4, 0x62, 0xfc, 0xfc, 0x08, 0xf7, 0xe4, 0x62, 0xfc, 0xfc, 0x0c, 0xf7, 0xe4, 0x62, 0xf4,
0x7c, 0x0c, 0xf7, 0xe0, 0x62, 0xbc, 0x78, 0x08, 0xf6, 0x24, 0x34, 0x62, 0xbc, 0x79, 0x08, 0xf7,
0x24, 0x34, 0x62, 0xbc, 0x78, 0x08, 0xf7, 0x24, 0x34, 0x62, 0xbc, 0xf8, 0x08, 0xf7, 0x24, 0x34,
0x62, 0xfc, 0x7c, 0x08, 0xf6, 0xdc, 0x62, 0xfc, 0x7c, 0x08, 0xf7, 0xdc, 0x62, 0xfc, 0x7d, 0x08,
0xf7, 0xdc, 0x62, 0xfc, 0xfc, 0x08, 0xf7, 0xdc, 0x62, 0xfc, 0xfc, 0x0c, 0xf7, 0xdc, 0x62, 0xf4,
0x7c, 0x0c, 0xf7, 0xd8, 0x62, 0xbc, 0x78, 0x08, 0xf6, 0x1c, 0x34, 0x62, 0xbc, 0x79, 0x08, 0xf7,
0x1c, 0x34, 0x62, 0xbc, 0x78, 0x08, 0xf7, 0x1c, 0x34, 0x62, 0xbc, 0xf8, 0x08, 0xf7, 0x1c, 0x34,
0x62, 0xfc, 0x7c, 0x08, 0xf6, 0xd4, 0x62, 0xfc, 0x7c, 0x08, 0xf7, 0xd4, 0x62, 0xfc, 0x7d, 0x08,
0xf7, 0xd4, 0x62, 0xfc, 0xfc, 0x08, 0xf7, 0xd4, 0x62, 0xbc, 0x78, 0x08, 0xf6, 0x14, 0x34, 0x62,
0xbc, 0x79, 0x08, 0xf7, 0x14, 0x34, 0x62, 0xbc, 0x78, 0x08, 0xf7, 0x14, 0x34, 0x62, 0xbc, 0xf8,
0x08, 0xf7, 0x14, 0x34,
};
const size_t n = sizeof(tbl);
CYBOZU_TEST_EQUAL(c.getSize(), n);
Expand Down
2 changes: 1 addition & 1 deletion xbyak/xbyak_mnemonic.h
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ void mulx(const Reg32e& r1, const Reg32e& r2, const Operand& op) { opRRO(r1, r2,
void mwait() { db(0x0F); db(0x01); db(0xC9); }
void mwaitx() { db(0x0F); db(0x01); db(0xFB); }
void neg(const Operand& op) { opRext(op, 0, 3, T_VEX|T_NF|T_CODE1_IF1, 0xF6); }
void not_(const Operand& op) { opRext(op, 0, 2, T_VEX|T_NF|T_CODE1_IF1, 0xF6); }
void not_(const Operand& op) { opRext(op, 0, 2, T_VEX|T_CODE1_IF1, 0xF6); }
void or_(const Operand& op, uint32_t imm) { opOI(op, imm, 0x08, 1); }
void or_(const Operand& op1, const Operand& op2) { opRO_MR(op1, op2, 0x08); }
void or_(const Reg& d, const Operand& op, uint32_t imm) { opROI(d, op, imm, T_NF|T_CODE1_IF1, 1); }
Expand Down

0 comments on commit 95ad592

Please sign in to comment.