Skip to content

Commit

Permalink
Implement pandn, paddd, shufps
Browse files Browse the repository at this point in the history
Helps with ish-app#805
  • Loading branch information
tbodt committed Dec 7, 2020
1 parent 6cb0a30 commit 9d6ae9b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
7 changes: 7 additions & 0 deletions emu/decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ __no_instrument DECODER_RET glue(DECODER_NAME, OP_SIZE)(DECODER_ARGS) {
READMODRM; V_OP(min_ub, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0xdb: TRACEI("pand xmm:modrm, xmm");
READMODRM; V_OP(and, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0xdf: TRACEI("pandn xmm:modrm, xmm");
READMODRM; V_OP(andn, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0xeb: TRACEI("por xmm:modrm, xmm");
READMODRM; V_OP(or, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0xef: TRACEI("pxor xmm:modrm, xmm");
Expand All @@ -345,6 +347,8 @@ __no_instrument DECODER_RET glue(DECODER_NAME, OP_SIZE)(DECODER_ARGS) {
READMODRM; V_OP(sub_q, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0xfc: TRACEI("paddb xmm:modrm, xmm");
READMODRM; V_OP(add_b, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0xfe: TRACEI("paddd xmm:modrm, xmm");
READMODRM; V_OP(add_d, xmm_modrm_val, xmm_modrm_reg,128); break;
#else
case 0x10: TRACEI("movups xmm:modrm, xmm");
READMODRM; VMOV(xmm_modrm_val, xmm_modrm_reg,128); break;
Expand Down Expand Up @@ -388,6 +392,9 @@ __no_instrument DECODER_RET glue(DECODER_NAME, OP_SIZE)(DECODER_ARGS) {
case 0x7f: TRACEI("movq mm, mm:modrm");
READMODRM_MEM; VMOV(mm_modrm_reg, mm_modrm_val,64); break;

case 0xc6: TRACEI("shufps xmm:modrm, xmm, imm8");
READMODRM; READIMM8; V_OP_IMM(shuffle_d, xmm_modrm_val, xmm_modrm_reg,128); break;

case 0xd4: TRACEI("paddq mm:modrm, mm");
READMODRM; V_OP(add_q, mm_modrm_val, mm_modrm_reg,64); break;
case 0xdb: TRACEI("pand mm:modrm, mm");
Expand Down
2 changes: 1 addition & 1 deletion emu/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,11 @@ void *mem_ptr(struct mem *mem, addr_t addr, int type) {
void *data = (char *) entry->data->data + entry->offset;
void *copy = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
memcpy(copy, data, PAGE_SIZE);

// copy/paste from above
read_wrunlock(&mem->lock);
write_wrlock(&mem->lock);
memcpy(copy, data, PAGE_SIZE);
pt_map(mem, page, 1, copy, 0, entry->flags &~ P_COW);
write_wrunlock(&mem->lock);
read_wrlock(&mem->lock);
Expand Down
4 changes: 4 additions & 0 deletions emu/vec.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ void vec_add_b128(NO_CPU, union xmm_reg *src, union xmm_reg *dst) {
for (unsigned i = 0; i < array_size(src->u8); i++)
dst->u8[i] += src->u8[i];
}
void vec_add_d128(NO_CPU, union xmm_reg *src, union xmm_reg *dst) {
for (unsigned i = 0; i < array_size(src->u32); i++)
dst->u32[i] += src->u32[i];
}
void vec_add_q128(NO_CPU, union xmm_reg *src, union xmm_reg *dst) {
dst->qw[0] += src->qw[0];
dst->qw[1] += src->qw[1];
Expand Down
1 change: 1 addition & 0 deletions emu/vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void vec_imm_shiftl_dq128(NO_CPU, const uint8_t amount, union xmm_reg *dst);
void vec_shiftl_q128(NO_CPU, union xmm_reg *amount, union xmm_reg *dst);
void vec_shiftr_q128(NO_CPU, union xmm_reg *amount, union xmm_reg *dst);
void vec_add_b128(NO_CPU, union xmm_reg *src, union xmm_reg *dst);
void vec_add_d128(NO_CPU, union xmm_reg *src, union xmm_reg *dst);
void vec_add_q128(NO_CPU, union xmm_reg *src, union xmm_reg *dst);
void vec_add_q64(NO_CPU, union mm_reg *src, union mm_reg *dst);
void vec_sub_q128(NO_CPU, union xmm_reg *src, union xmm_reg *dst);
Expand Down
14 changes: 9 additions & 5 deletions tests/e2e/qemu/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4275,12 +4275,12 @@ scasl ESI=00000800 EDI=00000814 EAX=12345678 ECX=00000011 EFL=0044
scasb ESI=00000800 EDI=0000080f EAX=12345678 ECX=00000011 EFL=0044
scasw ESI=00000800 EDI=0000080e EAX=12345678 ECX=00000011 EFL=0044
scasl ESI=00000800 EDI=0000080c EAX=12345678 ECX=00000011 EFL=0044
repz scasb ESI=00000800 EDI=00000812 EAX=12345678 ECX=0000000f EFL=0095
repz scasw ESI=00000800 EDI=00000814 EAX=12345678 ECX=0000000f EFL=0091
repz scasb ESI=00000800 EDI=00000812 EAX=12345678 ECX=0000000f EFL=0004
repz scasw ESI=00000800 EDI=00000814 EAX=12345678 ECX=0000000f EFL=0004
repz scasl ESI=00000800 EDI=00000854 EAX=12345678 ECX=00000000 EFL=0044
repz scasb ESI=00000800 EDI=0000080e EAX=12345678 ECX=0000000f EFL=0095
repz scasw ESI=00000800 EDI=0000080c EAX=12345678 ECX=0000000f EFL=0091
repz scasl ESI=00000800 EDI=000007d8 EAX=12345678 ECX=00000003 EFL=0014
repz scasb ESI=00000800 EDI=0000080e EAX=12345678 ECX=0000000f EFL=0004
repz scasw ESI=00000800 EDI=0000080c EAX=12345678 ECX=0000000f EFL=0004
repz scasl ESI=00000800 EDI=000007d8 EAX=12345678 ECX=00000003 EFL=0085
repnz scasb ESI=00000800 EDI=00000811 EAX=12345678 ECX=00000010 EFL=0044
repnz scasw ESI=00000800 EDI=00000812 EAX=12345678 ECX=00000010 EFL=0044
repnz scasl ESI=00000800 EDI=00000814 EAX=12345678 ECX=00000010 EFL=0044
Expand Down Expand Up @@ -4370,6 +4370,8 @@ pand : a=456723c698694873 b=1f297ccd58bad7ab r=052120c418284023
pand : a=007c62c2085427f8 b=0f76255a085427f8 r=00742042085427f8
pand : a=dc515cff944a58ec456723c698694873 b=41f21efba9e3e1461f297ccd58bad7ab r=40501cfb80424044052120c418284023
pand : a=231be9e8cde7438d007c62c2085427f8 b=c233e9e8c4c9439a0f76255a085427f8 r=0213e9e8c4c1438800742042085427f8
pandn : a=dc515cff944a58ec456723c698694873 b=41f21efba9e3e1461f297ccd58bad7ab r=01a2020029a1a1021a085c0940929788
pandn : a=231be9e8cde7438d007c62c2085427f8 b=c233e9e8c4c9439a0f76255a085427f8 r=c0200000000800120f02051800000000
por : a=dc515cff944a58ec456723c698694873 b=41f21efba9e3e1461f297ccd58bad7ab r=ddf35effbdebf9ee5f6f7fcfd8fbdffb
por : a=231be9e8cde7438d007c62c2085427f8 b=c233e9e8c4c9439a0f76255a085427f8 r=e33be9e8cdef439f0f7e67da085427f8
pxor : a=456723c698694873 b=1f297ccd58bad7ab r=5a4e5f0bc0d39fd8
Expand All @@ -4384,6 +4386,8 @@ psubq : a=dc515cff944a58ec456723c698694873 b=41f21efba9e3e1461f297ccd58bad7ab
psubq : a=231be9e8cde7438d007c62c2085427f8 b=c233e9e8c4c9439a0f76255a085427f8 r=60e80000091dfff3f1063d6800000000
paddb : a=dc515cff944a58ec456723c698694873 b=41f21efba9e3e1461f297ccd58bad7ab r=1d437afa3d2d393264909f93f0231f1e
paddb : a=231be9e8cde7438d007c62c2085427f8 b=c233e9e8c4c9439a0f76255a085427f8 r=e54ed2d091b086270ff2871c10a84ef0
paddd : a=dc515cff944a58ec456723c698694873 b=41f21efba9e3e1461f297ccd58bad7ab r=1e437bfa3e2e3a326490a093f124201e
paddd : a=231be9e8cde7438d007c62c2085427f8 b=c233e9e8c4c9439a0f76255a085427f8 r=e54fd3d092b087270ff2881c10a84ff0
pextrw : r=0000944a
pmovmskb : r=00009918
punpcklqdq: a=dc515cff944a58ec456723c698694873 b=41f21efba9e3e1461f297ccd58bad7ab r=1f297ccd58bad7ab456723c698694873
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/qemu/qemu-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2450,7 +2450,7 @@ void test_sse(void)
// MMX_OP2(paddusb);
// MMX_OP2(paddusw);
// MMX_OP2(pmaxub);
// MMX_OP2(pandn);
SSE_OP2(pandn);

// MMX_OP2(pmulhuw);
// MMX_OP2(pmulhw);
Expand All @@ -2472,7 +2472,7 @@ void test_sse(void)
SSE_OP2(psubq);
SSE_OP2(paddb);
// MMX_OP2(paddw);
// MMX_OP2(paddd);
SSE_OP2(paddd);

// MMX_OP2(pavgb);
// MMX_OP2(pavgw);
Expand Down

0 comments on commit 9d6ae9b

Please sign in to comment.