From 3c78269032071490bc13dc5dbac02567d4d491e0 Mon Sep 17 00:00:00 2001 From: Thomas Lively <7121787+tlively@users.noreply.github.com> Date: Thu, 3 Oct 2019 18:07:02 -0700 Subject: v8x16.swizzle (#2368) As specified at https://github.com/WebAssembly/simd/blob/master/proposals/simd/SIMD.md#swizzling-using-variable-indices. --- src/wasm/literal.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/wasm/literal.cpp') diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp index b382d1a3d..7f0c9fa6b 100644 --- a/src/wasm/literal.cpp +++ b/src/wasm/literal.cpp @@ -1867,4 +1867,15 @@ Literal Literal::widenHighUToVecI32x4() const { return widen<4, &Literal::getLanesUI16x8, LaneOrder::High>(*this); } +Literal Literal::swizzleVec8x16(const Literal& other) const { + auto lanes = getLanesUI8x16(); + auto indices = other.getLanesUI8x16(); + LaneArray<16> result; + for (size_t i = 0; i < 16; ++i) { + size_t index = indices[i].geti32(); + result[i] = index >= 16 ? Literal(int32_t(0)) : lanes[index]; + } + return Literal(result); +} + } // namespace wasm -- cgit v1.2.3