Skip to content

Commit 3ec56de

Browse files
Add support for xsimd::widen on WebAssembly
Related to #1179
1 parent f63bd07 commit 3ec56de

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

include/xsimd/arch/xsimd_wasm.hpp

Lines changed: 19 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,24 @@ 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+
17041723
// zip_hi
17051724
template <class A>
17061725
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)