Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented sadd, ssub & reduce_add through the generic implementation for xsimd_sse2 #960

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 6 additions & 60 deletions include/xsimd/arch/xsimd_sse2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1237,22 +1237,7 @@ namespace xsimd
batch<T, A> acc3 = min(acc2, step3);
return acc3.get(0);
}
// TODO: move this in xsimd_generic
namespace detail
{
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
inline T hadd_default(batch<T, A> const& self, requires_arch<sse2>) noexcept
{
alignas(A::alignment()) T buffer[batch<T, A>::size];
self.store_aligned(buffer);
T res = 0;
for (T val : buffer)
{
res += val;
}
return res;
}
}

template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
inline T reduce_add(batch<T, A> const& self, requires_arch<sse2>) noexcept
{
Expand Down Expand Up @@ -1280,7 +1265,7 @@ namespace xsimd
}
else
{
return detail::hadd_default(self, A {});
return hadd(self, generic {});
}
}
template <class A>
Expand Down Expand Up @@ -1381,28 +1366,6 @@ namespace xsimd

// sadd

// TODO: move this in xsimd_generic
namespace detail
{
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
inline batch<T, A> sadd_default(batch<T, A> const& self, batch<T, A> const& other, requires_arch<sse2>) noexcept
{
if (std::is_signed<T>::value)
{
auto mask = (other >> (8 * sizeof(T) - 1));
auto self_pos_branch = min(std::numeric_limits<T>::max() - other, self);
auto self_neg_branch = max(std::numeric_limits<T>::min() - other, self);
return other + select(batch_bool<T, A>(mask.data), self_neg_branch, self_pos_branch);
}
else
{
const auto diffmax = std::numeric_limits<T>::max() - self;
const auto mindiff = min(diffmax, other);
return self + mindiff;
}
}
}

template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
inline batch<T, A> sadd(batch<T, A> const& self, batch<T, A> const& other, requires_arch<sse2>) noexcept
{
Expand All @@ -1418,7 +1381,7 @@ namespace xsimd
}
else
{
return detail::sadd_default(self, other, A {});
return sadd(self, other, generic {});
}
}
else
Expand All @@ -1433,7 +1396,7 @@ namespace xsimd
}
else
{
return detail::sadd_default(self, other, A {});
return sadd(self, other, generic {});
}
}
}
Expand Down Expand Up @@ -1495,23 +1458,6 @@ namespace xsimd
}

// ssub
// TODO: move this in xsimd_generic
namespace detail
{
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
inline batch<T, A> ssub_default(batch<T, A> const& self, batch<T, A> const& other, requires_arch<sse2>) noexcept
{
if (std::is_signed<T>::value)
{
return sadd(self, -other);
}
else
{
const auto diff = min(self, other);
return self - diff;
}
}
}

template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
inline batch<T, A> ssub(batch<T, A> const& self, batch<T, A> const& other, requires_arch<sse2>) noexcept
Expand All @@ -1528,7 +1474,7 @@ namespace xsimd
}
else
{
return detail::ssub_default(self, other, A {});
return ssub(self, other, generic {});
}
}
else
Expand All @@ -1543,7 +1489,7 @@ namespace xsimd
}
else
{
return detail::ssub_default(self, other, A {});
return ssub(self, other, generic {});
}
}
}
Expand Down
Loading