diff options
-rw-r--r-- | test cases/common/139 simd/fallback.c | 7 | ||||
-rw-r--r-- | test cases/common/139 simd/meson.build | 13 | ||||
-rw-r--r-- | test cases/common/139 simd/simdchecker.c | 31 | ||||
-rw-r--r-- | test cases/common/139 simd/simdfuncs.h | 15 |
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 + |