From f6f27fb6bbe8658c6f8dbad241e2e6c7b1d1b546 Mon Sep 17 00:00:00 2001 From: Hendiadyoin1 Date: Sat, 8 Jun 2024 16:47:27 +0200 Subject: [PATCH] LibWasm: Use `shuffle_or_0` in for vector swizzles and shuffles Otherwise we'd hit a VERIFY in AK::SIMD::shuffle() when that operand contains an out-of-range value, the spec tests indicate that a swizzle with an out-of-range index should return 0. (cherry picked from commit cd454a1e3d0bc8b3342ed39891c9b27409ecc829) --- .../LibWasm/AbstractMachine/BytecodeInterpreter.cpp | 2 +- Userland/Libraries/LibWasm/AbstractMachine/Operators.h | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp index 9e73f26377d..4e3fb8e0071 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp @@ -254,7 +254,7 @@ static u128 shuffle_vector(VectorType values, VectorType indices) { auto vector = bit_cast(values); auto indices_vector = bit_cast(indices); - return bit_cast(shuffle(vector, indices_vector)); + return bit_cast(shuffle_or_0(vector, indices_vector)); } void BytecodeInterpreter::call_address(Configuration& configuration, FunctionAddress address) diff --git a/Userland/Libraries/LibWasm/AbstractMachine/Operators.h b/Userland/Libraries/LibWasm/AbstractMachine/Operators.h index 62c635ca999..38d97272ec9 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/Operators.h +++ b/Userland/Libraries/LibWasm/AbstractMachine/Operators.h @@ -10,8 +10,10 @@ #include #include #include +#include #include #include +#include #include #include @@ -192,7 +194,7 @@ struct VectorSwizzle { // https://webassembly.github.io/spec/core/bikeshed/#-mathsfi8x16hrefsyntax-instr-vecmathsfswizzle%E2%91%A0 auto i = bit_cast>(c2); auto j = bit_cast>(c1); - auto result = AK::SIMD::shuffle(i, j); + auto result = shuffle_or_0(i, j); return bit_cast(result); } static StringView name() { return "vec(8x16).swizzle"sv; } @@ -761,5 +763,4 @@ struct SaturatingTruncate { static StringView name() { return "truncate.saturating"sv; } }; - }