Fix printvideo regression and minor improvements

This commit is contained in:
Justine Tunney 2020-08-26 09:41:07 -07:00
parent eb4bb43275
commit e86cff8ba0
25 changed files with 240 additions and 207 deletions

View file

@ -241,9 +241,7 @@ static void OpVdqWpdCvtpd2dq(struct Machine *m) {
}
void OpCvt(struct Machine *m, unsigned long op) {
op |= m->xedd->op.rep;
op |= Prefix66(m->xedd);
switch (op) {
switch (op | Rep(m->xedd) | Osz(m->xedd)) {
case kOpCvt0f2a + 0:
OpVpsQpiCvtpi2ps(m);
break;

View file

@ -23,8 +23,17 @@
#include "libc/macros.h"
#include "libc/str/str.h"
#include "tool/build/lib/dis.h"
#include "tool/build/lib/endian.h"
#include "tool/build/lib/modrm.h"
#define SSTRCMP8(S1, S2) \
({ \
uint64_t x, y; \
x = READ64BE(S1); \
y = READ64BE(S2); \
x > y ? 1 : x < y ? -1 : 0; \
})
static const char kScale[4][4] = {"", ",2", ",4", ",8"};
static const char kSegName[8][3] = {"es", "cs", "ss", "ds", "fs", "gs"};
static const char kSegOverride[8][3] = {"", "cs", "ds", "es", "fs", "gs", "ss"};
@ -541,12 +550,14 @@ static const struct DisArg {
};
char *DisArg(struct DisBuilder b, char *p, const char *s) {
char key[8];
int c, m, l, r;
l = 0;
r = ARRAYLEN(kDisArgs) - 1;
strncpy(key, s, 8);
while (l <= r) {
m = (l + r) >> 1;
c = strcmp(kDisArgs[m].s, s);
c = SSTRCMP8(kDisArgs[m].s, key);
if (c < 0) {
l = m + 1;
} else if (c > 0) {

View file

@ -45,7 +45,7 @@ static int IsRepOpcode(struct DisBuilder b) {
static char *DisRepPrefix(struct DisBuilder b, char *p) {
const char *s;
if (b.xedd->op.rep && b.xedd->op.map == XED_ILD_MAP0) {
if (Rep(b.xedd) && b.xedd->op.map == XED_ILD_MAP0) {
switch (IsRepOpcode(b)) {
case 0:
break;
@ -53,7 +53,7 @@ static char *DisRepPrefix(struct DisBuilder b, char *p) {
p = stpcpy(p, "rep ");
break;
case 2:
p = stpcpy(p, b.xedd->op.rep == 2 ? "repnz " : "repz ");
p = stpcpy(p, Rep(b.xedd) == 2 ? "repnz " : "repz ");
break;
default:
break;
@ -135,7 +135,7 @@ static char *DisName(struct DisBuilder b, char *bp, const char *name,
p = DisBranchTaken(b, p);
}
if (wantsuffixsd) {
if (b.xedd->op.prefix66) {
if (Osz(b.xedd)) {
*p++ = 'd';
} else {
*p++ = 's';

View file

@ -49,7 +49,7 @@ char *DisOpFpu1(struct XedDecodedInst *x, char *p, const char *extra) {
char *DisOp66(struct XedDecodedInst *x, char *p, const char *s, const char *a,
const char *b) {
stpcpy(stpcpy(p, s), !Prefix66(x) ? a : b);
stpcpy(stpcpy(p, s), !Osz(x) ? a : b);
return p;
}
@ -80,7 +80,7 @@ char *DisOpVpsWpsVssWssVpdWpdVsdWsd(struct XedDecodedInst *x, char *p,
stpcpy(q, "ss %Vss Wss");
} else if (x->op.ild_f2) {
stpcpy(q, "sd %Vsd Wsd");
} else if (Prefix66(x)) {
} else if (Osz(x)) {
stpcpy(q, "pd %Vpd Wpd");
} else {
stpcpy(q, "ps %Vps Wps");
@ -580,8 +580,8 @@ const char *DisSpecMap1(struct XedDecodedInst *x, char *p) {
RCASE(0x28, "movapSD %Vps Wps");
RCASE(0x29, "movapSD Wps %Vps");
RCASE(0x2B, "movntpSD Mps %Vps");
RCASE(0x2E, Prefix66(x) ? "ucomisd %Vsd Wsd" : "ucomiss %Vss Wss");
RCASE(0x2F, Prefix66(x) ? "comisd %Vsd Wsd" : "comiss %Vss Wss");
RCASE(0x2E, Osz(x) ? "ucomisd %Vsd Wsd" : "ucomiss %Vss Wss");
RCASE(0x2F, Osz(x) ? "comisd %Vsd Wsd" : "comiss %Vss Wss");
RCASE(0x31, "rdtsc");
RCASE(0x40, "cmovo %Gvqp Evqp");
RCASE(0x41, "cmovno %Gvqp Evqp");
@ -693,7 +693,7 @@ const char *DisSpecMap1(struct XedDecodedInst *x, char *p) {
RCASE(0xD3, DisOpPqQqVdqWdq(x, p, "psrlq"));
RCASE(0xD4, DisOpPqQqVdqWdq(x, p, "paddq"));
RCASE(0xD5, DisOpPqQqVdqWdq(x, p, "pmullw"));
RCASE(0xD7, Prefix66(x) ? "pmovmskb %Gdqp %Udq" : "pmovmskb %Gdqp %Nq");
RCASE(0xD7, Osz(x) ? "pmovmskb %Gdqp %Udq" : "pmovmskb %Gdqp %Nq");
RCASE(0xD8, DisOpPqQqVdqWdq(x, p, "psubusb"));
RCASE(0xD9, DisOpPqQqVdqWdq(x, p, "psubusw"));
RCASE(0xDA, DisOpPqQqVdqWdq(x, p, "pminub"));
@ -708,7 +708,7 @@ const char *DisSpecMap1(struct XedDecodedInst *x, char *p) {
RCASE(0xE3, DisOpPqQqVdqWdq(x, p, "pavgw"));
RCASE(0xE4, DisOpPqQqVdqWdq(x, p, "pmulhuw"));
RCASE(0xE5, DisOpPqQqVdqWdq(x, p, "pmulhw"));
RCASE(0xE7, Prefix66(x) ? "movntdq Mdq %Vdq" : "movntq Mq %Pq");
RCASE(0xE7, Osz(x) ? "movntdq Mdq %Vdq" : "movntq Mq %Pq");
RCASE(0xE8, DisOpPqQqVdqWdq(x, p, "psubsb"));
RCASE(0xE9, DisOpPqQqVdqWdq(x, p, "psubsw"));
RCASE(0xEA, DisOpPqQqVdqWdq(x, p, "pminsw"));
@ -740,7 +740,7 @@ const char *DisSpecMap1(struct XedDecodedInst *x, char *p) {
}
break;
case 0x70:
switch (x->op.rep | Prefix66(x)) {
switch (Rep(x) | Osz(x)) {
RCASE(0, "pshufw %Pq Qq Ib");
RCASE(1, "pshufd %Vdq Wdq Ib");
RCASE(2, "pshuflw %Vdq Wdq Ib");
@ -799,7 +799,7 @@ const char *DisSpecMap1(struct XedDecodedInst *x, char *p) {
return "movss %Vss Wss";
} else if (x->op.ild_f2) {
return "movsd %Vsd Wsd";
} else if (Prefix66(x)) {
} else if (Osz(x)) {
return "movupd %Vpd Wpd";
} else {
return "movups %Vps Wps";
@ -810,14 +810,14 @@ const char *DisSpecMap1(struct XedDecodedInst *x, char *p) {
return "movss Wss %Vss";
} else if (x->op.ild_f2) {
return "movsd Wsd %Vsd";
} else if (Prefix66(x)) {
} else if (Osz(x)) {
return "movupd Wpd %Vpd";
} else {
return "movups Wps %Vps";
}
break;
case 0xC4:
if (!Prefix66(x)) {
if (!Osz(x)) {
if (IsModrmRegister(x)) {
return "pinsrw %Pq %Rdqp Ib";
} else {
@ -832,14 +832,14 @@ const char *DisSpecMap1(struct XedDecodedInst *x, char *p) {
}
break;
case 0xC5:
if (!Prefix66(x)) {
if (!Osz(x)) {
return "pextrw %Gdqp %Nq Ib";
} else {
return "pextrw %Gdqp %Udq Ib";
}
break;
case 0xC6:
if (!Prefix66(x)) {
if (!Osz(x)) {
return "shufps %Vps Wps Ib";
} else {
return "shufpd %Vpd Wpd Ib";
@ -853,7 +853,7 @@ const char *DisSpecMap1(struct XedDecodedInst *x, char *p) {
}
break;
case 0xD6:
if (Prefix66(x)) {
if (Osz(x)) {
return "movq Wq %Vq";
} else if (x->op.ild_f3) {
return "movq2dq %Vdq %Nq";
@ -862,7 +862,7 @@ const char *DisSpecMap1(struct XedDecodedInst *x, char *p) {
}
break;
case 0x12:
switch (x->op.rep | Prefix66(x)) {
switch (Rep(x) | Osz(x)) {
case 0:
if (IsModrmRegister(x)) {
return "movhlps %Vq %Uq";
@ -881,14 +881,14 @@ const char *DisSpecMap1(struct XedDecodedInst *x, char *p) {
}
break;
case 0x13:
if (Prefix66(x)) {
if (Osz(x)) {
return "movlpd Mq %Vq";
} else {
return "movlps Mq %Vq";
}
break;
case 0x16:
switch (x->op.rep | Prefix66(x)) {
switch (Rep(x) | Osz(x)) {
case 0:
if (IsModrmRegister(x)) {
return "movlhps %Vq %Uq";
@ -905,7 +905,7 @@ const char *DisSpecMap1(struct XedDecodedInst *x, char *p) {
}
break;
case 0x17:
if (Prefix66(x)) {
if (Osz(x)) {
return "movhpd Mq %Vq";
} else {
return "movhps Mq %Vq";
@ -916,7 +916,7 @@ const char *DisSpecMap1(struct XedDecodedInst *x, char *p) {
return "cvtsi2ss %Vss Edqp";
} else if (x->op.ild_f2) {
return "cvtsi2sd %Vsd Edqp";
} else if (Prefix66(x)) {
} else if (Osz(x)) {
return "cvtpi2pd %Vpd Qpi";
} else {
return "cvtpi2ps %Vps Qpi";
@ -927,7 +927,7 @@ const char *DisSpecMap1(struct XedDecodedInst *x, char *p) {
return "cvttss2si %Gdqp Wss";
} else if (x->op.ild_f2) {
return "cvttsd2si %Gdqp Wsd";
} else if (Prefix66(x)) {
} else if (Osz(x)) {
return "cvttpd2pi %Ppi Wpd";
} else {
return "cvttps2pi %Ppi Wpsq";
@ -938,7 +938,7 @@ const char *DisSpecMap1(struct XedDecodedInst *x, char *p) {
return "cvtss2si %Gdqp Wss";
} else if (x->op.ild_f2) {
return "cvtsd2si %Gdqp Wsd";
} else if (Prefix66(x)) {
} else if (Osz(x)) {
return "cvtpd2pi %Ppi Wpd";
} else {
return "cvtps2pi %Ppi Wpsq";
@ -949,7 +949,7 @@ const char *DisSpecMap1(struct XedDecodedInst *x, char *p) {
return "cvtss2sd %Vsd Wss";
} else if (x->op.ild_f2) {
return "cvtsd2ss %Vss Wsd";
} else if (Prefix66(x)) {
} else if (Osz(x)) {
return "cvtpd2ps %Vps Wpd";
} else {
return "cvtps2pd %Vpd Wps";
@ -958,7 +958,7 @@ const char *DisSpecMap1(struct XedDecodedInst *x, char *p) {
case 0x5b:
if (x->op.ild_f3) {
return "cvttps2dq %Vdq Wps";
} else if (Prefix66(x)) {
} else if (Osz(x)) {
return "cvtps2dq %Vdq Wps";
} else {
return "cvtdq2ps %Vps Wdq";
@ -969,14 +969,14 @@ const char *DisSpecMap1(struct XedDecodedInst *x, char *p) {
return "sqrtss %Vss Wss";
} else if (x->op.ild_f2) {
return "sqrtsd %Vsd Wsd";
} else if (Prefix66(x)) {
} else if (Osz(x)) {
return "sqrtpd %Vpd Wpd";
} else {
return "sqrtps %Vps Wps";
}
break;
case 0x6E:
if (Prefix66(x)) {
if (Osz(x)) {
if (Rexw(x)) {
return "movq %Vdq Eqp";
} else {
@ -993,7 +993,7 @@ const char *DisSpecMap1(struct XedDecodedInst *x, char *p) {
case 0x6F:
if (x->op.ild_f3) {
return "movdqu %Vdq Wdq";
} else if (Prefix66(x)) {
} else if (Osz(x)) {
return "movdqa %Vdq Wdq";
} else {
return "movq %Pq Qq";
@ -1002,7 +1002,7 @@ const char *DisSpecMap1(struct XedDecodedInst *x, char *p) {
case 0x7E:
if (x->op.ild_f3) {
return "movq %Vq Wq";
} else if (Prefix66(x)) {
} else if (Osz(x)) {
if (Rexw(x)) {
return "movq Eqp %Vdq";
} else {
@ -1019,7 +1019,7 @@ const char *DisSpecMap1(struct XedDecodedInst *x, char *p) {
case 0x7F:
if (x->op.ild_f3) {
return "movdqu Wdq %Vdq";
} else if (Prefix66(x)) {
} else if (Osz(x)) {
return "movdqa Wdq %Vdq";
} else {
return "movq Qq %Pq";
@ -1028,7 +1028,7 @@ const char *DisSpecMap1(struct XedDecodedInst *x, char *p) {
case 0xE6:
if (x->op.ild_f2) {
return "cvtpd2dq %Vdq Wpd";
} else if (Prefix66(x)) {
} else if (Osz(x)) {
return "cvttpd2dq %Vdq Wpd";
} else if (x->op.ild_f3) {
return "cvtdq2pd %Vpd Wdq";

View file

@ -329,7 +329,7 @@ static void OpLoop(struct Machine *m, bool cond) {
static void OpXlat(struct Machine *m) {
int64_t v;
uint8_t al, *p;
uint8_t al;
v = Read64(m->bx) + Read8(m->ax);
if (Asz(m->xedd)) v &= 0xffffffff;
SetReadAddr(m, v, 1);
@ -613,7 +613,7 @@ static uint8_t pmovmskb(uint64_t x) {
static void OpPmovmskbGdqpNqUdq(struct Machine *m) {
uint64_t bitmask;
if (Prefix66(m->xedd)) {
if (Osz(m->xedd)) {
bitmask = pmovmskb(Read64(XmmRexbRm(m) + 8)) << 8 |
pmovmskb(Read64(XmmRexbRm(m)));
} else {
@ -895,7 +895,7 @@ static void OpMaskMovDiXmmRegXmmRm(struct Machine *m) {
uint64_t v;
unsigned i, n;
uint8_t *mem, b[16];
n = Prefix66(m->xedd) ? 16 : 8;
n = Osz(m->xedd) ? 16 : 8;
v = GetSegment() + Read64(m->di);
if (Asz(m->xedd)) v &= 0xffffffff;
mem = BeginStore(m, v, n, p, b);
@ -1011,7 +1011,7 @@ static void OpMovapdWpdVpd(struct Machine *m) {
static void OpMovWpsVps(struct Machine *m) {
uint8_t *p, *r;
switch (m->xedd->op.rep | Prefix66(m->xedd)) {
switch (Rep(m->xedd) | Osz(m->xedd)) {
case 0:
OpMovupsWpsVps(m);
break;
@ -1030,7 +1030,7 @@ static void OpMovWpsVps(struct Machine *m) {
}
static void OpMov0f28(struct Machine *m) {
if (!Prefix66(m->xedd)) {
if (!Osz(m->xedd)) {
OpMovapsVpsWps(m);
} else {
OpMovapdVpdWpd(m);
@ -1038,7 +1038,7 @@ static void OpMov0f28(struct Machine *m) {
}
static void OpMov0f6e(struct Machine *m) {
if (Prefix66(m->xedd)) {
if (Osz(m->xedd)) {
if (Rexw(m->xedd)) {
OpMovqVdqEqp(m);
} else {
@ -1054,7 +1054,7 @@ static void OpMov0f6e(struct Machine *m) {
}
static void OpMov0f6f(struct Machine *m) {
if (Prefix66(m->xedd)) {
if (Osz(m->xedd)) {
OpMovdqaVdqWdq(m);
} else if (m->xedd->op.ild_f3) {
OpMovdquVdqWdq(m);
@ -1064,7 +1064,7 @@ static void OpMov0f6f(struct Machine *m) {
}
static void OpMov0fE7(struct Machine *m) {
if (!Prefix66(m->xedd)) {
if (!Osz(m->xedd)) {
OpMovntqMqPq(m);
} else {
OpMovntdqMdqVdq(m);
@ -1074,7 +1074,7 @@ static void OpMov0fE7(struct Machine *m) {
static void OpMov0f7e(struct Machine *m) {
if (m->xedd->op.ild_f3) {
OpMovqVqWq(m);
} else if (Prefix66(m->xedd)) {
} else if (Osz(m->xedd)) {
if (Rexw(m->xedd)) {
OpMovqEqpVdq(m);
} else {
@ -1092,7 +1092,7 @@ static void OpMov0f7e(struct Machine *m) {
static void OpMov0f7f(struct Machine *m) {
if (m->xedd->op.ild_f3) {
OpMovdquWdqVdq(m);
} else if (Prefix66(m->xedd)) {
} else if (Osz(m->xedd)) {
OpMovdqaWdqVdq(m);
} else {
OpMovqQqPq(m);
@ -1101,7 +1101,7 @@ static void OpMov0f7f(struct Machine *m) {
static void OpMov0f10(struct Machine *m) {
uint8_t *p, *r;
switch (m->xedd->op.rep | Prefix66(m->xedd)) {
switch (Rep(m->xedd) | Osz(m->xedd)) {
case 0:
OpMovupsVpsWps(m);
break;
@ -1120,7 +1120,7 @@ static void OpMov0f10(struct Machine *m) {
}
static void OpMov0f29(struct Machine *m) {
if (!Prefix66(m->xedd)) {
if (!Osz(m->xedd)) {
OpMovapsWpsVps(m);
} else {
OpMovapdWpdVpd(m);
@ -1128,7 +1128,7 @@ static void OpMov0f29(struct Machine *m) {
}
static void OpMov0f2b(struct Machine *m) {
if (!Prefix66(m->xedd)) {
if (!Osz(m->xedd)) {
OpMovntpsMpsVps(m);
} else {
OpMovntpdMpdVpd(m);
@ -1136,7 +1136,7 @@ static void OpMov0f2b(struct Machine *m) {
}
static void OpMov0f12(struct Machine *m) {
switch (m->xedd->op.rep | Prefix66(m->xedd)) {
switch (Rep(m->xedd) | Osz(m->xedd)) {
case 0:
if (IsModrmRegister(m->xedd)) {
OpMovhlpsVqUq(m);
@ -1159,7 +1159,7 @@ static void OpMov0f12(struct Machine *m) {
}
static void OpMov0f13(struct Machine *m) {
if (Prefix66(m->xedd)) {
if (Osz(m->xedd)) {
OpMovlpdMqVq(m);
} else {
OpMovlpsMqVq(m);
@ -1167,7 +1167,7 @@ static void OpMov0f13(struct Machine *m) {
}
static void OpMov0f16(struct Machine *m) {
switch (m->xedd->op.rep | Prefix66(m->xedd)) {
switch (Rep(m->xedd) | Osz(m->xedd)) {
case 0:
if (IsModrmRegister(m->xedd)) {
OpMovlhpsVqUq(m);
@ -1188,7 +1188,7 @@ static void OpMov0f16(struct Machine *m) {
}
static void OpMov0f17(struct Machine *m) {
if (Prefix66(m->xedd)) {
if (Osz(m->xedd)) {
OpMovhpdMqVq(m);
} else {
OpMovhpsMqVq(m);
@ -1200,7 +1200,7 @@ static void OpMov0fD6(struct Machine *m) {
OpMovq2dqVdqNq(m);
} else if (m->xedd->op.ild_f2) {
OpMovdq2qPqUq(m);
} else if (Prefix66(m->xedd)) {
} else if (Osz(m->xedd)) {
OpMovqWqVq(m);
} else {
OpUd(m);
@ -1211,7 +1211,7 @@ static void OpUnpcklpsd(struct Machine *m) {
uint8_t *a, *b;
a = XmmRexrReg(m);
b = GetModrmRegisterXmmPointerRead8(m);
if (Prefix66(m->xedd)) {
if (Osz(m->xedd)) {
memcpy(a + 8, b, 8);
} else {
memcpy(a + 4 * 3, b + 4, 4);
@ -1224,7 +1224,7 @@ static void OpUnpckhpsd(struct Machine *m) {
uint8_t *a, *b;
a = XmmRexrReg(m);
b = GetModrmRegisterXmmPointerRead16(m);
if (Prefix66(m->xedd)) {
if (Osz(m->xedd)) {
memcpy(a + 0, b + 8, 8);
memcpy(a + 8, b + 8, 8);
} else {
@ -1238,14 +1238,14 @@ static void OpUnpckhpsd(struct Machine *m) {
static void OpPextrwGdqpUdqIb(struct Machine *m) {
uint8_t i;
i = m->xedd->op.uimm0;
i &= Prefix66(m->xedd) ? 7 : 3;
i &= Osz(m->xedd) ? 7 : 3;
Write16(RegRexrReg(m), Read16(XmmRexbRm(m) + i * 2));
}
static void OpPinsrwVdqEwIb(struct Machine *m) {
uint8_t i;
i = m->xedd->op.uimm0;
i &= Prefix66(m->xedd) ? 7 : 3;
i &= Osz(m->xedd) ? 7 : 3;
Write16(XmmRexrReg(m) + i * 2, Read16(GetModrmRegisterWordPointerRead2(m)));
}
@ -1253,7 +1253,7 @@ static void OpShuffle(struct Machine *m) {
int16_t q16[4];
int16_t x16[8];
int32_t x32[4];
switch (m->xedd->op.rep | Prefix66(m->xedd)) {
switch (Rep(m->xedd) | Osz(m->xedd)) {
case 0:
memcpy(q16, GetModrmRegisterXmmPointerRead8(m), 8);
(pshufw)(q16, q16, m->xedd->op.uimm0);
@ -1282,7 +1282,7 @@ static void OpShuffle(struct Machine *m) {
static void OpShufpsd(struct Machine *m) {
float s[4];
double d[2];
if (Prefix66(m->xedd)) {
if (Osz(m->xedd)) {
memcpy(d, GetModrmRegisterXmmPointerRead16(m), 16);
(shufpd)(d, d, m->xedd->op.uimm0);
memcpy(XmmRexrReg(m), d, 16);
@ -1297,7 +1297,7 @@ static void OpSqrtpsd(struct Machine *m) {
long i;
float_v xf;
double_v xd;
switch (m->xedd->op.rep | Prefix66(m->xedd)) {
switch (Rep(m->xedd) | Osz(m->xedd)) {
case 0:
memcpy(&xf, GetModrmRegisterXmmPointerRead16(m), 16);
for (i = 0; i < 4; ++i) xf[i] = sqrtf(xf[i]);
@ -1375,13 +1375,13 @@ static void OpVpsdWpsd(struct Machine *m,
static void OpVpsdWpsd66(struct Machine *m,
float_v opf(struct Machine *, float_v, float_v),
double_v opd(struct Machine *, double_v, double_v)) {
OpVpsdWpsd(m, opf, opd, !Prefix66(m->xedd), Prefix66(m->xedd));
OpVpsdWpsd(m, opf, opd, !Osz(m->xedd), Osz(m->xedd));
}
static void OpVpsdWpsd66f2(struct Machine *m,
float_v opf(struct Machine *, float_v, float_v),
double_v opd(struct Machine *, double_v, double_v)) {
OpVpsdWpsd(m, opf, opd, m->xedd->op.ild_f2, Prefix66(m->xedd));
OpVpsdWpsd(m, opf, opd, m->xedd->op.ild_f2, Osz(m->xedd));
}
static void OpVspsdWspsd(struct Machine *m,
@ -1389,7 +1389,7 @@ static void OpVspsdWspsd(struct Machine *m,
double_v opd(struct Machine *, double_v, double_v)) {
float_v xf, yf;
double_v xd, yd;
switch (m->xedd->op.rep | Prefix66(m->xedd)) {
switch (Rep(m->xedd) | Osz(m->xedd)) {
case 0:
memcpy(&yf, GetModrmRegisterXmmPointerRead16(m), 16);
memcpy(&xf, XmmRexrReg(m), 16);
@ -1423,7 +1423,7 @@ static void OpComissVsWs(struct Machine *m) {
float xf, yf;
double xd, yd;
uint8_t zf, cf, pf, ie;
if (!Prefix66(m->xedd)) {
if (!Osz(m->xedd)) {
memcpy(&xf, XmmRexrReg(m), 4);
memcpy(&yf, GetModrmRegisterXmmPointerRead4(m), 4);
if (!isnan(xf) && !isnan(yf)) {
@ -2366,6 +2366,7 @@ static void SaveStash(struct Machine *m) {
}
void ExecuteInstruction(struct Machine *m) {
uint8_t *p;
m->ip += m->xedd->length;
switch (m->xedd->op.map) {
CASE(XED_ILD_MAP0, ExecuteInstructionMap0(m));

View file

@ -1,6 +1,7 @@
#ifndef COSMOPOLITAN_TOOL_BUILD_LIB_MACHINE_H_
#define COSMOPOLITAN_TOOL_BUILD_LIB_MACHINE_H_
#include "libc/elf/struct/ehdr.h"
#include "libc/runtime/runtime.h"
#include "third_party/xed/x86.h"
#include "tool/build/lib/pml4t.h"

View file

@ -27,7 +27,7 @@ COSMOPOLITAN_C_START_
#define Rexb(x) (((x)->op.rde & 000010000000) >> 21)
#define Rex(x) (((x)->op.rde & 000000000020) >> 4)
#define Osz(x) (((x)->op.rde & 000000000040) >> 5)
#define Prefix66(x) (((x)->op.rde & 010000000000) >> 30)
#define Rep(x) (((x)->op.rde & 030000000000) >> 30)
#define ByteRexrReg(m) m->beg[(m->xedd->op.rde & 00000000037) >> 0]
#define ByteRexbRm(m) m->beg[(m->xedd->op.rde & 00000003700) >> 6]
#define ByteRexbSrm(m) m->beg[(m->xedd->op.rde & 00000370000) >> 12]

View file

@ -119,7 +119,7 @@ void OpSse(struct Machine *m, enum OpSseKernel kernel) {
uint8_t *p;
union MachineVector x, y, t;
p = GetModrmRegisterXmmPointerRead16(m);
if (Prefix66(m->xedd)) {
if (Osz(m->xedd)) {
memcpy(&y, p, 16);
} else {
memset(&t, 0, 16);
@ -204,7 +204,7 @@ void OpSse(struct Machine *m, enum OpSseKernel kernel) {
default:
unreachable;
}
if (Prefix66(m->xedd)) {
if (Osz(m->xedd)) {
memcpy(XmmRexrReg(m), &x, 16);
} else {
memcpy(XmmRexrReg(m), &x, 8);
@ -230,7 +230,7 @@ void OpSseUdqIb(struct Machine *m, enum OpSseUdqIbKernel kernel) {
default:
unreachable;
}
if (Prefix66(m->xedd)) {
if (Osz(m->xedd)) {
memcpy(XmmRexbRm(m), &x, 16);
} else {
memcpy(XmmRexbRm(m), &x, 8);
@ -246,7 +246,7 @@ static void OpSsePalignrMmx(struct Machine *m) {
}
void OpSsePalignr(struct Machine *m) {
if (Prefix66(m->xedd)) {
if (Osz(m->xedd)) {
palignr(XmmRexrReg(m), XmmRexrReg(m), GetModrmRegisterXmmPointerRead8(m),
m->xedd->op.uimm0);
} else {

View file

@ -78,7 +78,7 @@ void OpString(struct Machine *m, int op) {
lg2 = RegLog2(m->xedd);
n = 1 << lg2;
for (;;) {
if (m->xedd->op.rep && !Read64(m->cx)) break;
if (Rep(m->xedd) && !Read64(m->cx)) break;
v = 0;
*p = NULL;
compare = false;
@ -125,11 +125,11 @@ void OpString(struct Machine *m, int op) {
abort();
}
EndStore(m, v, n, p, s[0]);
if (!m->xedd->op.rep) break;
if (!Rep(m->xedd)) break;
Write64(m->cx, Read64(m->cx) - 1);
if (compare) {
if (m->xedd->op.rep == 2 && GetFlag(m->flags, FLAGS_ZF)) break;
if (m->xedd->op.rep == 3 && !GetFlag(m->flags, FLAGS_ZF)) break;
if (Rep(m->xedd) == 2 && GetFlag(m->flags, FLAGS_ZF)) break;
if (Rep(m->xedd) == 3 && !GetFlag(m->flags, FLAGS_ZF)) break;
}
}
}
@ -211,7 +211,7 @@ void OpRepStosbEnhanced(struct Machine *m) {
}
void OpMovsb(struct Machine *m) {
if (m->xedd->op.rep && !GetFlag(m->flags, FLAGS_DF)) {
if (Rep(m->xedd) && !GetFlag(m->flags, FLAGS_DF)) {
OpRepMovsbEnhanced(m);
} else {
OpString(m, STRING_MOVS);
@ -219,7 +219,7 @@ void OpMovsb(struct Machine *m) {
}
void OpStosb(struct Machine *m) {
if (m->xedd->op.rep && !GetFlag(m->flags, FLAGS_DF)) {
if (Rep(m->xedd) && !GetFlag(m->flags, FLAGS_DF)) {
OpRepStosbEnhanced(m);
} else {
OpString(m, STRING_STOS);

View file

@ -19,6 +19,7 @@
*/
#include "libc/log/check.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "tool/build/lib/throw.h"
static bool IsHaltingInitialized(struct Machine *m) {