Skip to content

Commit

Permalink
Add movupd, pcmpgtb, pcmpgtw, pcmpgtd, psadbw, and movlhps
Browse files Browse the repository at this point in the history
Allows rustc to compile a Hello World
  • Loading branch information
jason-conway committed Aug 28, 2022
1 parent cb1fd5e commit 9b0e234
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
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

0 comments on commit 9b0e234

Please sign in to comment.