Skip to content

Commit

Permalink
Implement PADDQ
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewMerrill committed May 31, 2020
1 parent 03fd5bc commit 309bcf3
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions emu/decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ __no_instrument DECODER_RET glue(DECODER_NAME, OP_SIZE)(DECODER_ARGS) {
case 0xc5: TRACEI("pextrw xmm, modrm_val, imm8");
READMODRM_NOMEM; READIMM8; V_OP_IMM(extract_w, xmm_modrm_val, modrm_reg,128); break;

case 0xd4: TRACEI("paddq xmm:modrm, xmm");
READMODRM; V_OP(add, xmm_modrm_val, xmm_modrm_reg, 64); break;

case 0xd6: TRACEI("movq xmm, xmm:modrm");
READMODRM; VMOV(xmm_modrm_reg, xmm_modrm_val,64); break;

Expand Down
5 changes: 5 additions & 0 deletions emu/vec.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ void vec_xor128(NO_CPU, union xmm_reg *src, union xmm_reg *dst) {
dst->qw[1] ^= src->qw[1];
}

void vec_add64(NO_CPU, union xmm_reg *src, union xmm_reg *dst) {
dst->qw[0] += src->qw[0];
dst->qw[1] += src->qw[1];
}

void vec_fadds64(NO_CPU, const double *src, double *dst) {
*dst += *src;
}
Expand Down
2 changes: 2 additions & 0 deletions emu/vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ void vec_imm_shiftl64(NO_CPU, const uint8_t amount, union xmm_reg *dst);
void vec_imm_shiftr64(NO_CPU, const uint8_t amount, union xmm_reg *dst);
void vec_xor128(NO_CPU, union xmm_reg *src, union xmm_reg *dst);

void vec_add64(NO_CPU, union xmm_reg *src, union xmm_reg *dst);

void vec_fadds64(NO_CPU, const double *src, double *dst);
void vec_fmuls64(NO_CPU, const double *src, double *dst);
void vec_fsubs64(NO_CPU, const double *src, double *dst);
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/sse2/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ psrlq
01234 05678
00617 02839
00000 00000
paddq
01234 05678
11111 11111
12345 16789
29 changes: 29 additions & 0 deletions tests/e2e/sse2/paddq.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdint.h>
#include <stdio.h>
#include <emmintrin.h>
#include <xmmintrin.h>

#define printout() printf("%05lld %05lld\n", (long long) out[0], (long long) out[1])

void main(void) {
int64_t out[2] = { 0, 0 };
int64_t buf1234[2] = { 1234, 5678 };
int64_t buf1111[2] = { 11111, 11111 };

// xmm1 Initially 1234
__m128i xmm1 = _mm_load_si128((__m128i*) buf1234);
_mm_store_si128((__m128i*) out, xmm1);
printout();

// xmm2 Initially 1111
__m128i xmm2 = _mm_load_si128((__m128i*) buf1111);
_mm_store_si128((__m128i*) out, xmm2);
printout();

// Result is just each added by 1
asm volatile( "paddq %[vec2], %[vec1]\n\t"
: [vec1] "+x" (xmm1), [vec2] "+x" (xmm2)
:);
_mm_store_si128((__m128i*) out, xmm1);
printout();
}
4 changes: 4 additions & 0 deletions tests/e2e/sse2/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ gcc -msse2 psllq.c -o test_psllq
echo psrlq
gcc -msse2 psrlq.c -o test_psrlq
./test_psrlq

echo paddq
gcc -msse2 paddq.c -o test_paddq
./test_paddq

0 comments on commit 309bcf3

Please sign in to comment.