[go: up one dir, main page]

Skip to content

Commit

Permalink
added proper intrinsics
Browse files Browse the repository at this point in the history
  • Loading branch information
JustasMasiulis committed Oct 1, 2018
1 parent 950c7ea commit 44aa436
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions include/xorstr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@
XORSTR_STRING_EXPAND_10(6, x), XORSTR_STRING_EXPAND_10(7, x), \
XORSTR_STRING_EXPAND_10(8, x), XORSTR_STRING_EXPAND_10(9, x)

#define XORSTR_STR(s) \
::jm::detail::string_builder< \
typename ::jm::detail::decay_array_deref<decltype(*s)>::type, \
jm::detail::tstring_< \
typename ::jm::detail::decay_array_deref<decltype(*s)>::type>, \
#define XORSTR_STR(s) \
::jm::detail::string_builder< \
typename ::jm::detail::decay_array_deref<decltype(*s)>::type, \
jm::detail::tstring_<typename ::jm::detail::decay_array_deref<decltype(*s)>::type>, \
XORSTR_STRING_EXPAND_100(s)>::type

namespace jm {
Expand All @@ -82,7 +81,7 @@ namespace jm {
struct decay_array_deref<const T&> {
using type = T;
};

template<bool Cond>
struct conditional {
template<class, class False>
Expand All @@ -94,7 +93,7 @@ namespace jm {
template<class True, class>
using type = True;
};

template<class T>
struct as_unsigned {
using type = typename conditional<sizeof(T) == 1>::template type<
Expand All @@ -120,9 +119,8 @@ namespace jm {

template<class T, template<class, T...> class S, T... Hs, T C, T... Cs>
struct string_builder<T, S<T, Hs...>, C, Cs...>
: conditional<C ==
T(0)>::template type<string_builder<T, S<T, Hs...>>,
string_builder<T, S<T, Hs..., C>, Cs...>> {
: conditional<C == T(0)>::template type<string_builder<T, S<T, Hs...>>,
string_builder<T, S<T, Hs..., C>, Cs...>> {
};

template<class T, T... Cs>
Expand Down Expand Up @@ -232,8 +230,10 @@ namespace jm {
keys[2] = detail::key8<N + 2>();
keys[3] = detail::key8<N + 3>();

*(__m256i*)(&_storage[N]) = _mm256_xor_si256(
*(__m256i*)(&_storage[N]), *(const __m256i*)(&keys));
_mm256_store_si256(
(__m256i*)(&_storage[N]),
_mm256_xor_si256(_mm256_load_si256((const __m256i*)(&_storage[N])),
_mm256_load_si256((const __m256i*)(&keys))));
_crypt<N + 4>();
}
else
Expand All @@ -243,8 +243,10 @@ namespace jm {
keys[0] = detail::key8<N + 0>();
keys[1] = detail::key8<N + 1>();

*(__m128i*)(&_storage[N]) = _mm_xor_si128(*(__m128i*)(&_storage[N]),
*(const __m128i*)(&keys));
_mm_store_si128(
(__m128i*)(&_storage[N]),
_mm_xor_si128(_mm_load_si128((const __m128i*)(&_storage[N])),
_mm_load_si128((const __m128i*)(&keys))));
_crypt<N + 2>();
}
}
Expand Down

0 comments on commit 44aa436

Please sign in to comment.