| 1 |
// { dg-additional-options "-fopenmp-simd" } |
| 2 |
// { dg-additional-options "-mavx2" { target { avx2_runtime } } } |
| 3 |
|
| 4 |
extern "C" int memcmp(const void *s1, const void *s2, __SIZE_TYPE__ n); |
| 5 |
extern "C" void abort(void); |
| 6 |
|
| 7 |
template <typename T> |
| 8 |
T reverseBits(T x) |
| 9 |
{ |
| 10 |
unsigned int s = sizeof(x) * 8; |
| 11 |
T mask = ~T(0); |
| 12 |
while ((s >>= 1) > 0) |
| 13 |
{ |
| 14 |
mask ^= (mask << s); |
| 15 |
x = ((x >> s) & mask) | ((x << s) & ~mask); // unsupported use in stmt |
| 16 |
} |
| 17 |
return x; |
| 18 |
} |
| 19 |
|
| 20 |
void __attribute__((noinline,noipa)) |
| 21 |
test_reverseBits(unsigned* x) |
| 22 |
{ |
| 23 |
#pragma omp simd aligned(x:32) |
| 24 |
for (int i = 0; i < 16; ++i) |
| 25 |
x[i] = reverseBits(x[i]); // couldn't vectorize loop |
| 26 |
} |
| 27 |
|
| 28 |
int main() |
| 29 |
{ |
| 30 |
unsigned arr[16] __attribute__((aligned(32))) |
| 31 |
= { 0x01020304, 0x05060708, 0x0a0b0c0d, 0x0e0f1011, |
| 32 |
0x11121314, 0x45065708, 0xfa0b3c0du, 0x0e0f1211, |
| 33 |
0x21222324, 0x55066708, 0xfa0b2c0du, 0x1e0f1011, |
| 34 |
0x31323334, 0x65067708, 0xfa0b5c0du, 0x0e3f1011 }; |
| 35 |
unsigned arr2[16] |
| 36 |
= { 0x20c04080, 0x10e060a0, 0xb030d050, 0x8808f070u, |
| 37 |
0x28c84888, 0x10ea60a2, 0xb03cd05f, 0x8848f070u, |
| 38 |
0x24c44484, 0x10e660aa, 0xb034d05f, 0x8808f078u, |
| 39 |
0x2ccc4c8c, 0x10ee60a6, 0xb03ad05f, 0x8808fc70u }; |
| 40 |
|
| 41 |
test_reverseBits (arr); |
| 42 |
|
| 43 |
if (memcmp (arr, arr2, sizeof (arr)) != 0) |
| 44 |
abort (); |
| 45 |
return 0; |
| 46 |
} |
| 47 |
|
| 48 |
// { dg-final { scan-tree-dump "OUTER LOOP VECTORIZED" "vect" { target { vect_var_shift && vect_int } } } } |