aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNingxin Hu <ningxin.hu@intel.com>2014-06-04 08:57:00 +0800
committerNingxin Hu <ningxin.hu@intel.com>2014-06-04 08:57:43 +0800
commit9bce5fec791ed44199a2873ffdef67a94e392462 (patch)
tree6e6bb371dd433f854bb387735baa92b4171c56b6
parent3b6cd16ed015e90fa54127a903343e7bf65c86ce (diff)
Add test case for phi node handling in SIMD path
-rw-r--r--tests/core/test_simd4.in39
-rw-r--r--tests/core/test_simd4.out1
-rw-r--r--tests/test_core.py9
3 files changed, 49 insertions, 0 deletions
diff --git a/tests/core/test_simd4.in b/tests/core/test_simd4.in
new file mode 100644
index 00000000..b597d8a3
--- /dev/null
+++ b/tests/core/test_simd4.in
@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include <xmmintrin.h>
+
+static __inline__ __m128 __attribute__((__always_inline__))
+_mm_load_ps(const float *__p)
+{
+ return *(__m128*)__p;
+}
+
+float simdAverage(float *src, int len) {
+ __m128 sumx4 = _mm_setzero_ps();
+ for (int i = 0; i < len; i += 4) {
+ __m128 v = _mm_load_ps(src);
+ sumx4 = _mm_add_ps(sumx4, v);
+ src += 4;
+ }
+ float sumx4_mem[4];
+ float *sumx4_ptr = sumx4_mem;
+ _mm_store_ps(sumx4_ptr, sumx4);
+ return (sumx4_mem[0] + sumx4_mem[1] +
+ sumx4_mem[2] + sumx4_mem[3])/len;
+}
+
+void initArray(float *src, int len) {
+ for (int i = 0; i < len; ++i) {
+ src[i] = 0.1 * i;
+ }
+}
+
+int main() {
+ const int len = 100000;
+ float src[len];
+ float result = 0.0;
+
+ initArray(src, len);
+
+ result = simdAverage(src, len);
+ printf("averagex4 result: %.1f\n", result);
+} \ No newline at end of file
diff --git a/tests/core/test_simd4.out b/tests/core/test_simd4.out
new file mode 100644
index 00000000..99449772
--- /dev/null
+++ b/tests/core/test_simd4.out
@@ -0,0 +1 @@
+averagex4 result: 4999.9 \ No newline at end of file
diff --git a/tests/test_core.py b/tests/test_core.py
index bcb03830..b9057f4e 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -4892,6 +4892,15 @@ return malloc(size);
self.do_run_from_file(src, output)
+ def test_simd4(self):
+ # test_simd4 is to test phi node handling of SIMD path
+ if Settings.ASM_JS: Settings.ASM_JS = 2 # does not validate
+
+ test_path = path_from_root('tests', 'core', 'test_simd4')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
+
def test_gcc_unmangler(self):
if os.environ.get('EMCC_FAST_COMPILER') == '0': Settings.NAMED_GLOBALS = 1 # test coverage for this; fastcomp never names globals