Skip to content

Commit

Permalink
Merge pull request ish-app#1887 from jason-conway/rust
Browse files Browse the repository at this point in the history
Instructions for rustc
  • Loading branch information
tbodt authored Aug 28, 2022
2 parents cb1fd5e + ac5e0ee commit 1b790aa
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 5 deletions.
14 changes: 14 additions & 0 deletions emu/decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ __no_instrument DECODER_RET glue(DECODER_NAME, OP_SIZE)(DECODER_ARGS) {
#endif

#if OP_SIZE == 16
case 0x10: TRACEI("movupd xmm:modrm, xmm");
READMODRM; VMOV(xmm_modrm_val, xmm_modrm_reg,128); break;
case 0x11: TRACEI("movupd xmm, xmm:modrm");
READMODRM; VMOV(xmm_modrm_reg, xmm_modrm_val,128); break;
case 0x14: TRACEI("unpcklpd xmm, xmm:modrm");
READMODRM; V_OP(unpackl_pd, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0x15: TRACEI("unpckhpd xmm, xmm:modrm");
Expand Down Expand Up @@ -299,6 +303,12 @@ __no_instrument DECODER_RET glue(DECODER_NAME, OP_SIZE)(DECODER_ARGS) {
READMODRM; V_OP(unpackl_dq, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0x63: TRACEI("packsswb xmm:modrm, xmm");
READMODRM; V_OP(packss_w, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0x64: TRACEI("pcmpgtb xmm:modrm, xmm");
READMODRM; V_OP(compares_gtb, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0x65: TRACEI("pcmpgtw xmm:modrm, xmm");
READMODRM; V_OP(compares_gtw, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0x66: TRACEI("pcmpgtd xmm:modrm, xmm");
READMODRM; V_OP(compares_gtd, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0x68: TRACEI("punpckhbw xmm:modrm, xmm");
READMODRM; V_OP(unpackh_bw, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0x69: TRACEI("punpckhwd xmm:modrm, xmm");
Expand Down Expand Up @@ -413,6 +423,8 @@ __no_instrument DECODER_RET glue(DECODER_NAME, OP_SIZE)(DECODER_ARGS) {
READMODRM; V_OP(mulu_dq, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0xf5: TRACEI("pmaddwd xmm:modrm, xmm");
READMODRM; V_OP(madd_d, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0xf6: TRACEI("psadbw xmm:modrm, xmm");
READMODRM; V_OP(sumabs_w, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0xfb: TRACEI("psubq xmm:modrm, xmm");
READMODRM; V_OP(sub_q, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0xf8: TRACEI("psubb xmm:modrm, xmm");
Expand All @@ -437,6 +449,8 @@ __no_instrument DECODER_RET glue(DECODER_NAME, OP_SIZE)(DECODER_ARGS) {
READMODRM; V_OP(unpackl_ps, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0x15: TRACEI("unpckhps xmm, xmm:modrm");
READMODRM; V_OP(unpackh_ps, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0x16: TRACEI("movlhps xmm, xmm:modrm");
READMODRM; V_OP(movlh_ps, xmm_modrm_val, xmm_modrm_reg,128); break;

case 0x2e: TRACEI("ucomiss xmm, xmm:modrm");
READMODRM; V_OP(single_ucomi, xmm_modrm_val, xmm_modrm_reg,32); break;
Expand Down
29 changes: 29 additions & 0 deletions emu/vec.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,19 @@ void vec_madd_d128(NO_CPU, union xmm_reg *src, union xmm_reg *dst) {
(int32_t)((int16_t)dst->u16[7] * (int16_t)src->u16[7]);
}

void vec_sumabs_w128(NO_CPU, union xmm_reg *src, union xmm_reg *dst) {
uint32_t sum[2] = { 0, 0 };
for (unsigned i = 0; i < 8; i++) {
int32_t difflo = dst->u8[i + 0] - src->u8[i + 0];
int32_t diffhi = dst->u8[i + 8] - src->u8[i + 8];
sum[0] += (difflo < 0) ? -(uint32_t)difflo : difflo;
sum[1] += (diffhi < 0) ? -(uint32_t)diffhi : diffhi;
}
dst->u32[0] = sum[0];
dst->u32[2] = sum[1];
dst->u32[1] = dst->u32[3] = 0;
}

void vec_mulu_dq128(NO_CPU, union xmm_reg *src, union xmm_reg *dst) {
dst->qw[0] = (uint64_t) src->u32[0] * dst->u32[0];
dst->qw[1] = (uint64_t) src->u32[2] * dst->u32[2];
Expand Down Expand Up @@ -439,6 +452,9 @@ void vec_unpackh_pd128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst) {
dst->f64[0] = dst->f64[1];
dst->f64[1] = src->f64[1];
}
void vec_movlh_ps128(NO_CPU, union xmm_reg *src, union xmm_reg *dst) {
dst->qw[1] = src->qw[0];
}

void vec_packss_w128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst) {
dst->u32[0] = (satw(dst->u16[0]) << 0x00) | (satw(dst->u16[1]) << 0x08) |
Expand Down Expand Up @@ -488,6 +504,19 @@ void vec_compare_eqd128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst) {
dst->u32[i] = dst->u32[i] == src->u32[i] ? ~0 : 0;
}

void vec_compares_gtb128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst) {
for (unsigned i = 0; i < array_size(src->u8); i++)
dst->u8[i] = (int8_t)dst->u8[i] > (int8_t)src->u8[i] ? ~0 : 0;
}
void vec_compares_gtw128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst) {
for (unsigned i = 0; i < array_size(src->u16); i++)
dst->u16[i] = (int16_t)dst->u16[i] > (int16_t)src->u16[i] ? ~0 : 0;
}
void vec_compares_gtd128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst) {
for (unsigned i = 0; i < array_size(src->u32); i++)
dst->u32[i] = (int32_t)dst->u32[i] > (int32_t)src->u32[i] ? ~0 : 0;
}

void vec_movmask_b128(NO_CPU, const union xmm_reg *src, uint32_t *dst) {
*dst = 0;
for (unsigned i = 0; i < array_size(src->u8); i++) {
Expand Down
8 changes: 7 additions & 1 deletion emu/vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void vec_mulu128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst);
void vec_muluu128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst);
void vec_mull128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst);
void vec_madd_d128(NO_CPU, union xmm_reg *src, union xmm_reg *dst);
void vec_sumabs_w128(NO_CPU, union xmm_reg *src, union xmm_reg *dst);

void vec_add_p64(NO_CPU, union xmm_reg *src, union xmm_reg *dst);
void vec_add_p32(NO_CPU, union xmm_reg *src, union xmm_reg *dst);
Expand Down Expand Up @@ -112,13 +113,18 @@ void vec_unpackh_d128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst);
void vec_unpackh_dq128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst);
void vec_unpackh_ps128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst);
void vec_unpackh_pd128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst);

void vec_movlh_ps128(NO_CPU, union xmm_reg *src, union xmm_reg *dst);
void vec_shuffle_lw128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst, uint8_t encoding);
void vec_shuffle_hw128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst, uint8_t encoding);
void vec_shuffle_d128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst, uint8_t encoding);

void vec_compare_eqb128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst);
void vec_compare_eqw128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst);
void vec_compare_eqd128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst);
void vec_compares_gtb128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst);
void vec_compares_gtw128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst);
void vec_compares_gtd128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst);

void vec_movmask_b128(NO_CPU, const union xmm_reg *src, uint32_t *dst);
void vec_fmovmask_d128(NO_CPU, const union xmm_reg *src, uint32_t *dst);
void vec_extract_w128(NO_CPU, const union xmm_reg *src, uint32_t *dst, uint8_t index);
Expand Down
8 changes: 8 additions & 0 deletions tests/e2e/qemu/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4360,6 +4360,12 @@ punpckldq: a=dc515cff944a58ec456723c698694873 b=41f21efba9e3e1461f297ccd58bad7ab
punpckldq: a=231be9e8cde7438d007c62c2085427f8 b=c233e9e8c4c9439a0f76255a085427f8 r=0f76255a007c62c2085427f8085427f8
packsswb : a=dc515cff944a58ec456723c698694873 b=41f21efba9e3e1461f297ccd58bad7ab r=7f7f80807f7f7f80807f807f7f7f807f
packsswb : a=231be9e8cde7438d007c62c2085427f8 b=c233e9e8c4c9439a0f76255a085427f8 r=8080807f7f7f7f7f7f80807f7c7f7f7f
pcmpgtb : a=dc515cff944a58ec456723c698694873 b=41f21efba9e3e1461f297ccd58bad7ab r=00ffffff00ffff00ffff000000ffffff
pcmpgtb : a=231be9e8cde7438d007c62c2085427f8 b=c233e9e8c4c9439a0f76255a085427f8 r=ff000000ffff000000ffff0000000000
pcmpgtw : a=dc515cff944a58ec456723c698694873 b=41f21efba9e3e1461f297ccd58bad7ab r=0000ffff0000ffffffff00000000ffff
pcmpgtw : a=231be9e8cde7438d007c62c2085427f8 b=c233e9e8c4c9439a0f76255a085427f8 r=ffff0000ffff00000000ffff00000000
pcmpgtd : a=dc515cff944a58ec456723c698694873 b=41f21efba9e3e1461f297ccd58bad7ab r=0000000000000000ffffffff00000000
pcmpgtd : a=231be9e8cde7438d007c62c2085427f8 b=c233e9e8c4c9439a0f76255a085427f8 r=ffffffffffffffff0000000000000000
punpckhbw: a=dc515cff944a58ec456723c698694873 b=41f21efba9e3e1461f297ccd58bad7ab r=41dcf2511e5cfbffa994e34ae15846ec
punpckhbw: a=231be9e8cde7438d007c62c2085427f8 b=c233e9e8c4c9439a0f76255a085427f8 r=c223331be9e9e8e8c4cdc9e743439a8d
punpckhwd: a=dc515cff944a58ec456723c698694873 b=41f21efba9e3e1461f297ccd58bad7ab r=41f2dc511efb5cffa9e3944ae14658ec
Expand Down Expand Up @@ -4410,6 +4416,8 @@ pmuludq : a=dc515cff944a58ec456723c698694873 b=41f21efba9e3e1461f297ccd58bad7ab
pmuludq : a=231be9e8cde7438d007c62c2085427f8 b=c233e9e8c4c9439a0f76255a085427f8 r=9e46f0ab618189d200455e29c0fd8040
pmaddwd : a=dc515cff944a58ec456723c698694873 b=41f21efba9e3e1461f297ccd58bad7ab r=020fe597198f142619e3240dd0aece1b
pmaddwd : a=231be9e8cde7438d007c62c2085427f8 b=c233e9e8c4c9439a0f76255a085427f8 r=f96e96a11d6d10310e703f5c0682dbd0
psadbw : a=dc515cff944a58ec456723c698694873 b=41f21efba9e3e1461f297ccd58bad7ab r=000000000000035b000000000000021c
psadbw : a=231be9e8cde7438d007c62c2085427f8 b=c233e9e8c4c9439a0f76255a085427f8 r=00000000000000eb00000000000000ba
psubb : a=dc515cff944a58ec456723c698694873 b=41f21efba9e3e1461f297ccd58bad7ab r=9b5f3e04eb6777a6263ea7f940af71c8
psubb : a=231be9e8cde7438d007c62c2085427f8 b=c233e9e8c4c9439a0f76255a085427f8 r=61e80000091e00f3f1063d6800000000
psubw : a=dc515cff944a58ec456723c698694873 b=41f21efba9e3e1461f297ccd58bad7ab r=9a5f3e04ea6777a6263ea6f93faf70c8
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/qemu/qemu-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2438,9 +2438,9 @@ void test_sse(void)
SSE_OP2(punpcklwd);
SSE_OP2(punpckldq);
SSE_OP2(packsswb);
// MMX_OP2(pcmpgtb);
// MMX_OP2(pcmpgtw);
// MMX_OP2(pcmpgtd);
SSE_OP2(pcmpgtb);
SSE_OP2(pcmpgtw);
SSE_OP2(pcmpgtd);
// MMX_OP2(packuswb);
SSE_OP2(punpckhbw);
SSE_OP2(punpckhwd);
Expand Down Expand Up @@ -2474,7 +2474,7 @@ void test_sse(void)
MMX_OP2(pxor);
MMX_OP2(pmuludq);
SSE_OP2(pmaddwd);
// MMX_OP2(psadbw);
SSE_OP2(psadbw);
SSE_OP2(psubb);
SSE_OP2(psubw);
SSE_OP2(psubd);
Expand Down

0 comments on commit 1b790aa

Please sign in to comment.