forked from ish-app/ish
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
movaps, movss, movsd, ucomiss, pxor, xorps
- Loading branch information
1 parent
c0f2ebc
commit d8b08da
Showing
9 changed files
with
285 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,70 @@ | ||
#include <math.h> | ||
|
||
#include "emu/cpu.h" | ||
|
||
void vec_compare32(struct cpu_state *cpu, float *f2, float *f1) { | ||
if (isnan(*f1) || isnan(*f2)) { | ||
cpu->zf = 1; | ||
cpu->pf = 1; | ||
cpu->cf = 1; | ||
} | ||
else if (*f1 > *f2) { | ||
cpu->zf = 0; | ||
cpu->pf = 0; | ||
cpu->cf = 0; | ||
} | ||
else if (*f1 < *f2) { | ||
cpu->zf = 0; | ||
cpu->pf = 0; | ||
cpu->cf = 1; | ||
} | ||
else if (*f1 == *f2) { | ||
cpu->zf = 1; | ||
cpu->pf = 0; | ||
cpu->cf = 0; | ||
} | ||
else { | ||
printf("something's horribly wrong. err 1093281094"); | ||
} | ||
cpu->zf_res = 0; | ||
cpu->pf_res = 0; | ||
} | ||
|
||
void vec_load32(struct cpu_state *UNUSED(cpu), union xmm_reg *src, union xmm_reg *dst) { | ||
dst->dw[0] = src->dw[0]; | ||
} | ||
void vec_load64(struct cpu_state *UNUSED(cpu), union xmm_reg *src, union xmm_reg *dst) { | ||
dst->qw[0] = src->qw[0]; | ||
} | ||
void vec_load128(struct cpu_state *UNUSED(cpu), union xmm_reg *src, union xmm_reg *dst) { | ||
*dst = *src; | ||
} | ||
|
||
static inline void zero_xmm(union xmm_reg *xmm) { | ||
xmm->qw[0] = 0; | ||
xmm->qw[1] = 0; | ||
} | ||
#define ZLOAD(sz) \ | ||
void vec_zload##sz(struct cpu_state *cpu, union xmm_reg *src, union xmm_reg *dst) { \ | ||
zero_xmm(dst); \ | ||
vec_load##sz(cpu, src, dst); \ | ||
} | ||
ZLOAD(32) | ||
ZLOAD(64) | ||
ZLOAD(128) | ||
#undef ZLOAD | ||
|
||
void vec_store32(struct cpu_state *UNUSED(cpu), union xmm_reg *dst, union xmm_reg *src) { | ||
dst->dw[0] = src->dw[0]; | ||
} | ||
void vec_store64(struct cpu_state *UNUSED(cpu), union xmm_reg *dst, union xmm_reg *src) { | ||
dst->qw[0] = src->qw[0]; | ||
} | ||
void vec_store128(struct cpu_state *UNUSED(cpu), union xmm_reg *dst, union xmm_reg *src) { | ||
*dst = *src; | ||
} | ||
|
||
void vec_xor128(struct cpu_state *UNUSED(cpu), union xmm_reg *src, union xmm_reg *dst) { | ||
dst->qw[0] ^= src->qw[0]; | ||
dst->qw[1] ^= src->qw[1]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
movaps | ||
11.11 22.22 33.33 44.44 | ||
55.55 66.66 77.77 88.88 | ||
55.55 66.66 77.77 88.88 | ||
movss | ||
11.11 22.22 33.33 44.44 | ||
55.55 66.66 77.77 88.88 | ||
55.55 22.22 33.33 44.44 | ||
16.12 00.00 00.00 00.00 | ||
16.12 | ||
xorps | ||
0.00E+00 0.00E+00 0.00E+00 0.00E+00 | ||
1.11E+01 2.22E+01 3.33E+01 4.44E+01 | ||
5.55E+01 6.67E+01 7.78E+01 8.89E+01 | ||
1.11E+01 2.22E+01 3.33E+01 4.44E+01 | ||
0.00E+00 0.00E+00 0.00E+00 0.00E+00 | ||
7.05E-37 5.31E-37 1.46E-38 1.18E-38 | ||
1.11E+01 2.22E+01 3.33E+01 4.44E+01 | ||
0.00E+00 0.00E+00 0.00E+00 0.00E+00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <stdio.h> | ||
#include <xmmintrin.h> | ||
|
||
#define printout() printf("%05.2f %05.2f %05.2f %05.2f\n", out[0], out[1], out[2], out[3]) | ||
|
||
void main(void) { | ||
float out[4] = { 0, 0, 0, 0 }; | ||
float buf1234[4] = { 11.11, 22.22, 33.33, 44.44 }; | ||
float buf5678[4] = { 55.55, 66.66, 77.77, 88.88 }; | ||
float fa = 16.12; | ||
|
||
// xmm1 Initially 1234 | ||
__m128 xmm1 = _mm_load_ps((float*) buf1234); | ||
_mm_store_ps((float*) out, xmm1); | ||
printout(); | ||
|
||
// xmm2 Initially 5678 | ||
__m128 xmm2 = _mm_load_ps((float*) buf5678); | ||
_mm_store_ps((float*) out, xmm2); | ||
printout(); | ||
|
||
// Move xmm2 onto xmm1 | ||
asm volatile( "movaps %[vec2], %[vec1]\n\t" | ||
: [vec1] "+x" (xmm1) | ||
: [vec2] "x" (xmm2)); | ||
|
||
_mm_store_ps((float*) out, xmm1); | ||
printout(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include <stdio.h> | ||
#include <xmmintrin.h> | ||
|
||
#define NOINLINE __attribute__ ((noinline)) | ||
#define printout() printf("%05.2f %05.2f %05.2f %05.2f\n", out[0], out[1], out[2], out[3]) | ||
|
||
void move5(__m128 *xmm1, __m128 *xmm2); | ||
void move1612(__m128 *xmm1, float fa); | ||
void store1612(__m128 *xmm1, float *fa); | ||
|
||
void main(void) { | ||
float out[4] = { 0, 0, 0, 0 }; | ||
float buf1234[4] = { 11.11, 22.22, 33.33, 44.44 }; | ||
float buf5678[4] = { 55.55, 66.66, 77.77, 88.88 }; | ||
float fa = 16.12; | ||
|
||
// xmm1 Initially 1234 | ||
__m128 xmm1 = _mm_load_ps((float*) buf1234); | ||
_mm_store_ps((float*) out, xmm1); | ||
printout(); | ||
|
||
// xmm2 Initially 5678 | ||
__m128 xmm2 = _mm_load_ps((float*) buf5678); | ||
_mm_store_ps((float*) out, xmm2); | ||
printout(); | ||
|
||
//move5(&xmm1, &xmm2); | ||
__m128 xmm3 = _mm_move_ss(xmm1, xmm2); | ||
_mm_store_ps((float*) out, xmm3); | ||
printout(); | ||
|
||
move1612(&xmm1, fa); | ||
_mm_store_ps((float*) out, xmm1); | ||
printout(); | ||
|
||
fa = 00.00; | ||
store1612(&xmm1, &fa); | ||
printf("%05.2f\n", fa); | ||
} | ||
|
||
void NOINLINE move5(__m128 *xmm1, __m128 *xmm2) { | ||
// Move the 5 from 5678, rest should remain: 5234. | ||
//*xmm1 = _mm_move_ss(*xmm1, *xmm2); | ||
asm volatile( "movss %[vec2], %[vec1]\n\t" | ||
: [vec1] "+x" (*xmm1) | ||
: [vec2] "x" (*xmm2)); | ||
} | ||
|
||
void NOINLINE move1612(__m128 *xmm1, float fa) { | ||
// Move the 16.12 into first position of xmm1. | ||
// This is mem, so rest should be zeroed. | ||
asm volatile( "movss %[flt], %[vec]\n\t" | ||
: [vec] "+x" (*xmm1) | ||
: [flt] "m" (fa)); | ||
} | ||
|
||
void NOINLINE store1612(__m128 *xmm1, float *fa) { | ||
// Store the 16.12 into float. | ||
asm volatile( "movss %[vec], %[flt]\n\t" | ||
: [flt] "+m" (*fa) | ||
: [vec] "x" (*xmm1)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
gcc -msse2 movaps.c -o test_movaps | ||
echo movaps | ||
./test_movaps | ||
|
||
echo movss | ||
gcc -msse2 movss.c -o test_movss | ||
./test_movss | ||
|
||
echo xorps | ||
gcc -msse2 xorps.c -o test_xorps | ||
./test_xorps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include <stdio.h> | ||
#include <xmmintrin.h> | ||
|
||
#define printout() printf("%05.2E %05.2E %05.2E %05.2E\n", out[0], out[1], out[2], out[3]) | ||
|
||
void main(void) { | ||
float out[4] = { 0, 0, 0, 0 }; | ||
float buf0000[4] = { 00.00, 00.00, 00.00, 00.00 }; | ||
float buf1234[4] = { 11.11, 22.22, 33.33, 44.44 }; | ||
float buf5678[4] = { 55.55, 66.66, 77.77, 88.88 }; | ||
|
||
// xmm0 Initially 1234 | ||
__m128 xmm0 = _mm_load_ps((float*) buf0000); | ||
_mm_store_ps((float*) out, xmm0); | ||
printout(); | ||
|
||
// xmm1 Initially 1234 | ||
__m128 xmm1 = _mm_load_ps((float*) buf1234); | ||
_mm_store_ps((float*) out, xmm1); | ||
printout(); | ||
|
||
// xmm2 Initially 5678 | ||
__m128 xmm2 = _mm_load_ps((float*) buf5678); | ||
_mm_store_ps((float*) out, xmm2); | ||
printout(); | ||
|
||
// 0000 ^ 1234 = 1234 | ||
_mm_store_ps((float*) out, _mm_xor_ps(xmm0, xmm1)); | ||
printout(); | ||
|
||
// 1234 ^ 1234 = 0000 | ||
_mm_store_ps((float*) out, _mm_xor_ps(xmm1, xmm1)); | ||
printout(); | ||
|
||
// 1234 ^ 5678 = some known value | ||
_mm_store_ps((float*) out, _mm_xor_ps(xmm1, xmm2)); | ||
printout(); | ||
|
||
// 5678 ^ (1234 ^ 5678) = 1234 | ||
_mm_store_ps((float*) out, _mm_xor_ps(xmm2, _mm_xor_ps(xmm1, xmm2))); | ||
printout(); | ||
|
||
// setzero with xorps = 0000 | ||
_mm_store_ps((float*) out, _mm_setzero_ps()); | ||
printout(); | ||
} |