From dbe028cc17ea402883755d46e1b64abff4769cb7 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Fri, 17 Feb 2017 23:26:57 +0200 Subject: [PATCH] Add AVX2. --- test cases/common/139 simd/meson.build | 1 + test cases/common/139 simd/simd_avx2.c | 27 ++++++++++++++++++++++++ test cases/common/139 simd/simdchecker.c | 6 ++++++ 3 files changed, 34 insertions(+) create mode 100644 test cases/common/139 simd/simd_avx2.c diff --git a/test cases/common/139 simd/meson.build b/test cases/common/139 simd/meson.build index 1d23ffb78..60312186e 100644 --- a/test cases/common/139 simd/meson.build +++ b/test cases/common/139 simd/meson.build @@ -30,6 +30,7 @@ simdarr = [['-mmmx', 'HAVE_MMX', 'simd_mmx', 'simd_mmx.c'], ['-msse4.1', 'HAVE_SSE41', 'simd_sse41', 'simd_sse41.c'], ['-msse4.2', 'HAVE_SSE42', 'simd_sse42', 'simd_sse42.c'], ['-mavx', 'HAVE_AVX', 'simd_avx', 'simd_avx.c'], + ['-mavx2', 'HAVE_AVX2', 'simd_avx2', 'simd_avx2.c'], ] foreach ia : simdarr diff --git a/test cases/common/139 simd/simd_avx2.c b/test cases/common/139 simd/simd_avx2.c new file mode 100644 index 000000000..bca8c99a8 --- /dev/null +++ b/test cases/common/139 simd/simd_avx2.c @@ -0,0 +1,27 @@ +#include +#include + +#include +#include +#include + +int avx2_available() { + return __builtin_cpu_supports("avx2"); +} + +void increment_avx2(float arr[4]) { + double darr[4]; + darr[0] = arr[0]; + darr[1] = arr[1]; + darr[2] = arr[2]; + darr[3] = arr[3]; + __m256d val = _mm256_loadu_pd(darr); + __m256d one = _mm256_set1_pd(1.0); + __m256d result = _mm256_add_pd(val, one); + _mm256_storeu_pd(darr, result); + one = _mm256_permute4x64_pd(one, 66); /* A no-op, just here to use AVX2. */ + arr[0] = (float)darr[0]; + arr[1] = (float)darr[1]; + arr[2] = (float)darr[2]; + arr[3] = (float)darr[3]; +} diff --git a/test cases/common/139 simd/simdchecker.c b/test cases/common/139 simd/simdchecker.c index da53f0ada..1502ae7d1 100644 --- a/test cases/common/139 simd/simdchecker.c +++ b/test cases/common/139 simd/simdchecker.c @@ -17,6 +17,12 @@ int main(int argc, char **argv) { /* Add here. The first matched one is used so put "better" instruction * sets at the top. */ +#if HAVE_AVX2 + if(fptr == NULL && avx2_available()) { + fptr = increment_avx2; + type = "AVX2"; + } +#endif #if HAVE_AVX if(fptr == NULL && avx_available()) { fptr = increment_avx;