Skip to content

Commit cb3fead

Browse files
Add support for xsimd::widen on WebAssembly
Related to #1179
1 parent 538aa9d commit cb3fead

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

include/xsimd/arch/xsimd_wasm.hpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <type_traits>
1717

1818
#include "../types/xsimd_wasm_register.hpp"
19+
#include "./common/xsimd_common_cast.hpp"
1920

2021
namespace xsimd
2122
{
@@ -1701,6 +1702,44 @@ namespace xsimd
17011702
return wasm_f64x2_trunc(self);
17021703
}
17031704

1705+
// widen
1706+
template <class A>
1707+
XSIMD_INLINE std::array<batch<double, A>, 2> widen(batch<float, A> const& x, requires_arch<wasm>) noexcept
1708+
{
1709+
return { batch<double, A>(wasm_f64x2_promote_low_f32x4(x)),
1710+
batch<double, A>(wasm_f64x2_promote_low_f32x4(wasm_i32x4_shuffle(x, x, 2, 3, 0, 1))) };
1711+
}
1712+
template <class A>
1713+
XSIMD_INLINE std::array<batch<widen_t<uint8_t>, A>, 2> widen(batch<uint8_t, A> const& x, requires_arch<wasm>) noexcept
1714+
{
1715+
return { batch<widen_t<uint8_t>, A>(wasm_u16x8_extend_low_u8x16(x)), batch<widen_t<uint8_t>, A>(wasm_u16x8_extend_high_u8x16(x)) };
1716+
}
1717+
template <class A>
1718+
XSIMD_INLINE std::array<batch<widen_t<int8_t>, A>, 2> widen(batch<int8_t, A> const& x, requires_arch<wasm>) noexcept
1719+
{
1720+
return { batch<widen_t<int8_t>, A>(wasm_i16x8_extend_low_i8x16(x)), batch<widen_t<int8_t>, A>(wasm_i16x8_extend_high_i8x16(x)) };
1721+
}
1722+
template <class A>
1723+
XSIMD_INLINE std::array<batch<widen_t<uint16_t>, A>, 2> widen(batch<uint16_t, A> const& x, requires_arch<wasm>) noexcept
1724+
{
1725+
return { batch<widen_t<uint16_t>, A>(wasm_u32x4_extend_low_u16x8(x)), batch<widen_t<uint16_t>, A>(wasm_u32x4_extend_high_u16x8(x)) };
1726+
}
1727+
template <class A>
1728+
XSIMD_INLINE std::array<batch<widen_t<int16_t>, A>, 2> widen(batch<int16_t, A> const& x, requires_arch<wasm>) noexcept
1729+
{
1730+
return { batch<widen_t<int16_t>, A>(wasm_i32x4_extend_low_i16x8(x)), batch<widen_t<int16_t>, A>(wasm_i32x4_extend_high_i16x8(x)) };
1731+
}
1732+
template <class A>
1733+
XSIMD_INLINE std::array<batch<widen_t<uint32_t>, A>, 2> widen(batch<uint32_t, A> const& x, requires_arch<wasm>) noexcept
1734+
{
1735+
return { batch<widen_t<uint32_t>, A>(wasm_u64x2_extend_low_u32x4(x)), batch<widen_t<uint32_t>, A>(wasm_u64x2_extend_high_u32x4(x)) };
1736+
}
1737+
template <class A>
1738+
XSIMD_INLINE std::array<batch<widen_t<int32_t>, A>, 2> widen(batch<int32_t, A> const& x, requires_arch<wasm>) noexcept
1739+
{
1740+
return { batch<widen_t<int32_t>, A>(wasm_i64x2_extend_low_i32x4(x)), batch<widen_t<int32_t>, A>(wasm_i64x2_extend_high_i32x4(x)) };
1741+
}
1742+
17041743
// zip_hi
17051744
template <class A>
17061745
XSIMD_INLINE batch<float, A> zip_hi(batch<float, A> const& self, batch<float, A> const& other, requires_arch<wasm>) noexcept

0 commit comments

Comments
 (0)