From 625fbc8085debf5f145ec1e9de24854fc9573834 Mon Sep 17 00:00:00 2001 From: Diego <96022404+dzfrias@users.noreply.github.com> Date: Wed, 10 Jul 2024 13:42:46 -0700 Subject: [PATCH] LibWasm: Implement SIMD bitwise operations --- .../AbstractMachine/BytecodeInterpreter.cpp | 18 +++++++++++++++--- .../LibWasm/AbstractMachine/Operators.h | 14 ++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp index 167e5ad47c3..e92466d195f 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp @@ -1548,12 +1548,24 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi return unary_operation>(configuration); case Instructions::f64x2_abs.value(): return unary_operation>(configuration); - case Instructions::v128_not.value(): case Instructions::v128_and.value(): - case Instructions::v128_andnot.value(): + return binary_numeric_operation(configuration); case Instructions::v128_or.value(): + return binary_numeric_operation(configuration); case Instructions::v128_xor.value(): - case Instructions::v128_bitselect.value(): + return binary_numeric_operation(configuration); + case Instructions::v128_not.value(): + return unary_operation(configuration); + case Instructions::v128_andnot.value(): + return binary_numeric_operation(configuration); + case Instructions::v128_bitselect.value(): { + auto mask = *configuration.stack().pop().get().to(); + auto false_vector = *configuration.stack().pop().get().to(); + auto true_vector = *configuration.stack().pop().get().to(); + u128 result = (true_vector & mask) | (false_vector & ~mask); + configuration.stack().push(Value(result)); + return; + } case Instructions::v128_any_true.value(): case Instructions::v128_load8_lane.value(): case Instructions::v128_load16_lane.value(): diff --git a/Userland/Libraries/LibWasm/AbstractMachine/Operators.h b/Userland/Libraries/LibWasm/AbstractMachine/Operators.h index d3bfb90a5bd..76f78795de9 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/Operators.h +++ b/Userland/Libraries/LibWasm/AbstractMachine/Operators.h @@ -96,6 +96,20 @@ struct BitShiftRight { static StringView name() { return ">>"sv; } }; +struct BitAndNot { + template + auto operator()(Lhs lhs, Rhs rhs) const { return lhs & ~rhs; } + + static StringView name() { return "andnot"sv; } +}; + +struct BitNot { + template + auto operator()(Lhs lhs) const { return ~lhs; } + + static StringView name() { return "~"sv; } +}; + struct BitRotateLeft { template auto operator()(Lhs lhs, Rhs rhs) const