Debian Codegraph @

libgomp/testsuite/libgomp.c/examples-4/simd-1.c

raw
1 /* { dg-do run } */
2 /* { dg-additional-options "-msse2" { target sse2_runtime } } */
3 /* { dg-additional-options "-mavx" { target avx_runtime } } */
4
5 #define N 100
6 #define OFF 32
7 #define EPS 0.0000000000000001
8
9 #include <stdlib.h>
10
11 void init(double *a, double *a_ref, double *b, double *c, int n, int ioff)
12 {
13 int i;
14 for ( i = 0; i < n; i++ )
15 {
16 a[i] = i*i;
17 a_ref[i] = a[i];
18 b[i] = i+i;
19 }
20
21 int s = -1;
22 for ( i = 0; i < n+ioff; i++ )
23 {
24 c[i] = s*3;
25 s = -s;
26 }
27 }
28
29 void star( double *a, double *b, double *c, int n, int *ioff )
30 {
31 int i;
32 #pragma omp simd
33 for ( i = 0; i < n; i++ )
34 a[i] *= b[i] * c[i+ *ioff];
35 }
36
37 void star_ref( double *a, double *b, double *c, int n, int *ioff )
38 {
39 int i;
40 for ( i = 0; i < n; i++ )
41 a[i] *= b[i] * c[i+ *ioff];
42 }
43
44 void check (double *a, double *b)
45 {
46 int i;
47 for (i = 0; i < N; i++)
48 if (a[i] - b[i] > EPS || b[i] - a[i] > EPS)
49 abort ();
50 }
51
52 int main ()
53 {
54 double a[N], a_ref[N], b[N], c[N+OFF];
55 int ioff = OFF;
56
57 init(a, a_ref, b, c, N, ioff);
58
59 star(a, b, c, N, &ioff);
60 star_ref(a_ref, b, c, N, &ioff);
61
62 check(a, a_ref);
63
64 return 0;
65 }