Skip to content

Commit

Permalink
LibWasm: Use shuffle_or_0 in for vector swizzles and shuffles
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
Hendiadyoin1 authored and alimpfard committed Jul 14, 2024
1 parent 42f0665 commit f6f27fb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ static u128 shuffle_vector(VectorType values, VectorType indices)
{
auto vector = bit_cast<VectorType>(values);
auto indices_vector = bit_cast<VectorType>(indices);
return bit_cast<u128>(shuffle(vector, indices_vector));
return bit_cast<u128>(shuffle_or_0(vector, indices_vector));
}

void BytecodeInterpreter::call_address(Configuration& configuration, FunctionAddress address)
Expand Down
5 changes: 3 additions & 2 deletions Userland/Libraries/LibWasm/AbstractMachine/Operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
#include <AK/BuiltinWrappers.h>
#include <AK/Result.h>
#include <AK/SIMD.h>
#include <AK/SIMDExtras.h>
#include <AK/StringView.h>
#include <AK/Types.h>
#include <LibWasm/Types.h>
#include <limits.h>
#include <math.h>

Expand Down Expand Up @@ -192,7 +194,7 @@ struct VectorSwizzle {
// https://webassembly.github.io/spec/core/bikeshed/#-mathsfi8x16hrefsyntax-instr-vecmathsfswizzle%E2%91%A0
auto i = bit_cast<Native128ByteVectorOf<i8, MakeSigned>>(c2);
auto j = bit_cast<Native128ByteVectorOf<i8, MakeSigned>>(c1);
auto result = AK::SIMD::shuffle(i, j);
auto result = shuffle_or_0(i, j);
return bit_cast<u128>(result);
}
static StringView name() { return "vec(8x16).swizzle"sv; }
Expand Down Expand Up @@ -761,5 +763,4 @@ struct SaturatingTruncate {

static StringView name() { return "truncate.saturating"sv; }
};

}

0 comments on commit f6f27fb

Please sign in to comment.