Debian Codegraph @

libgomp/testsuite/libgomp.c++/simd-5.C

raw
1 // { dg-do run }
2 // { dg-additional-options "-msse2" { target sse2_runtime } }
3 // { dg-additional-options "-mavx" { target avx_runtime } }
4
5 extern "C" void abort ();
6 int a[1024] __attribute__((aligned (32))) = { 1 };
7 struct S
8 {
9 int s;
10 S () : s (0) {}
11 ~S () {}
12 };
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)
16
17 __attribute__((noinline, noclone)) int
18 foo ()
19 {
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;
35 }
36
37 int
38 main ()
39 {
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 ();
46 }