10#ifndef XTENSOR_SIMD_HPP
11#define XTENSOR_SIMD_HPP
15#include <xtl/xdynamic_bitset.hpp>
19#ifdef XTENSOR_USE_XSIMD
21#include <xsimd/xsimd.hpp>
24#if defined(_MSV_VER) && (_MSV_VER < 1910)
25template <
class T,
class A>
26inline xsimd::batch_bool<T, A> isnan(
const xsimd::batch<T, A>& b)
28 return xsimd::isnan(b);
34 template <
class T, std::
size_t A>
35 using aligned_allocator = xsimd::aligned_allocator<T, A>;
37 using aligned_mode = xsimd::aligned_mode;
38 using unaligned_mode = xsimd::unaligned_mode;
41 using allocator_alignment = xsimd::allocator_alignment<A>;
44 using allocator_alignment_t = xsimd::allocator_alignment_t<A>;
47 using container_alignment = xsimd::container_alignment<C>;
50 using container_alignment_t = xsimd::container_alignment_t<C>;
53 using simd_traits = xsimd::simd_traits<T>;
56 using revert_simd_traits = xsimd::revert_simd_traits<T>;
59 using simd_type = xsimd::simd_type<T>;
62 using simd_bool_type = xsimd::simd_bool_type<T>;
65 using revert_simd_type = xsimd::revert_simd_type<T>;
67 template <
class T1,
class T2>
68 using simd_return_type = xsimd::simd_return_type<T1, T2>;
70 using xsimd::broadcast_as;
71 using xsimd::get_alignment_offset;
74 using xsimd::store_as;
77 using is_batch_bool = xsimd::is_batch_bool<V>;
80 using is_batch_complex = xsimd::is_batch_complex<V>;
82 template <
class T1,
class T2>
83 using simd_condition = xsimd::detail::simd_condition<T1, T2>;
90 template <
class T, std::
size_t A>
123 using bool_type = bool;
124 using batch_bool = bool;
125 static constexpr std::size_t size = 1;
136 using simd_type =
typename simd_traits<T>::type;
139 using simd_bool_type =
typename simd_traits<T>::bool_type;
142 using revert_simd_type =
typename revert_simd_traits<T>::type;
144 template <
class R,
class T>
145 inline simd_type<R> broadcast_as(
const T& value)
150 template <
class R,
class T>
151 inline simd_type<R> load_as(
const T* src, aligned_mode)
156 template <
class R,
class T>
157 inline simd_type<R> load_as(
const T* src, unaligned_mode)
162 template <
class R,
class T>
163 inline void store_as(R* dst,
const simd_type<T>& src, aligned_mode)
168 template <
class R,
class T>
169 inline void store_as(R* dst,
const simd_type<T>& src, unaligned_mode)
175 inline T select(
bool cond,
const T& t1,
const T& t2)
177 return cond ? t1 : t2;
181 inline std::size_t get_alignment_offset(
const T* , std::size_t size, std::size_t )
186 template <
class T1,
class T2>
187 using simd_return_type = simd_type<T2>;
199 template <
class T1,
class T2>
218 template <
class A1,
class A2>
219 struct driven_align_mode_impl
225 struct driven_align_mode_impl<inner_aligned_mode, A>
231 template <
class A1,
class A2>
234 using type =
typename detail::driven_align_mode_impl<A1, A2>::type;
237 template <
class A1,
class A2>
238 using driven_align_mode_t =
typename detail::driven_align_mode_impl<A1, A2>::type;
242 template <
class E,
class T,
class =
void>
243 struct has_load_simd : std::false_type
247 template <
class E,
class T>
248 struct has_load_simd<
251 void_t<decltype(std::declval<E>().template load_simd<aligned_mode, T>(typename E::size_type(0)))>>
256 template <class E, class T, bool B = xt_simd::simd_condition<typename E::value_type, T>::value>
257 struct has_simd_interface_impl : has_load_simd<E, T>
261 template <
class E,
class T>
262 struct has_simd_interface_impl<E, T, false> : std::false_type
267 template <class E, class T = typename std::decay_t<E>::value_type>
273 struct has_simd_type : std::integral_constant<bool, !std::is_same<T, xt_simd::simd_type<T>>::value>
279 template <
class F,
class B,
class =
void>
280 struct has_simd_apply_impl : std::false_type
284 template <
class F,
class B>
285 struct has_simd_apply_impl<F, B, void_t<decltype(&F::template simd_apply<B>)>> : std::true_type
290 template <
class F,
class B>
296 using bool_load_type = std::conditional_t<std::is_same<T, bool>::value,
uint8_t, T>;
313 template <
class B,
class A>
318 template <
class B,
class A>
323 template <
class C,
class T1,
class T2>
325 : std::enable_if<!forbid_simd<C>::value, xt_simd::simd_return_type<T1, bool_load_type<T2>>>
329 template <
class C,
class T1,
class T2>
standard mathematical functions for xexpressions