diff --git a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp index 2360f0fa617..bf6cf86d708 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp @@ -1701,9 +1701,9 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi case Instructions::v128_store64_lane.value(): return pop_and_store_lane_n<64>(configuration, instruction); case Instructions::i32x4_trunc_sat_f32x4_s.value(): - return unary_operation>>(configuration); + return unary_operation>>(configuration); case Instructions::i32x4_trunc_sat_f32x4_u.value(): - return unary_operation>>(configuration); + return unary_operation>>(configuration); case Instructions::i8x16_bitmask.value(): return unary_operation>(configuration); case Instructions::i16x8_bitmask.value(): @@ -1725,18 +1725,21 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi case Instructions::i16x8_q15mulr_sat_s.value(): return binary_numeric_operation, MakeSigned>>(configuration); case Instructions::f32x4_convert_i32x4_s.value(): - return unary_operation, MakeSigned>>(configuration); + return unary_operation>>(configuration); case Instructions::f32x4_convert_i32x4_u.value(): - return unary_operation, MakeUnsigned>>(configuration); - case Instructions::f32x4_demote_f64x2_zero.value(): - case Instructions::f64x2_promote_low_f32x4.value(): - case Instructions::i32x4_trunc_sat_f64x2_s_zero.value(): - case Instructions::i32x4_trunc_sat_f64x2_u_zero.value(): + return unary_operation>>(configuration); case Instructions::f64x2_convert_low_i32x4_s.value(): + return unary_operation>>(configuration); case Instructions::f64x2_convert_low_i32x4_u.value(): - dbgln_if(WASM_TRACE_DEBUG, "Instruction '{}' not implemented", instruction_name(instruction.opcode())); - m_trap = Trap { ByteString::formatted("Unimplemented instruction {}", instruction_name(instruction.opcode())) }; - return; + return unary_operation>>(configuration); + case Instructions::f32x4_demote_f64x2_zero.value(): + return unary_operation>>(configuration); + case Instructions::f64x2_promote_low_f32x4.value(): + return unary_operation>>(configuration); + case Instructions::i32x4_trunc_sat_f64x2_s_zero.value(): + return unary_operation>>(configuration); + case Instructions::i32x4_trunc_sat_f64x2_u_zero.value(): + return unary_operation>>(configuration); } } diff --git a/Userland/Libraries/LibWasm/AbstractMachine/Operators.h b/Userland/Libraries/LibWasm/AbstractMachine/Operators.h index 2f765dc323d..9865ab425d0 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/Operators.h +++ b/Userland/Libraries/LibWasm/AbstractMachine/Operators.h @@ -882,51 +882,33 @@ struct VectorFloatUnaryOp { } }; -template -struct VectorFloatConvertOp { +template +struct VectorConvertOp { auto operator()(u128 lhs) const { - using VectorInput = NativeFloatingVectorType<128, VectorSize, NativeFloatingType<128 / VectorSize>>; - using VectorResult = NativeVectorType<128 / VectorSize, VectorSize, MakeUnsigned>; + using VectorInput = NativeVectorType<128 / InputSize, InputSize, MakeUnsigned>; + using VectorResult = NativeVectorType<128 / ResultSize, ResultSize, MakeUnsigned>; auto value = bit_cast(lhs); VectorResult result; Op op; - for (size_t i = 0; i < VectorSize; ++i) { - result[i] = op(value[i]); + auto size = min(InputSize, ResultSize); + for (size_t i = 0; i < size; ++i) + result[i] = bit_cast(op(bit_cast(value[i]))); + // FIXME: We shouldn't need this, but the auto-vectorizer sometimes doesn't see that we + // need to pad with zeroes when InputSize < ResultSize (i.e. converting from f64x2 -> f32x4). + // So we put this here to make sure. Putting [[clang::optnone]] over this function resolves + // this issue, but that would be pretty unacceptable... + if constexpr (InputSize < ResultSize) { + constexpr size_t remaining = ResultSize - InputSize; + for (size_t i = 0; i < remaining; ++i) + result[i + InputSize] = 0; } return bit_cast(result); } static StringView name() { - switch (VectorSize) { - case 4: - return "vecf(32x4).cvt_op"sv; - case 2: - return "vecf(64x2).cvt_op"sv; - default: - VERIFY_NOT_REACHED(); - } - } -}; - -template typename SetSign = MakeSigned> -struct VectorIntegerConvertOp { - auto operator()(u128 lhs) const - { - using VectorInput = NativeVectorType<128 / VectorSize, VectorSize, SetSign>; - using VectorResult = NativeFloatingVectorType<128, VectorSize, NativeFloatingType<128 / VectorSize>>; - auto value = bit_cast(lhs); - VectorResult result; - Op op; - for (size_t i = 0; i < VectorSize; ++i) - result[i] = op(value[i]); - return bit_cast(result); - } - - static StringView name() - { - switch (VectorSize) { + switch (ResultSize) { case 4: return "vec(32x4).cvt_op"sv; case 2: