aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2017-02-09 21:41:02 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2017-07-17 19:00:42 +0300
commitfd91749e5a4feb45eafa91a0fd76685a104ad5e0 (patch)
tree452d7a596df64783cd9c0626f6bb8e7c81ba262f
parent2009fdbd434279f0feddccc610067dedb7a26133 (diff)
downloadmeson-fd91749e5a4feb45eafa91a0fd76685a104ad5e0.zip
meson-fd91749e5a4feb45eafa91a0fd76685a104ad5e0.tar.gz
meson-fd91749e5a4feb45eafa91a0fd76685a104ad5e0.tar.bz2
The beginning of a test that checks for various SIMD implementations.
-rw-r--r--test cases/common/139 simd/fallback.c7
-rw-r--r--test cases/common/139 simd/meson.build13
-rw-r--r--test cases/common/139 simd/simdchecker.c31
-rw-r--r--test cases/common/139 simd/simdfuncs.h15
4 files changed, 66 insertions, 0 deletions
diff --git a/test cases/common/139 simd/fallback.c b/test cases/common/139 simd/fallback.c
new file mode 100644
index 0000000..2b98304
--- /dev/null
+++ b/test cases/common/139 simd/fallback.c
@@ -0,0 +1,7 @@
+#include<simdfuncs.h>
+
+void increment_fallback(float arr[4]) {
+ for(int i=0; i<4; i++) {
+ arr[i]++;
+ }
+}
diff --git a/test cases/common/139 simd/meson.build b/test cases/common/139 simd/meson.build
new file mode 100644
index 0000000..b26d007
--- /dev/null
+++ b/test cases/common/139 simd/meson.build
@@ -0,0 +1,13 @@
+project('simd', 'c')
+
+cdata = configuration_data()
+
+#cdata.set('HAVE_MMX', 1)
+
+configure_file(output : 'simdconfig.h',
+ configuration : cdata)
+
+p = executable('simdtest', 'simdchecker.c', 'fallback.c')
+
+test('simdtest', p)
+
diff --git a/test cases/common/139 simd/simdchecker.c b/test cases/common/139 simd/simdchecker.c
new file mode 100644
index 0000000..bcc6cef
--- /dev/null
+++ b/test cases/common/139 simd/simdchecker.c
@@ -0,0 +1,31 @@
+#include<simdfuncs.h>
+#include<stdio.h>
+
+/*
+ * A function that checks at runtime if simd acceleration is
+ * available and calls the respective function if it is. Falls
+ * back to plain C implementation if not.
+ */
+
+int main(int argc, char **argv) {
+ float four[4] = {2.0, 3.0, 4.0, 5.0};
+ const float expected[4] = {3.0, 4.0, 5.0, 6.0};
+ void (*fptr)(float[4]) = NULL;
+
+#if HAVE_MMX
+ if(mmx_available()) {
+ fptr = increment_mmx;
+ }
+#endif
+ if(fptr == NULL) {
+ fptr = increment_fallback;
+ }
+ fptr(four);
+ for(int i=0; i<4; i++) {
+ if(four[i] != expected[i]) {
+ printf("Increment function failed.\n");
+ return 1;
+ }
+ }
+ return 0;
+}
diff --git a/test cases/common/139 simd/simdfuncs.h b/test cases/common/139 simd/simdfuncs.h
new file mode 100644
index 0000000..17c627e
--- /dev/null
+++ b/test cases/common/139 simd/simdfuncs.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#include<simdconfig.h>
+
+/* Yes, I do know that arr[4] decays into a pointer
+ * here. Don't do this in real code but for test code
+ * it is ok.
+ */
+
+void increment_fallback(float arr[4]);
+
+#if HAVE_MMX
+void increment_mmx(float arr[4]);
+#endif
+