Skip to content

Commit

Permalink
Added support for set and stored_aligned operations
Browse files Browse the repository at this point in the history
  • Loading branch information
anutosh491 committed Oct 3, 2023
1 parent bcbe287 commit 95680fb
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions include/xsimd/arch/xsimd_wasm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,23 @@ namespace xsimd
return wasm_f64x2_add(self, other);
}

// all
template <class A>
inline bool all(batch_bool<float, A> const& self, requires_arch<wasm>) noexcept
{
return wasm_i32x4_bitmask(self) == 0x0F;
}
template <class A>
inline bool all(batch_bool<double, A> const& self, requires_arch<wasm>) noexcept
{
return wasm_i64x2_bitmask(self) == 0x03;
}
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
inline bool all(batch_bool<T, A> const& self, requires_arch<wasm>) noexcept
{
return wasm_i8x16_bitmask(self) == 0xFFFF;
}

// set
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
inline batch<T, A> set(batch<T, A> const&, requires_arch<wasm>, T v0, T v1) noexcept
Expand All @@ -140,13 +157,44 @@ namespace xsimd
return wasm_i8x16_make(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15);
}

template <class A, class... Values>
inline batch<double, A> set(batch<double, A> const&, requires_arch<wasm>, Values... values) noexcept
{
static_assert(sizeof...(Values) == batch<double, A>::size, "consistent init");
return wasm_f64x2_make(values...);
}

template <class A, class T, class... Values, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
inline batch_bool<T, A> set(batch_bool<T, A> const&, requires_arch<wasm>, Values... values) noexcept
{
return set(batch<T, A>(), A {}, static_cast<T>(values ? -1LL : 0LL)...).data;
}

//store_aligned
template <class A>
inline void store_aligned(float* mem, batch<float, A> const& self, requires_arch<wasm>) noexcept
{
// Assuming that mem is aligned properly, you can use wasm_v128_store to store the batch.
return wasm_v128_store(mem, self);
}
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
inline void store_aligned(T* mem, batch<T, A> const& self, requires_arch<wasm>) noexcept
{
// Assuming that mem is aligned properly, you can use wasm_v128_store to store the batch.
return wasm_v128_store((v128_t*)mem, self);
}
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
inline void store_aligned(T* mem, batch_bool<T, A> const& self, requires_arch<wasm>) noexcept
{
// Assuming that mem is aligned properly, you can use wasm_v128_store to store the batch.
return wasm_v128_store((v128_t*)mem, self);
}
template <class A>
inline void store_aligned(double* mem, batch<double, A> const& self, requires_arch<wasm>) noexcept
{
// Assuming that mem is aligned properly, you can use wasm_v128_store to store the batch.
return wasm_v128_store(mem, self);
}
}
}

Expand Down

0 comments on commit 95680fb

Please sign in to comment.