| 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 |
int b[1024] __attribute__((aligned (32))) = { 1 }; |
| 8 |
int k, m; |
| 9 |
struct U { U (); ~U (); int u; }; |
| 10 |
struct V |
| 11 |
{ |
| 12 |
V () : v (8) {} |
| 13 |
~V () |
| 14 |
{ |
| 15 |
if (v > 38 + 4 + 3 * 1024 + 1) |
| 16 |
abort (); |
| 17 |
} |
| 18 |
V &operator= (const V &x) { v = x.v + 1; return *this; } |
| 19 |
int v; |
| 20 |
}; |
| 21 |
|
| 22 |
__attribute__((noinline, noclone)) |
| 23 |
U::U () : u (6) |
| 24 |
{ |
| 25 |
} |
| 26 |
|
| 27 |
__attribute__((noinline, noclone)) |
| 28 |
U::~U () |
| 29 |
{ |
| 30 |
if (u > 38 + 4 + 3 * 1023) |
| 31 |
abort (); |
| 32 |
} |
| 33 |
|
| 34 |
__attribute__((noinline, noclone)) int |
| 35 |
foo (int *p) |
| 36 |
{ |
| 37 |
int i, s = 0; |
| 38 |
U u; |
| 39 |
V v; |
| 40 |
#pragma omp simd aligned(a, p : 32) linear(k: m + 1) \ |
| 41 |
reduction(+:s) lastprivate(u, v) |
| 42 |
for (i = 0; i < 1024; i++) |
| 43 |
{ |
| 44 |
a[i] *= p[i]; |
| 45 |
u.u = p[i] + k; |
| 46 |
k += m + 1; |
| 47 |
v.v = p[i] + k; |
| 48 |
s += p[i] + k; |
| 49 |
} |
| 50 |
if (u.u != 36 + 4 + 3 * 1023 || v.v != 36 + 4 + 3 * 1024 + 1) |
| 51 |
abort (); |
| 52 |
return s; |
| 53 |
} |
| 54 |
|
| 55 |
int |
| 56 |
main () |
| 57 |
{ |
| 58 |
#if __SIZEOF_INT__ >= 4 |
| 59 |
int i; |
| 60 |
k = 4; |
| 61 |
m = 2; |
| 62 |
for (i = 0; i < 1024; i++) |
| 63 |
{ |
| 64 |
a[i] = i - 512; |
| 65 |
b[i] = (i - 51) % 39; |
| 66 |
} |
| 67 |
int s = foo (b); |
| 68 |
for (i = 0; i < 1024; i++) |
| 69 |
{ |
| 70 |
if (b[i] != (i - 51) % 39 |
| 71 |
|| a[i] != (i - 512) * b[i]) |
| 72 |
abort (); |
| 73 |
} |
| 74 |
if (k != 4 + 3 * 1024 || s != 1596127) |
| 75 |
abort (); |
| 76 |
#endif |
| 77 |
return 0; |
| 78 |
} |