32 #ifndef MCKL_RANDOM_INTERNAL_PHILOX_SSE2_32_HPP 33 #define MCKL_RANDOM_INTERNAL_PHILOX_SSE2_32_HPP 49 template <std::
size_t>
56 template <std::
size_t S>
61 template <std::
size_t S>
64 shuffle_epi32<0xB1>(s);
67 template <std::
size_t S>
70 shuffle_epi32<0xB1>(s);
78 template <std::
size_t S>
81 shuffle_epi32<0xC6>(s);
84 template <std::
size_t S>
87 shuffle_epi32<0x93>(s);
90 template <std::
size_t S>
93 shuffle_epi32<0xB1>(s);
97 template <
typename T, std::
size_t K, std::
size_t Rounds,
typename Constants>
102 const void *plain,
void *cipher,
const std::array<T, K / 2> &key)
108 template <
typename ResultType>
110 Counter<T, K> &ctr, ResultType *r,
const std::array<T, K / 2> &key)
115 template <
typename ResultType>
117 const std::array<T, K / 2> &key)
119 constexpr std::size_t
S = 8;
120 constexpr std::size_t N =
sizeof(__m128i) * S / (
sizeof(T) * K);
121 constexpr std::size_t R =
sizeof(T) * K /
sizeof(ResultType);
123 const std::array<__m128i, Rounds> rk(round_key(key));
125 std::array<__m128i, S> s;
130 std::memcpy(r, s.data(),
sizeof(__m128i) * N);
137 ctr, n, t.data(), key);
138 std::memcpy(r, t.data(),
sizeof(__m128i) * n);
142 template <std::
size_t, std::
size_t S>
143 static void round(std::array<__m128i, S> &,
144 const std::array<__m128i, Rounds> &, std::false_type)
148 template <std::
size_t N, std::
size_t S>
149 static void round(std::array<__m128i, S> &s,
150 const std::array<__m128i, Rounds> &rk, std::true_type)
155 template <std::
size_t N, std::
size_t S>
157 std::array<__m128i, S> &s,
const std::array<__m128i, Rounds> &rk)
159 rbox<N>(s, rk, std::integral_constant<bool, (N > 0 && N <= Rounds)>());
162 template <std::
size_t, std::
size_t S>
163 static void rbox(std::array<__m128i, S> &,
164 const std::array<__m128i, Rounds> &, std::false_type)
168 template <std::
size_t N, std::
size_t S>
169 static void rbox(std::array<__m128i, S> &s,
170 const std::array<__m128i, Rounds> &rk, std::true_type)
173 static_cast<int>(Constants::multiplier::value[0 % (K / 2)]);
175 static_cast<int>(Constants::multiplier::value[1 % (K / 2)]);
176 constexpr
int mask =
static_cast<int>(0xFFFFFFFF);
178 const __m128i m = _mm_set_epi32(0, mul1, 0, mul0);
179 const __m128i a = _mm_set_epi32(mask, 0, mask, 0);
180 const __m128i k = std::get<N - 1>(rk);
182 std::array<__m128i, S> t;
190 MCKL_INLINE static std::array<__m128i, Rounds> round_key(
191 const std::array<T, K / 2> &key)
193 const int k0 =
static_cast<int>(std::get<0 % (K / 2)>(key));
194 const int k1 =
static_cast<int>(std::get<1 % (K / 2)>(key));
196 std::array<__m128i, Rounds> rk;
197 set_key<0>(rk, _mm_set_epi32(k1, 0, k0, 0), std::true_type());
202 template <std::
size_t>
204 std::array<__m128i, Rounds> &,
const __m128i &, std::false_type)
208 template <std::
size_t N>
210 std::array<__m128i, Rounds> &rk,
const __m128i &k, std::true_type)
213 static_cast<int>(Constants::weyl::value[0 % (K / 2)] * N);
215 static_cast<int>(Constants::weyl::value[1 % (K / 2)] * N);
217 std::get<N>(rk) = _mm_add_epi32(k, _mm_set_epi32(w1, 0, w0, 0));
218 set_key<N + 1>(rk, k, std::integral_constant<bool, N + 1 < Rounds>());
221 template <std::
size_t N, std::
size_t S>
222 static void permute(std::array<__m128i, S> &s)
224 permute(s, std::integral_constant<
bool, (N > 0 && N < Rounds)>());
227 template <std::
size_t S>
228 static void permute(std::array<__m128i, S> &, std::false_type)
232 template <std::
size_t S>
233 static void permute(std::array<__m128i, S> &s, std::true_type)
239 template <
typename T,
typename Constants>
245 template <
typename T,
typename Constants>
257 #endif // MCKL_RANDOM_INTERNAL_PHILOX_SSE2_32_HPP static void eval(Counter< T, K > &ctr, std::size_t n, ResultType *r, const std::array< T, K/2 > &key)
#define MCKL_PUSH_GCC_WARNING(warning)
void increment_si128(std::array< T, K > &ctr, std::array< __m128i, S > &s, std::false_type)
void round(std::size_t n, const float *a, float *y)
static void eval(const void *plain, void *cipher, const std::array< T, K/2 > &key)
typename internal::CounterImpl< T, K >::type Counter
A counter type with the same width as std::array<T, K> but with possibly fewer elements.
#define MCKL_RANDOM_INTERNAL_PHILOX_UNROLL_ROUND(N, s, rk)
static void eval(Counter< T, K > &ctr, ResultType *r, const std::array< T, K/2 > &key)
#define MCKL_ALIGNMENT
The default alignment for scalar type.
#define MCKL_POP_GCC_WARNING