2016-01-14 Edward Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / libgomp / testsuite / libgomp.c++ / simd-4.C
blobb81f230b25db0fea93121833ec1a6ffa5a673301
1 // { dg-do run }
2 // { dg-additional-options "-msse2" { target sse2_runtime } }
3 // { dg-additional-options "-mavx" { target avx_runtime } }
5 extern "C" void abort ();
6 int a[1024] __attribute__((aligned (32))) = { 1 };
7 struct S
9   int s;
10   S () : s (0) {}
11   ~S () {}
13 #pragma omp declare reduction (+:S:omp_out.s += omp_in.s)
14 #pragma omp declare reduction (foo:S:omp_out.s += omp_in.s)
15 #pragma omp declare reduction (foo:int:omp_out += omp_in)
17 __attribute__((noinline, noclone)) int
18 foo ()
20   int i, u = 0;
21   S s, t;
22   #pragma omp simd aligned(a : 32) reduction(+:s) reduction(foo:t, u)
23   for (i = 0; i < 1024; i++)
24     {
25       int x = a[i];
26       s.s += x;
27       t.s += x;
28       u += x;
29     }
30   if (t.s != s.s || u != s.s)
31     abort ();
32   return s.s;
35 int
36 main ()
38   int i;
39   for (i = 0; i < 1024; i++)
40     a[i] = (i & 31) + (i / 128);
41   int s = foo ();
42   if (s != 19456)
43     abort ();