Debian Codegraph @

libgomp/testsuite/libgomp.c-target/aarch64/firstprivate.c

raw
1 /* { dg-do run { target aarch64_sve256_hw } } */
2 /* { dg-options "-msve-vector-bits=256 -fopenmp -O2" } */
3
4 #pragma GCC target "+sve"
5
6 #include <arm_sve.h>
7 #include <omp.h>
8
9 static void __attribute__ ((noipa))
10 vec_compare (svint32_t *x, svint32_t y)
11 {
12 svbool_t p = svnot_b_z (svptrue_b32 (), svcmpeq_s32 (svptrue_b32 (), *x, y));
13
14 if (svptest_any (svptrue_b32 (), p))
15 __builtin_abort ();
16 }
17
18 void __attribute__ ((noipa))
19 firstprivate_sections ()
20 {
21 int b[8], c[8];
22 svint32_t vb, vc;
23 int i;
24
25 #pragma omp parallel for
26 for (i = 0; i < 8; i++)
27 {
28 b[i] = i;
29 c[i] = i + 1;
30 }
31
32 vb = svld1_s32 (svptrue_b32 (), b);
33 vc = svld1_s32 (svptrue_b32 (), c);
34
35 #pragma omp parallel sections firstprivate (vb, vc)
36 {
37 #pragma omp section
38 vec_compare (&vb, svindex_s32 (0, 1));
39 vec_compare (&vc, svindex_s32 (1, 1));
40
41 #pragma omp section
42 vec_compare (&vb, svindex_s32 (0, 1));
43 vec_compare (&vc, svindex_s32 (1, 1));
44 }
45
46 }
47
48 void __attribute__ ((noipa))
49 firstprivate_for ()
50 {
51
52 int a[32], b[32], c[32];
53 svint32_t va, vb, vc;
54 int i;
55
56 #pragma omp parallel for
57 for (i = 0; i < 32; i++)
58 {
59 b[i] = i;
60 c[i] = i + 1;
61 }
62
63 vb = svindex_s32 (1, 0);
64 vc = svindex_s32 (0, 1);
65
66 #pragma omp parallel for firstprivate (vb, vc) private (va)
67 for (i = 0; i < 4; i++)
68 {
69 svint32_t tb, tc;
70 vec_compare (&vb, svindex_s32 (1, 0));
71 vec_compare (&vc, svindex_s32 (0, 1));
72 tb = svld1_s32 (svptrue_b32 (), b + i * 8);
73 tc = svld1_s32 (svptrue_b32 (), c + i * 8);
74 va = svadd_s32_z (svptrue_b32 (), vb, vc);
75 va = svadd_s32_z (svptrue_b32 (), va, tb);
76 va = svadd_s32_z (svptrue_b32 (), va, tc);
77 svst1_s32 (svptrue_b32 (), a + i * 8, va);
78 }
79
80 for (i = 0; i < 32; i++)
81 if (a[i] != b[i] + c[i] + vb[i % 8] + vc[i % 8])
82 __builtin_abort ();
83 }
84
85 void __attribute__ ((noipa))
86 firstprivate_distribute ()
87 {
88
89 int a[32], b[32], c[32];
90 svint32_t va, vb, vc;
91 int i;
92
93 #pragma omp parallel for
94 for (i = 0; i < 32; i++)
95 {
96 b[i] = i;
97 c[i] = i + 1;
98 }
99
100 vb = svindex_s32 (1, 0);
101 vc = svindex_s32 (0, 1);
102
103 #pragma omp teams
104 #pragma omp distribute firstprivate (vb, vc) private (va)
105 for (i = 0; i < 4; i++)
106 {
107 svint32_t tb, tc;
108 vec_compare (&vb, svindex_s32 (1, 0));
109 vec_compare (&vc, svindex_s32 (0, 1));
110 tb = svld1_s32 (svptrue_b32 (), b + i * 8);
111 tc = svld1_s32 (svptrue_b32 (), c + i * 8);
112 va = svadd_s32_z (svptrue_b32 (), vb, vc);
113 va = svadd_s32_z (svptrue_b32 (), va, tb);
114 va = svadd_s32_z (svptrue_b32 (), va, tc);
115 svst1_s32 (svptrue_b32 (), a + i * 8, va);
116 }
117
118 for (i = 0; i < 32; i++)
119 if (a[i] != b[i] + c[i] + vb[i % 8] + vc[i % 8])
120 __builtin_abort ();
121 }
122
123 int
124 main ()
125 {
126 firstprivate_for ();
127 firstprivate_sections ();
128 firstprivate_distribute ();
129 }