diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2018-11-10 21:18:03 +0200 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2018-11-10 21:18:03 +0200 |
commit | 0859442480d4e0f607100a3bd62224156474a6b2 (patch) | |
tree | 2310a943761656ddcbb2cfa9f510ef38a91cf8e9 | |
parent | 621df77049ff9bd264367dc430e6e5fa562ed604 (diff) | |
download | meson-0859442480d4e0f607100a3bd62224156474a6b2.zip meson-0859442480d4e0f607100a3bd62224156474a6b2.tar.gz meson-0859442480d4e0f607100a3bd62224156474a6b2.tar.bz2 |
Refactor check to its own function.
-rw-r--r-- | test cases/common/152 simd/simdchecker.c | 134 | ||||
-rw-r--r-- | test cases/common/152 simd/simdtest.h | 9 |
2 files changed, 90 insertions, 53 deletions
diff --git a/test cases/common/152 simd/simdchecker.c b/test cases/common/152 simd/simdchecker.c index 5e24751..bc7c10a 100644 --- a/test cases/common/152 simd/simdchecker.c +++ b/test cases/common/152 simd/simdchecker.c @@ -3,96 +3,142 @@ #include<stdio.h> #include<string.h> -/* - * A function that checks at runtime which simd accelerations are - * available and calls the best one. Falls - * back to plain C implementation if SIMD is not available. - */ +typedef void (*simd_func)(float*); + +int check_simd_implementation(float *four, + const float *four_initial, + const char *simd_type, + const float *expected, + simd_func fptr, + const int blocksize) { + int rv = 0; + memcpy(four, four_initial, blocksize*sizeof(float)); + printf("Using %s.\n", simd_type); + fptr(four); + for(int i=0; i<blocksize; i++) { + if(four[i] != expected[i]) { + printf("Increment function failed, got %f expected %f.\n", four[i], expected[i]); + rv = 1; + } + } + return rv; +} int main(int argc, char **argv) { static const float four_initial[4] = {2.0, 3.0, 4.0, 5.0}; alignas(16) float four[4]; const float expected[4] = {3.0, 4.0, 5.0, 6.0}; - void (*fptr)(float[4]) = NULL; - const char *type; - int i, r=0; + int r=0; + const int blocksize = 4; -/* Add here. The first matched one is used so put "better" instruction - * sets at the top. +/* + * Test all implementations that the current CPU supports. */ #if HAVE_NEON if(neon_available()) { - fptr = increment_neon; - type = "NEON"; - #include<simdtest.h> + r += check_simd_implementation(four, + four_initial, + "NEON", + expected, + increment_neon, + blocksize); } #endif #if HAVE_AVX2 if(avx2_available()) { - fptr = increment_avx2; - type = "AVX2"; - #include<simdtest.h> + r += check_simd_implementation(four, + four_initial, + "AVX2", + expected, + increment_avx2, + blocksize); } #endif #if HAVE_AVX if(avx_available()) { - fptr = increment_avx; - type = "AVX"; - #include<simdtest.h> + r += check_simd_implementation(four, + four_initial, + "AVC", + expected, + increment_avx, + blocksize); } #endif #if HAVE_SSE42 if(sse42_available()) { - fptr = increment_sse42; - type = "SSE42"; - #include<simdtest.h> + r += check_simd_implementation(four, + four_initial, + "SSR42", + expected, + increment_sse42, + blocksize); } #endif #if HAVE_SSE41 if(sse41_available()) { - fptr = increment_sse41; - type = "SSE41"; - #include<simdtest.h> + r += check_simd_implementation(four, + four_initial, + "SSE41", + expected, + increment_sse41, + blocksize); } #endif #if HAVE_SSSE3 if(ssse3_available()) { - fptr = increment_ssse3; - type = "SSSE3"; - #include<simdtest.h> + r += check_simd_implementation(four, + four_initial, + "SSSE3", + expected, + increment_ssse3, + blocksize); } #endif #if HAVE_SSE3 if(sse3_available()) { - fptr = increment_sse3; - type = "SSE3"; - #include<simdtest.h> + r += check_simd_implementation(four, + four_initial, + "SSE3", + expected, + increment_sse3, + blocksize); } #endif #if HAVE_SSE2 if(sse2_available()) { - fptr = increment_sse2; - type = "SSE2"; - #include<simdtest.h> + r += check_simd_implementation(four, + four_initial, + "SSE2", + expected, + increment_sse2, + blocksize); } #endif #if HAVE_SSE if(sse_available()) { - fptr = increment_sse; - type = "SSE"; - #include<simdtest.h> + r += check_simd_implementation(four, + four_initial, + "SSE", + expected, + increment_sse, + blocksize); } #endif #if HAVE_MMX if(mmx_available()) { - fptr = increment_mmx; - type = "MMX"; - #include<simdtest.h> + r += check_simd_implementation(four, + four_initial, + "MMX", + expected, + increment_mmx, + blocksize); } #endif - fptr = increment_fallback; - type = "fallback"; - #include<simdtest.h> - + r += check_simd_implementation(four, + four_initial, + "fallback", + expected, + increment_fallback, + blocksize); return r; } diff --git a/test cases/common/152 simd/simdtest.h b/test cases/common/152 simd/simdtest.h deleted file mode 100644 index 2bd07e7..0000000 --- a/test cases/common/152 simd/simdtest.h +++ /dev/null @@ -1,9 +0,0 @@ -memcpy(four, four_initial, sizeof(four_initial)); -printf("Using %s.\n", type); -fptr(four); -for(i=0; i<4; i++) { - if(four[i] != expected[i]) { - printf("Increment function failed, got %f expected %f.\n", four[i], expected[i]); - r=1; - } -} |