Skip to content

Commit

Permalink
Merge pull request #952 from anutosh491/Introducing_wasm_based_IS
Browse files Browse the repository at this point in the history
Initial Implementation for the new WASM based instruction set
  • Loading branch information
JohanMabille authored Oct 25, 2023
2 parents cc14c23 + 1402e0e commit f27bbb8
Show file tree
Hide file tree
Showing 8 changed files with 1,585 additions and 3 deletions.
44 changes: 44 additions & 0 deletions include/xsimd/arch/generic/xsimd_generic_arithmetic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,20 @@ namespace xsimd
return { res_r, res_i };
}

// hadd
template <class A, class T, class /*=typename std::enable_if<std::is_integral<T>::value, void>::type*/>
inline T hadd(batch<T, A> const& self, requires_arch<generic>) 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;
}

// incr
template <class A, class T>
inline batch<T, A> incr(batch<T, A> const& self, requires_arch<generic>) noexcept
Expand Down Expand Up @@ -172,6 +186,23 @@ namespace xsimd
{
return add(self, other); // no saturated arithmetic on floating point numbers
}
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<generic>) 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>
inline batch<double, A> sadd(batch<double, A> const& self, batch<double, A> const& other, requires_arch<generic>) noexcept
{
Expand All @@ -184,6 +215,19 @@ namespace xsimd
{
return sub(self, other); // no saturated arithmetic on floating point numbers
}
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<generic>) noexcept
{
if (std::is_signed<T>::value)
{
return sadd(self, -other);
}
else
{
const auto diff = min(self, other);
return self - diff;
}
}
template <class A>
inline batch<double, A> ssub(batch<double, A> const& self, batch<double, A> const& other, requires_arch<generic>) noexcept
{
Expand Down
6 changes: 6 additions & 0 deletions include/xsimd/arch/xsimd_generic_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ namespace xsimd
inline batch_bool<T, A> gt(batch<T, A> const& self, batch<T, A> const& other, requires_arch<generic>) noexcept;
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
inline batch<T, A> mul(batch<T, A> const& self, batch<T, A> const& other, requires_arch<generic>) noexcept;
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<generic>) noexcept;
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<generic>) noexcept;
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
inline T hadd(batch<T, A> const& self, requires_arch<generic>) noexcept;

}
}
Expand Down
4 changes: 4 additions & 0 deletions include/xsimd/arch/xsimd_isa.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@
#include "./xsimd_sve.hpp"
#endif

#if XSIMD_WITH_WASM
#include "./xsimd_wasm.hpp"
#endif

// Must come last to have access to all conversion specializations.
#include "./xsimd_generic.hpp"

Expand Down
Loading

0 comments on commit f27bbb8

Please sign in to comment.