2018-01-22 Sebastian Perta <sebastian.perta@renesas.com>
[official-gcc.git] / libgomp / testsuite / libgomp.c++ / simd-5.C
blobe7cea84548c45e486d2aaf46972f62e19f16ee02
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, q = 0;
21   S s, t;
22   #pragma omp simd aligned(a : 32) reduction(+:s, q) reduction(foo:t, u) \
23               safelen(1)
24   for (i = 0; i < 1024; i++)
25     {
26       int x = a[i];
27       s.s += x;
28       t.s += x;
29       u += x;
30       q++;
31     }
32   if (t.s != s.s || u != s.s || q != 1024)
33     abort ();
34   return s.s;
37 int
38 main ()
40   int i;
41   for (i = 0; i < 1024; i++)
42     a[i] = (i & 31) + (i / 128);
43   int s = foo ();
44   if (s != 19456)
45     abort ();