| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "-O -fno-tree-forwprop -maltivec" } */ |
| 3 |
/* { dg-require-effective-target vmx_hw } */ |
| 4 |
|
| 5 |
typedef __attribute__ ((altivec (vector__))) unsigned native_simd_type; |
| 6 |
|
| 7 |
union |
| 8 |
{ |
| 9 |
native_simd_type V; |
| 10 |
int R[4]; |
| 11 |
} store_le_vec; |
| 12 |
|
| 13 |
struct S |
| 14 |
{ |
| 15 |
S () = default; |
| 16 |
S (unsigned B0) |
| 17 |
{ |
| 18 |
native_simd_type val{B0}; |
| 19 |
m_simd = val; |
| 20 |
} |
| 21 |
void store_le (unsigned int out[]) |
| 22 |
{ |
| 23 |
store_le_vec.V = m_simd; |
| 24 |
unsigned int x0 = store_le_vec.R[0]; |
| 25 |
__builtin_memcpy (out, &x0, 4); |
| 26 |
} |
| 27 |
S rotl (unsigned int r) |
| 28 |
{ |
| 29 |
native_simd_type rot{r}; |
| 30 |
return __builtin_vec_rl (m_simd, rot); |
| 31 |
} |
| 32 |
void operator+= (S other) |
| 33 |
{ |
| 34 |
m_simd = __builtin_vec_add (m_simd, other.m_simd); |
| 35 |
} |
| 36 |
void operator^= (S other) |
| 37 |
{ |
| 38 |
m_simd = __builtin_vec_xor (m_simd, other.m_simd); |
| 39 |
} |
| 40 |
static void transpose (S &B0, S B1, S B2, S B3) |
| 41 |
{ |
| 42 |
native_simd_type T0 = __builtin_vec_mergeh (B0.m_simd, B2.m_simd); |
| 43 |
native_simd_type T1 = __builtin_vec_mergeh (B1.m_simd, B3.m_simd); |
| 44 |
native_simd_type T2 = __builtin_vec_mergel (B0.m_simd, B2.m_simd); |
| 45 |
native_simd_type T3 = __builtin_vec_mergel (B1.m_simd, B3.m_simd); |
| 46 |
B0 = __builtin_vec_mergeh (T0, T1); |
| 47 |
B3 = __builtin_vec_mergel (T2, T3); |
| 48 |
} |
| 49 |
S (native_simd_type x) : m_simd (x) {} |
| 50 |
native_simd_type m_simd; |
| 51 |
}; |
| 52 |
|
| 53 |
void |
| 54 |
foo (unsigned int output[], unsigned state[]) |
| 55 |
{ |
| 56 |
S R00 = state[0]; |
| 57 |
S R01 = state[0]; |
| 58 |
S R02 = state[2]; |
| 59 |
S R03 = state[0]; |
| 60 |
S R05 = state[5]; |
| 61 |
S R06 = state[6]; |
| 62 |
S R07 = state[7]; |
| 63 |
S R08 = state[8]; |
| 64 |
S R09 = state[9]; |
| 65 |
S R10 = state[10]; |
| 66 |
S R11 = state[11]; |
| 67 |
S R12 = state[12]; |
| 68 |
S R13 = state[13]; |
| 69 |
S R14 = state[4]; |
| 70 |
S R15 = state[15]; |
| 71 |
for (int r = 0; r != 10; ++r) |
| 72 |
{ |
| 73 |
R09 += R13; |
| 74 |
R11 += R15; |
| 75 |
R05 ^= R09; |
| 76 |
R06 ^= R10; |
| 77 |
R07 ^= R11; |
| 78 |
R07 = R07.rotl (7); |
| 79 |
R00 += R05; |
| 80 |
R01 += R06; |
| 81 |
R02 += R07; |
| 82 |
R15 ^= R00; |
| 83 |
R12 ^= R01; |
| 84 |
R13 ^= R02; |
| 85 |
R00 += R05; |
| 86 |
R01 += R06; |
| 87 |
R02 += R07; |
| 88 |
R15 ^= R00; |
| 89 |
R12 = R12.rotl (8); |
| 90 |
R13 = R13.rotl (8); |
| 91 |
R10 += R15; |
| 92 |
R11 += R12; |
| 93 |
R08 += R13; |
| 94 |
R09 += R14; |
| 95 |
R05 ^= R10; |
| 96 |
R06 ^= R11; |
| 97 |
R07 ^= R08; |
| 98 |
R05 = R05.rotl (7); |
| 99 |
R06 = R06.rotl (7); |
| 100 |
R07 = R07.rotl (7); |
| 101 |
} |
| 102 |
R00 += state[0]; |
| 103 |
S::transpose (R00, R01, R02, R03); |
| 104 |
R00.store_le (output); |
| 105 |
} |
| 106 |
|
| 107 |
unsigned int res[1]; |
| 108 |
unsigned main_state[]{1634760805, 60878, 2036477234, 6, |
| 109 |
0, 825562964, 1471091955, 1346092787, |
| 110 |
506976774, 4197066702, 518848283, 118491664, |
| 111 |
0, 0, 0, 0}; |
| 112 |
int |
| 113 |
main () |
| 114 |
{ |
| 115 |
foo (res, main_state); |
| 116 |
if (res[0] != 0x41fcef98) |
| 117 |
__builtin_abort (); |
| 118 |
return 0; |
| 119 |
} |