diff options
Diffstat (limited to 'libgomp/testsuite/libgomp.c/examples-4/simd-4.c')
-rw-r--r-- | libgomp/testsuite/libgomp.c/examples-4/simd-4.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/libgomp/testsuite/libgomp.c/examples-4/simd-4.c b/libgomp/testsuite/libgomp.c/examples-4/simd-4.c new file mode 100644 index 00000000000..1aa0425010d --- /dev/null +++ b/libgomp/testsuite/libgomp.c/examples-4/simd-4.c @@ -0,0 +1,58 @@ +/* { dg-do run } */ +/* { dg-additional-options "-msse2" { target sse2_runtime } } */ +/* { dg-additional-options "-mavx" { target avx_runtime } } */ + +#define N 128 +#define M 16 +#define EPS 0.0000000000000001 +#define SAFELEN 16 + +#include <stdlib.h> + +void init(double *a, double *b, int n) +{ + int i, s = -1; + for ( i = 0; i < n; i++ ) + { + a[i] = i*i*s; + b[i] = a[i]; + s = -s; + } +} + +void work( double *b, int n, int m ) +{ + int i; + #pragma omp simd safelen(SAFELEN) + for (i = m; i < n; i++) + b[i] = b[i-m] - 1.0f; +} + +void work_ref( double *b, int n, int m ) +{ + int i; + for (i = m; i < n; i++) + b[i] = b[i-m] - 1.0f; +} + +void check (double *a, double *b) +{ + int i; + for (i = 0; i < N; i++) + if (a[i] - b[i] > EPS || b[i] - a[i] > EPS) + abort (); +} + +int main () +{ + double b[N], b_ref[N]; + + init(b, b_ref, N); + + work(b, N, M); + work(b_ref, N, M); + + check(b, b_ref); + + return 0; +} |