aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorVasilis Kalintiris <ehostunreach@gmail.com>2013-12-07 17:18:43 +0200
committerVasilis Kalintiris <ehostunreach@gmail.com>2013-12-07 19:36:02 +0200
commit37cfd33068ad6ae43fc644a6f620856d63ba68b7 (patch)
treec89ea5b0e9b3641cd50fbc275f0d1defbc84e7df /tests
parent179da486f99c85cb0d3d159d5eedf96f60cc6dcb (diff)
Use do_run_from_file() for test_simd
Diffstat (limited to 'tests')
-rw-r--r--tests/core/test_simd.in61
-rw-r--r--tests/core/test_simd.out8
-rw-r--r--tests/test_core.py72
3 files changed, 72 insertions, 69 deletions
diff --git a/tests/core/test_simd.in b/tests/core/test_simd.in
new file mode 100644
index 00000000..978ea96a
--- /dev/null
+++ b/tests/core/test_simd.in
@@ -0,0 +1,61 @@
+
+#include <stdio.h>
+
+#include <emscripten/vector.h>
+
+static inline float32x4 __attribute__((always_inline))
+_mm_set_ps(const float __Z, const float __Y, const float __X, const float __W)
+{
+ return (float32x4){ __W, __X, __Y, __Z };
+}
+
+static __inline__ float32x4 __attribute__((__always_inline__))
+_mm_setzero_ps(void)
+{
+ return (float32x4){ 0.0, 0.0, 0.0, 0.0 };
+}
+
+int main(int argc, char **argv) {
+ float data[8];
+ for (int i = 0; i < 32; i++) data[i] = (1+i+argc)*(2+i+argc*argc); // confuse optimizer
+ {
+ float32x4 *a = (float32x4*)&data[0];
+ float32x4 *b = (float32x4*)&data[4];
+ float32x4 c, d;
+ c = *a;
+ d = *b;
+ printf("1floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
+ c = c+d;
+ printf("2floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
+ d = c*d;
+ printf("3floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
+ c = _mm_setzero_ps();
+ printf("zeros %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3]);
+ }
+ {
+ int32x4 *a = (int32x4*)&data[0];
+ int32x4 *b = (int32x4*)&data[4];
+ int32x4 c, d, e, f;
+ c = *a;
+ d = *b;
+ printf("4ints! %d, %d, %d, %d %d, %d, %d, %d\n", c[0], c[1], c[2], c[3], d[0], d[1], d[2], d[3]);
+ e = c+d;
+ f = c-d;
+ printf("5ints! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], f[0], f[1], f[2], f[3]);
+ e = c&d;
+ f = c|d;
+ e = ~c&d;
+ f = c^d;
+ printf("5intops! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], f[0], f[1], f[2], f[3]);
+ }
+ {
+ float32x4 c, d, e, f;
+ c = _mm_set_ps(9.0, 4.0, 0, -9.0);
+ d = _mm_set_ps(10.0, 14.0, -12, -2.0);
+ printf("6floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
+ printf("7calcs: %d\n", emscripten_float32x4_signmask(c)); // TODO: just not just compilation but output as well
+ }
+
+ return 0;
+}
+ \ No newline at end of file
diff --git a/tests/core/test_simd.out b/tests/core/test_simd.out
new file mode 100644
index 00000000..08ca3738
--- /dev/null
+++ b/tests/core/test_simd.out
@@ -0,0 +1,8 @@
+1floats! 6, 12, 20, 30 42, 56, 72, 90
+2floats! 48, 68, 92, 120 42, 56, 72, 90
+3floats! 48, 68, 92, 120 2016, 3808, 6624, 10800
+zeros 0, 0, 0, 0
+4ints! 1086324736, 1094713344, 1101004800, 1106247680 1109917696, 1113587712, 1116733440, 1119092736
+5ints! -2098724864, -2086666240, -2077229056, -2069626880 -23592960, -18874368, -15728640, -12845056
+5intops! 36175872, 35651584, 34603008, 33816576 48758784, 52428800, 53477376, 54788096
+6floats! -9, 0, 4, 9 -2, -12, 14, 10
diff --git a/tests/test_core.py b/tests/test_core.py
index 242494b6..787a240d 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -4548,77 +4548,11 @@ return malloc(size);
def test_simd(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('needs ta2')
if Settings.ASM_JS: Settings.ASM_JS = 2 # does not validate
- src = r'''
-#include <stdio.h>
-
-#include <emscripten/vector.h>
-static inline float32x4 __attribute__((always_inline))
-_mm_set_ps(const float __Z, const float __Y, const float __X, const float __W)
-{
- return (float32x4){ __W, __X, __Y, __Z };
-}
-
-static __inline__ float32x4 __attribute__((__always_inline__))
-_mm_setzero_ps(void)
-{
- return (float32x4){ 0.0, 0.0, 0.0, 0.0 };
-}
-
-int main(int argc, char **argv) {
- float data[8];
- for (int i = 0; i < 32; i++) data[i] = (1+i+argc)*(2+i+argc*argc); // confuse optimizer
- {
- float32x4 *a = (float32x4*)&data[0];
- float32x4 *b = (float32x4*)&data[4];
- float32x4 c, d;
- c = *a;
- d = *b;
- printf("1floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
- c = c+d;
- printf("2floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
- d = c*d;
- printf("3floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
- c = _mm_setzero_ps();
- printf("zeros %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3]);
- }
- {
- int32x4 *a = (int32x4*)&data[0];
- int32x4 *b = (int32x4*)&data[4];
- int32x4 c, d, e, f;
- c = *a;
- d = *b;
- printf("4ints! %d, %d, %d, %d %d, %d, %d, %d\n", c[0], c[1], c[2], c[3], d[0], d[1], d[2], d[3]);
- e = c+d;
- f = c-d;
- printf("5ints! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], f[0], f[1], f[2], f[3]);
- e = c&d;
- f = c|d;
- e = ~c&d;
- f = c^d;
- printf("5intops! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], f[0], f[1], f[2], f[3]);
- }
- {
- float32x4 c, d, e, f;
- c = _mm_set_ps(9.0, 4.0, 0, -9.0);
- d = _mm_set_ps(10.0, 14.0, -12, -2.0);
- printf("6floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
- printf("7calcs: %d\n", emscripten_float32x4_signmask(c)); // TODO: just not just compilation but output as well
- }
-
- return 0;
-}
- '''
+ test_path = path_from_root('tests', 'core', 'test_simd')
+ src, output = (test_path + s for s in ('.in', '.out'))
- self.do_run(src, '''1floats! 6, 12, 20, 30 42, 56, 72, 90
-2floats! 48, 68, 92, 120 42, 56, 72, 90
-3floats! 48, 68, 92, 120 2016, 3808, 6624, 10800
-zeros 0, 0, 0, 0
-4ints! 1086324736, 1094713344, 1101004800, 1106247680 1109917696, 1113587712, 1116733440, 1119092736
-5ints! -2098724864, -2086666240, -2077229056, -2069626880 -23592960, -18874368, -15728640, -12845056
-5intops! 36175872, 35651584, 34603008, 33816576 48758784, 52428800, 53477376, 54788096
-6floats! -9, 0, 4, 9 -2, -12, 14, 10
-''')
+ self.do_run_from_file(src, output)
def test_simd2(self):
if Settings.ASM_JS: Settings.ASM_JS = 2 # does not validate