Skip to content

Commit

Permalink
Use iterator_traits with simd_for_each
Browse files Browse the repository at this point in the history
This enables use of std::array (with simple pointer-base iterators) and
C-arrays

Signed-off-by: Matthias Kretz <kretz@kde.org>
  • Loading branch information
mattkretz committed May 5, 2017
1 parent 71316b1 commit 037be1b
Showing 1 changed file with 38 additions and 26 deletions.
64 changes: 38 additions & 26 deletions common/algorithms.h
Expand Up @@ -77,14 +77,16 @@ constexpr bool some_of(bool) { return false; }
//@}

template <typename InputIt, typename UnaryFunction>
inline enable_if<std::is_arithmetic<typename InputIt::value_type>::value &&
Traits::is_functor_argument_immutable<
UnaryFunction, Vector<typename InputIt::value_type>>::value,
UnaryFunction>
inline enable_if<
std::is_arithmetic<typename std::iterator_traits<InputIt>::value_type>::value &&
Traits::is_functor_argument_immutable<
UnaryFunction,
Vector<typename std::iterator_traits<InputIt>::value_type>>::value,
UnaryFunction>
simd_for_each(InputIt first, InputIt last, UnaryFunction f)
{
typedef Vector<typename InputIt::value_type> V;
typedef Scalar::Vector<typename InputIt::value_type> V1;
typedef Vector<typename std::iterator_traits<InputIt>::value_type> V;
typedef Scalar::Vector<typename std::iterator_traits<InputIt>::value_type> V1;
for (; reinterpret_cast<std::uintptr_t>(std::addressof(*first)) &
(V::MemoryAlignment - 1) &&
first != last;
Expand All @@ -102,14 +104,16 @@ simd_for_each(InputIt first, InputIt last, UnaryFunction f)
}

template <typename InputIt, typename UnaryFunction>
inline enable_if<std::is_arithmetic<typename InputIt::value_type>::value &&
!Traits::is_functor_argument_immutable<
UnaryFunction, Vector<typename InputIt::value_type>>::value,
UnaryFunction>
inline enable_if<
std::is_arithmetic<typename std::iterator_traits<InputIt>::value_type>::value &&
!Traits::is_functor_argument_immutable<
UnaryFunction,
Vector<typename std::iterator_traits<InputIt>::value_type>>::value,
UnaryFunction>
simd_for_each(InputIt first, InputIt last, UnaryFunction f)
{
typedef Vector<typename InputIt::value_type> V;
typedef Scalar::Vector<typename InputIt::value_type> V1;
typedef Vector<typename std::iterator_traits<InputIt>::value_type> V;
typedef Scalar::Vector<typename std::iterator_traits<InputIt>::value_type> V1;
for (; reinterpret_cast<std::uintptr_t>(std::addressof(*first)) &
(V::MemoryAlignment - 1) &&
first != last;
Expand All @@ -133,23 +137,27 @@ simd_for_each(InputIt first, InputIt last, UnaryFunction f)
}

template <typename InputIt, typename UnaryFunction>
inline enable_if<!std::is_arithmetic<typename InputIt::value_type>::value, UnaryFunction>
inline enable_if<
!std::is_arithmetic<typename std::iterator_traits<InputIt>::value_type>::value,
UnaryFunction>
simd_for_each(InputIt first, InputIt last, UnaryFunction f)
{
return std::for_each(first, last, std::move(f));
}

///////////////////////////////////////////////////////////////////////////////
template <typename InputIt, typename UnaryFunction>
inline enable_if<std::is_arithmetic<typename InputIt::value_type>::value &&
Traits::is_functor_argument_immutable<
UnaryFunction, Vector<typename InputIt::value_type>>::value,
UnaryFunction>
inline enable_if<
std::is_arithmetic<typename std::iterator_traits<InputIt>::value_type>::value &&
Traits::is_functor_argument_immutable<
UnaryFunction,
Vector<typename std::iterator_traits<InputIt>::value_type>>::value,
UnaryFunction>
simd_for_each_n(InputIt first, std::size_t count, UnaryFunction f)
{
typename std::make_signed<size_t>::type len = count;
typedef Vector<typename InputIt::value_type> V;
typedef Scalar::Vector<typename InputIt::value_type> V1;
typedef Vector<typename std::iterator_traits<InputIt>::value_type> V;
typedef Scalar::Vector<typename std::iterator_traits<InputIt>::value_type> V1;
for (; reinterpret_cast<std::uintptr_t>(std::addressof(*first)) &
(V::MemoryAlignment - 1) &&
len != 0;
Expand All @@ -166,15 +174,17 @@ simd_for_each_n(InputIt first, std::size_t count, UnaryFunction f)
}

template <typename InputIt, typename UnaryFunction>
inline enable_if<std::is_arithmetic<typename InputIt::value_type>::value &&
!Traits::is_functor_argument_immutable<
UnaryFunction, Vector<typename InputIt::value_type>>::value,
UnaryFunction>
inline enable_if<
std::is_arithmetic<typename std::iterator_traits<InputIt>::value_type>::value &&
!Traits::is_functor_argument_immutable<
UnaryFunction,
Vector<typename std::iterator_traits<InputIt>::value_type>>::value,
UnaryFunction>
simd_for_each_n(InputIt first, std::size_t count, UnaryFunction f)
{
typename std::make_signed<size_t>::type len = count;
typedef Vector<typename InputIt::value_type> V;
typedef Scalar::Vector<typename InputIt::value_type> V1;
typedef Vector<typename std::iterator_traits<InputIt>::value_type> V;
typedef Scalar::Vector<typename std::iterator_traits<InputIt>::value_type> V1;
for (; reinterpret_cast<std::uintptr_t>(std::addressof(*first)) &
(V::MemoryAlignment - 1) &&
len != 0;
Expand All @@ -198,7 +208,9 @@ simd_for_each_n(InputIt first, std::size_t count, UnaryFunction f)

#ifdef Vc_CXX17
template <typename InputIt, typename UnaryFunction>
inline enable_if<!std::is_arithmetic<typename InputIt::value_type>::value, UnaryFunction>
inline enable_if<
!std::is_arithmetic<typename std::iterator_traits<InputIt>::value_type>::value,
UnaryFunction>
simd_for_each_n(InputIt first, std::size_t count, UnaryFunction f)
{
return std::for_each_n(first, count, std::move(f));
Expand Down

0 comments on commit 037be1b

Please sign in to comment.