| 1 |
template <typename T> |
| 2 |
struct A |
| 3 |
{ |
| 4 |
A () { t = 0; } |
| 5 |
A (T x) { t = x; } |
| 6 |
A (const A &x) { t = x.t; } |
| 7 |
~A () {} |
| 8 |
T t; |
| 9 |
}; |
| 10 |
template <typename T> |
| 11 |
struct M |
| 12 |
{ |
| 13 |
M () { t = 1; } |
| 14 |
M (T x) { t = x; } |
| 15 |
M (const M &x) { t = x.t; } |
| 16 |
~M () {} |
| 17 |
T t; |
| 18 |
}; |
| 19 |
template <typename T> |
| 20 |
struct B |
| 21 |
{ |
| 22 |
B () { t = ~(T) 0; } |
| 23 |
B (T x) { t = x; } |
| 24 |
B (const B &x) { t = x.t; } |
| 25 |
~B () {} |
| 26 |
T t; |
| 27 |
}; |
| 28 |
template <typename T> |
| 29 |
void |
| 30 |
add (T &x, T &y) |
| 31 |
{ |
| 32 |
x.t += y.t; |
| 33 |
} |
| 34 |
template <typename T> |
| 35 |
void |
| 36 |
zero (T &x) |
| 37 |
{ |
| 38 |
x.t = 0; |
| 39 |
} |
| 40 |
template <typename T> |
| 41 |
void |
| 42 |
orit (T *x, T *y) |
| 43 |
{ |
| 44 |
y->t |= x->t; |
| 45 |
} |
| 46 |
B<long> bb; |
| 47 |
#pragma omp declare reduction(+:A<int>:omp_out.t += omp_in.t) |
| 48 |
#pragma omp declare reduction(+:A<char>:add (omp_out, omp_in)) initializer(zero (omp_priv)) |
| 49 |
#pragma omp declare reduction(*:M<int>:omp_out.t *= omp_in.t) initializer(omp_priv = 1) |
| 50 |
#pragma omp declare reduction(|:A<unsigned long long>:orit (&omp_in, &omp_out)) |
| 51 |
#pragma omp declare reduction(&:B<long>:omp_out.t = omp_out.t & omp_in.t) initializer(orit (&omp_priv, &omp_orig)) |
| 52 |
#pragma omp declare reduction(maxb:short:omp_out = omp_in > omp_out ? omp_in : omp_out) initializer(omp_priv = -6) |
| 53 |
|
| 54 |
A<char> z[10]; |
| 55 |
|
| 56 |
__attribute__((noinline, noclone)) void |
| 57 |
foo (A<int> (*&x)[3][2], M<int> *y, B<long> (&w)[1][2]) |
| 58 |
{ |
| 59 |
A<unsigned long long> a[9]; |
| 60 |
short bb[5] = {}; |
| 61 |
short (&b)[5] = bb; |
| 62 |
#pragma omp parallel for reduction(+:x[0:2][:][0:2], z[:4]) \ |
| 63 |
reduction(*:y[:3]) reduction(|:a[:4]) \ |
| 64 |
reduction(&:w[0:][:2]) reduction(maxb:b) |
| 65 |
for (int i = 0; i < 128; i++) |
| 66 |
{ |
| 67 |
x[i / 64][i % 3][(i / 4) & 1].t += i; |
| 68 |
if ((i & 15) == 1) |
| 69 |
y[0].t *= 3; |
| 70 |
if ((i & 31) == 2) |
| 71 |
y[1].t *= 7; |
| 72 |
if ((i & 63) == 3) |
| 73 |
y[2].t *= 17; |
| 74 |
z[i / 32].t += (i & 3); |
| 75 |
if (i < 4) |
| 76 |
z[i].t += i; |
| 77 |
a[i / 32].t |= 1ULL << (i & 30); |
| 78 |
w[0][i & 1].t &= ~(1L << (i / 17 * 3)); |
| 79 |
if ((i % 79) > b[0]) |
| 80 |
b[0] = i % 79; |
| 81 |
if ((i % 13) > b[1]) |
| 82 |
b[1] = i % 13; |
| 83 |
if ((i % 23) > b[2]) |
| 84 |
b[2] = i % 23; |
| 85 |
if ((i % 85) > b[3]) |
| 86 |
b[3] = i % 85; |
| 87 |
if ((i % 192) > b[4]) |
| 88 |
b[4] = i % 192; |
| 89 |
} |
| 90 |
for (int i = 0; i < 9; i++) |
| 91 |
if (a[i].t != (i < 4 ? 0x55555555ULL : 0)) |
| 92 |
__builtin_abort (); |
| 93 |
if (bb[0] != 78 || bb[1] != 12 || bb[2] != 22 || bb[3] != 84 || bb[4] != 127) |
| 94 |
__builtin_abort (); |
| 95 |
} |
| 96 |
|
| 97 |
A<int> a3[4][3][2]; |
| 98 |
A<int> (*p3)[3][2] = &a3[1]; |
| 99 |
M<int> y3[5] = { 0, 1, 1, 1, 0 }; |
| 100 |
B<long> w3[1][2]; |
| 101 |
|
| 102 |
struct S |
| 103 |
{ |
| 104 |
A<int> (*&x)[3][2]; |
| 105 |
M<int> *y; |
| 106 |
B<long> (&w)[1][2]; |
| 107 |
A<char> z[10]; |
| 108 |
short b[5]; |
| 109 |
A<unsigned long long> a[9]; |
| 110 |
S() : x(p3), y(y3+1), w(w3), z(), a(), b() {} |
| 111 |
__attribute__((noinline, noclone)) void foo (); |
| 112 |
}; |
| 113 |
|
| 114 |
void |
| 115 |
S::foo () |
| 116 |
{ |
| 117 |
#pragma omp parallel for reduction(+:x[0:2][:][0:2], z[:4]) \ |
| 118 |
reduction(*:y[:3]) reduction(|:a[:4]) \ |
| 119 |
reduction(&:w[0:][:2]) reduction(maxb:b) |
| 120 |
for (int i = 0; i < 128; i++) |
| 121 |
{ |
| 122 |
x[i / 64][i % 3][(i / 4) & 1].t += i; |
| 123 |
if ((i & 15) == 1) |
| 124 |
y[0].t *= 3; |
| 125 |
if ((i & 31) == 2) |
| 126 |
y[1].t *= 7; |
| 127 |
if ((i & 63) == 3) |
| 128 |
y[2].t *= 17; |
| 129 |
z[i / 32].t += (i & 3); |
| 130 |
if (i < 4) |
| 131 |
z[i].t += i; |
| 132 |
a[i / 32].t |= 1ULL << (i & 30); |
| 133 |
w[0][i & 1].t &= ~(1L << (i / 17 * 3)); |
| 134 |
if ((i % 79) > b[0]) |
| 135 |
b[0] = i % 79; |
| 136 |
if ((i % 13) > b[1]) |
| 137 |
b[1] = i % 13; |
| 138 |
if ((i % 23) > b[2]) |
| 139 |
b[2] = i % 23; |
| 140 |
if ((i % 85) > b[3]) |
| 141 |
b[3] = i % 85; |
| 142 |
if ((i % 192) > b[4]) |
| 143 |
b[4] = i % 192; |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
int |
| 148 |
main () |
| 149 |
{ |
| 150 |
A<int> a[4][3][2]; |
| 151 |
static int a2[4][3][2] = {{{ 0, 0 }, { 0, 0 }, { 0, 0 }}, |
| 152 |
{{ 312, 381 }, { 295, 356 }, { 337, 335 }}, |
| 153 |
{{ 1041, 975 }, { 1016, 1085 }, { 935, 1060 }}, |
| 154 |
{{ 0, 0 }, { 0, 0 }, { 0, 0 }}}; |
| 155 |
A<int> (*p)[3][2] = &a[1]; |
| 156 |
M<int> y[5] = { 0, 1, 1, 1, 0 }; |
| 157 |
int y2[5] = { 0, 6561, 2401, 289, 0 }; |
| 158 |
char z2[10] = { 48, 49, 50, 51, 0, 0, 0, 0, 0, 0 }; |
| 159 |
B<long> w[1][2]; |
| 160 |
foo (p, y + 1, w); |
| 161 |
for (int i = 0; i < 4; i++) |
| 162 |
for (int j = 0; j < 3; j++) |
| 163 |
for (int k = 0; k < 2; k++) |
| 164 |
if (a[i][j][k].t != a2[i][j][k]) |
| 165 |
__builtin_abort (); |
| 166 |
for (int i = 0; i < 5; i++) |
| 167 |
if (y[i].t != y2[i]) |
| 168 |
__builtin_abort (); |
| 169 |
for (int i = 0; i < 10; i++) |
| 170 |
if (z[i].t != z2[i]) |
| 171 |
__builtin_abort (); |
| 172 |
if (w[0][0].t != ~0x249249L || w[0][1].t != ~0x249249L) |
| 173 |
__builtin_abort (); |
| 174 |
S s; |
| 175 |
s.foo (); |
| 176 |
for (int i = 0; i < 9; i++) |
| 177 |
if (s.a[i].t != (i < 4 ? 0x55555555ULL : 0)) |
| 178 |
__builtin_abort (); |
| 179 |
for (int i = 0; i < 4; i++) |
| 180 |
for (int j = 0; j < 3; j++) |
| 181 |
for (int k = 0; k < 2; k++) |
| 182 |
if (a3[i][j][k].t != a2[i][j][k]) |
| 183 |
__builtin_abort (); |
| 184 |
for (int i = 0; i < 5; i++) |
| 185 |
if (y3[i].t != y2[i]) |
| 186 |
__builtin_abort (); |
| 187 |
for (int i = 0; i < 10; i++) |
| 188 |
if (s.z[i].t != z2[i]) |
| 189 |
__builtin_abort (); |
| 190 |
if (w3[0][0].t != ~0x249249L || w3[0][1].t != ~0x249249L) |
| 191 |
__builtin_abort (); |
| 192 |
if (s.b[0] != 78 || s.b[1] != 12 || s.b[2] != 22 |
| 193 |
|| s.b[3] != 84 || s.b[4] != 127) |
| 194 |
__builtin_abort (); |
| 195 |
} |