1 /* { dg-do run { target vect_simd_clones } } */
2 /* { dg-additional-options "-msse2" { target sse2_runtime } } */
3 /* { dg-additional-options "-mavx" { target avx_runtime } } */
4 
5 #define N 100
6 #define EPS 0.0000000000000001
7 
8 #include <stdlib.h>
9 
init(double * a,double * a_ref,double * b,int n)10 void init(double *a, double *a_ref, double *b, int n)
11 {
12    int i;
13    for ( i=0; i<N; i++ )
14    {
15       a[i] = i;
16       a_ref[i] = i;
17       b[i] = N-i;
18    }
19 }
20 
21 #pragma omp declare simd uniform(fact)
add1(double a,double b,double fact)22 double add1(double a, double b, double fact)
23 {
24    double c;
25    c = a + b + fact;
26    return c;
27 }
28 
29 #pragma omp declare simd uniform(a,b,fact) linear(i:1)
add2(double * a,double * b,int i,double fact)30 double add2(double *a, double *b, int i, double fact)
31 {
32    double c;
33    c = a[i] + b[i] + fact;
34    return c;
35 }
36 
37 #pragma omp declare simd uniform(fact) linear(a,b:1)
add3(double * a,double * b,double fact)38 double add3(double *a, double *b, double fact)
39 {
40    double c;
41    c = *a + *b + fact;
42    return c;
43 }
44 
work(double * a,double * b,int n)45 void work( double *a, double *b, int n )
46 {
47    int i;
48    double tmp;
49    #pragma omp simd private(tmp)
50    for ( i = 0; i < n; i++ ) {
51       tmp  = add1( a[i],  b[i], 1.0);
52       a[i] = add2( a,     b, i, 1.0) + tmp;
53       a[i] = add3(&a[i], &b[i], 1.0);
54    }
55 }
56 
work_ref(double * a,double * b,int n)57 void work_ref( double *a, double *b, int n )
58 {
59    int i;
60    double tmp;
61    for ( i = 0; i < n; i++ ) {
62       tmp  = add1( a[i],  b[i], 1.0);
63       a[i] = add2( a,     b, i, 1.0) + tmp;
64       a[i] = add3(&a[i], &b[i], 1.0);
65    }
66 }
67 
check(double * a,double * b)68 void check (double *a, double *b)
69 {
70   int i;
71   for (i = 0; i < N; i++)
72     if (a[i] - b[i] > EPS || b[i] - a[i] > EPS)
73       abort ();
74 }
75 
76 
main()77 int main ()
78 {
79    int i;
80    double a[N], a_ref[N], b[N];
81 
82    init(a, a_ref, b, N);
83 
84    work(a, b, N );
85    work_ref(a_ref, b, N );
86 
87    check(a, a_ref);
88 
89    return 0;
90 }
91