Skip to content

Commit

Permalink
Add pslrw and pshufhw
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-conway committed Aug 17, 2022
1 parent a8d9ea9 commit c6e1385
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
7 changes: 6 additions & 1 deletion emu/decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ __no_instrument DECODER_RET glue(DECODER_NAME, OP_SIZE)(DECODER_ARGS) {
READMODRM; V_OP(unpackl_w, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0x62: TRACEI("punpckldq xmm:modrm, xmm");
READMODRM; V_OP(unpackl_dq, 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 All @@ -315,6 +315,8 @@ __no_instrument DECODER_RET glue(DECODER_NAME, OP_SIZE)(DECODER_ARGS) {
READMODRM; READIMM8; V_OP_IMM(shuffle_d, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0x71: READMODRM_NOMEM;
switch (modrm.opcode) {
case 2: TRACEI("psrlw imm, xmm");
READIMM8; V_OP(imm_shiftr_w, imm, xmm_modrm_reg, 128); break;
case 4: TRACEI("psraw imm, xmm");
READIMM8; V_OP(imm_shiftrs_w, imm, xmm_modrm_reg, 128); break;
case 6: TRACEI("psllw imm, xmm");
Expand Down Expand Up @@ -1145,6 +1147,9 @@ __no_instrument DECODER_RET glue(DECODER_NAME, OP_SIZE)(DECODER_ARGS) {

case 0x18 ... 0x1f: TRACEI("repz nop modrm\t"); READMODRM; break;

case 0x70: TRACEI("pshufhw xmm:modrm, xmm, imm8");
READMODRM; READIMM8; V_OP_IMM(shuffle_hw, xmm_modrm_val, xmm_modrm_reg,128); break;

case 0x7f: TRACEI("movdqu xmm, xmm:modrm");
READMODRM; VMOV(xmm_modrm_reg, xmm_modrm_val,128); break;

Expand Down
15 changes: 15 additions & 0 deletions emu/vec.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ void vec_imm_shiftr_d128(NO_CPU, const uint8_t amount, union xmm_reg *dst) {
dst->u32[3] >>= amount;
}
}
void vec_imm_shiftr_w128(NO_CPU, const uint8_t amount, union xmm_reg *dst) {
if (amount > 15) {
zero_xmm(dst);
} else {
for (unsigned i = 0; i < 8; i++) {
dst->u16[i] >>= amount;
}
}
}

void vec_imm_shiftr_q64(NO_CPU, const uint8_t amount, union mm_reg *dst) {
if (amount > 63)
Expand Down Expand Up @@ -411,6 +420,12 @@ void vec_shuffle_lw128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst, uin
dst->u16[i] = src_copy.u16[(encoding >> (i*2)) % 4];
dst->qw[1] = src->qw[1];
}
void vec_shuffle_hw128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst, uint8_t encoding) {
union xmm_reg src_copy = *src;
dst->qw[0] = src->qw[0];
dst->u32[2] = src_copy.u16[(encoding >> 0 & 3) | 4] | src_copy.u16[(encoding >> 2 & 3) | 4] << 16;
dst->u32[3] = src_copy.u16[(encoding >> 4 & 3) | 4] | src_copy.u16[(encoding >> 6 & 3) | 4] << 16;
}
void vec_shuffle_d128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst, uint8_t encoding) {
union xmm_reg src_copy = *src;
for (int i = 0; i < 4; i++)
Expand Down
4 changes: 3 additions & 1 deletion emu/vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ void vec_merge128(NO_CPU, const void *src, void *dst);
void vec_imm_shiftl_w128(NO_CPU, const uint8_t amount, union xmm_reg *dst);
void vec_imm_shiftl_q128(NO_CPU, const uint8_t amount, union xmm_reg *dst);
void vec_imm_shiftl_d128(NO_CPU, const uint8_t amount, union xmm_reg *dst);
void vec_imm_shiftl_dq128(NO_CPU, const uint8_t amount, union xmm_reg *dst);
void vec_imm_shiftl_q64(NO_CPU, const uint8_t amount, union mm_reg *dst);
void vec_imm_shiftr_q128(NO_CPU, const uint8_t amount, union xmm_reg *dst);
void vec_imm_shiftr_w128(NO_CPU, const uint8_t amount, union xmm_reg *dst);
void vec_imm_shiftr_d128(NO_CPU, const uint8_t amount, union xmm_reg *dst);
void vec_imm_shiftr_q64(NO_CPU, const uint8_t amount, union mm_reg *dst);
void vec_imm_shiftl_dq128(NO_CPU, const uint8_t amount, union xmm_reg *dst);
void vec_imm_shiftr_dq128(NO_CPU, uint8_t amount, union xmm_reg *dst);
void vec_imm_shiftrs_w128(NO_CPU, const uint8_t amount, union xmm_reg *dst);
void vec_imm_shiftrs_d128(NO_CPU, const uint8_t amount, union xmm_reg *dst);
Expand Down Expand Up @@ -105,6 +106,7 @@ void vec_unpackh_w128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst);
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_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);
Expand Down
6 changes: 6 additions & 0 deletions tests/e2e/qemu/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4444,6 +4444,12 @@ pshufd : a=dc515cff944a58ec456723c698694873 ib=78 r=456723c6dc515cff944a58ec98
pshufd : a=231be9e8cde7438d007c62c2085427f8 ib=78 r=007c62c2231be9e8cde7438d085427f8
pshuflw : a=dc515cff944a58ec456723c698694873 ib=78 r=dc515cff944a58ec9869456723c64873
pshuflw : a=231be9e8cde7438d007c62c2085427f8 ib=78 r=231be9e8cde7438d0854007c62c227f8
pshufhw : a=dc515cff944a58ec456723c698694873 ib=78 r=944adc515cff58ec456723c698694873
pshufhw : a=231be9e8cde7438d007c62c2085427f8 ib=78 r=cde7231be9e8438d007c62c2085427f8
psrlw : a=dc515cff944a58ec456723c698694873 ib=07 r=01b800b9012800b1008a004701300090
psrlw : a=231be9e8cde7438d007c62c2085427f8 ib=07 r=004601d3019b0087000000c50010004f
psrlw : a=dc515cff944a58ec456723c698694873 ib=10 r=00000000000000000000000000000000
psrlw : a=231be9e8cde7438d007c62c2085427f8 ib=10 r=00000000000000000000000000000000
psraw : a=dc515cff944a58ec456723c698694873 ib=07 r=ffb800b9ff2800b1008a0047ff300090
psraw : a=231be9e8cde7438d007c62c2085427f8 ib=07 r=0046ffd3ff9b0087000000c50010004f
psraw : a=dc515cff944a58ec456723c698694873 ib=10 r=ffff0000ffff000000000000ffff0000
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/qemu/qemu-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2546,10 +2546,10 @@ void test_sse(void)

PSHUF_OP(pshufd, 0x78);
PSHUF_OP(pshuflw, 0x78);
// PSHUF_OP(pshufhw, 0x78);
PSHUF_OP(pshufhw, 0x78);

// SHIFT_OP(psrlw, 7);
// SHIFT_OP(psrlw, 16);
SHIFT_DQ_IM(psrlw, 7);
SHIFT_DQ_IM(psrlw, 16);
SHIFT_DQ_IM(psraw, 7);
SHIFT_DQ_IM(psraw, 16);
SHIFT_DQ_IM(psllw, 7);
Expand Down

0 comments on commit c6e1385

Please sign in to comment.