Skip to content

Commit c272863

Browse files
JohanMabilleserge-sans-paille
authored andcommitted
Fixed handling of xtl::xcomplex
1 parent 8cc1a5f commit c272863

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

include/xsimd/types/xsimd_api.hpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,14 @@ namespace xsimd
10331033
return kernel::load_complex_aligned<A>(ptr, kernel::convert<batch_value_type> {}, A {});
10341034
}
10351035

1036+
#if XSIMD_ENABLE_XTL_COMPLEX
1037+
template <class To, class A = default_arch, class From, bool i3ec>
1038+
inline simd_return_type<xtl::xcomplex<From, From, i3ec>, To> load_as(xtl::xcomplex<From, From, i3ec> const* ptr, aligned_mode) noexcept
1039+
{
1040+
return load_as<To>(reinterpret_cast<std::complex<From> const*>(ptr), aligned_mode());
1041+
}
1042+
#endif
1043+
10361044
/**
10371045
* @ingroup batch_data_transfer
10381046
*
@@ -1061,6 +1069,14 @@ namespace xsimd
10611069
return kernel::load_complex_unaligned<A>(ptr, kernel::convert<batch_value_type> {}, A {});
10621070
}
10631071

1072+
#if XSIMD_ENABLE_XTL_COMPLEX
1073+
template <class To, class A = default_arch, class From, bool i3ec>
1074+
inline simd_return_type<xtl::xcomplex<From, From, i3ec>, To> load_as(xtl::xcomplex<From, From, i3ec> const* ptr, unaligned_mode) noexcept
1075+
{
1076+
return load_as<To>(reinterpret_cast<std::complex<From> const*>(ptr), unaligned_mode());
1077+
}
1078+
#endif
1079+
10641080
/**
10651081
* @ingroup batch_data_transfer
10661082
*
@@ -1754,6 +1770,14 @@ namespace xsimd
17541770
kernel::store_complex_aligned(dst, src, A {});
17551771
}
17561772

1773+
#if XSIMD_ENABLE_XTL_COMPLEX
1774+
template <class To, class A = default_arch, class From, bool i3ec>
1775+
inline void store_as(xtl::xcomplex<To, To, i3ec>* dst, batch<std::complex<From>, A> const& src, aligned_mode) noexcept
1776+
{
1777+
store_as(reinterpret_cast<std::complex<To>*>(dst), src, aligned_mode());
1778+
}
1779+
#endif
1780+
17571781
/**
17581782
* @ingroup batch_data_transfer
17591783
*
@@ -1780,6 +1804,14 @@ namespace xsimd
17801804
kernel::store_complex_unaligned(dst, src, A {});
17811805
}
17821806

1807+
#if XSIMD_ENABLE_XTL_COMPLEX
1808+
template <class To, class A = default_arch, class From, bool i3ec>
1809+
inline void store_as(xtl::xcomplex<To, To, i3ec>* dst, batch<std::complex<From>, A> const& src, unaligned_mode) noexcept
1810+
{
1811+
store_as(reinterpret_cast<std::complex<To>*>(dst), src, unaligned_mode());
1812+
}
1813+
#endif
1814+
17831815
/**
17841816
* @ingroup batch_data_transfer
17851817
*

include/xsimd/types/xsimd_traits.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,23 @@ namespace xsimd
160160
{
161161
};
162162

163+
template <class T1, class T2, bool I3EC, class A>
164+
struct simd_return_type_impl<xtl::xcomplex<T1, T1, I3EC>, std::complex<T2>, A>
165+
: std::enable_if<simd_condition<T1, T2>::value, batch<std::complex<T2>, A>>
166+
{
167+
};
168+
163169
template <class T1, class T2, bool I3EC, class A>
164170
struct simd_return_type_impl<xtl::xcomplex<T1, T1, I3EC>, xtl::xcomplex<T2, T2, I3EC>, A>
165171
: std::enable_if<simd_condition<T1, T2>::value, batch<std::complex<T2>, A>>
166172
{
167173
};
174+
175+
template <class T1, class T2, bool I3EC, class A>
176+
struct simd_return_type_impl<std::complex<T1>, xtl::xcomplex<T2, T2, I3EC>, A>
177+
: std::enable_if<simd_condition<T1, T2>::value, batch<std::complex<T2>, A>>
178+
{
179+
};
168180
#endif
169181
}
170182

test/test_batch_complex.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ class batch_complex_test : public testing::Test
123123
std::fill(tmp.begin(), tmp.end(), xtl_value_type(2, 3));
124124
batch_type b0(xtl_value_type(2, 3));
125125
EXPECT_EQ(b0, tmp) << print_function_name("batch(value_type)");
126+
127+
batch_type b1 = xsimd::load_as<xtl_value_type>(tmp.data(), xsimd::aligned_mode());
128+
EXPECT_EQ(b1, tmp) << print_function_name("load_as<value_type> aligned");
129+
130+
batch_type b2 = xsimd::load_as<xtl_value_type>(tmp.data(), xsimd::unaligned_mode());
131+
EXPECT_EQ(b2, tmp) << print_function_name("load_as<value_type> unaligned");
132+
133+
xsimd::store_as(tmp.data(), b1, xsimd::aligned_mode());
134+
EXPECT_EQ(b1, tmp) << print_function_name("store_as<value_type> aligned");
135+
136+
xsimd::store_as(tmp.data(), b2, xsimd::unaligned_mode());
137+
EXPECT_EQ(b2, tmp) << print_function_name("store_as<value_type> unaligned");
126138
}
127139
#endif
128140

0 commit comments

Comments
 (0)