From 56ba869c57de54391d69970f2d684be87889f9ff Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Sun, 18 Feb 2024 06:16:44 +0330 Subject: [PATCH] LibWasm: Implement all remaining comparison SIMD instructions --- .../AbstractMachine/BytecodeInterpreter.cpp | 42 ++++++++++++++ .../LibWasm/AbstractMachine/Operators.h | 57 +++++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp index f75018d8af..af61128e24 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp @@ -1272,47 +1272,89 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi case Instructions::f64x2_replace_lane.value(): return binary_numeric_operation, double>(configuration, instruction.arguments().get().lane); case Instructions::i8x16_eq.value(): + return binary_numeric_operation>(configuration); case Instructions::i8x16_ne.value(): + return binary_numeric_operation>(configuration); case Instructions::i8x16_lt_s.value(): + return binary_numeric_operation>(configuration); case Instructions::i8x16_lt_u.value(): + return binary_numeric_operation>(configuration); case Instructions::i8x16_gt_s.value(): + return binary_numeric_operation>(configuration); case Instructions::i8x16_gt_u.value(): + return binary_numeric_operation>(configuration); case Instructions::i8x16_le_s.value(): + return binary_numeric_operation>(configuration); case Instructions::i8x16_le_u.value(): + return binary_numeric_operation>(configuration); case Instructions::i8x16_ge_s.value(): + return binary_numeric_operation>(configuration); case Instructions::i8x16_ge_u.value(): + return binary_numeric_operation>(configuration); case Instructions::i16x8_eq.value(): + return binary_numeric_operation>(configuration); case Instructions::i16x8_ne.value(): + return binary_numeric_operation>(configuration); case Instructions::i16x8_lt_s.value(): + return binary_numeric_operation>(configuration); case Instructions::i16x8_lt_u.value(): + return binary_numeric_operation>(configuration); case Instructions::i16x8_gt_s.value(): + return binary_numeric_operation>(configuration); case Instructions::i16x8_gt_u.value(): + return binary_numeric_operation>(configuration); case Instructions::i16x8_le_s.value(): + return binary_numeric_operation>(configuration); case Instructions::i16x8_le_u.value(): + return binary_numeric_operation>(configuration); case Instructions::i16x8_ge_s.value(): + return binary_numeric_operation>(configuration); case Instructions::i16x8_ge_u.value(): + return binary_numeric_operation>(configuration); case Instructions::i32x4_eq.value(): + return binary_numeric_operation>(configuration); case Instructions::i32x4_ne.value(): + return binary_numeric_operation>(configuration); case Instructions::i32x4_lt_s.value(): + return binary_numeric_operation>(configuration); case Instructions::i32x4_lt_u.value(): + return binary_numeric_operation>(configuration); case Instructions::i32x4_gt_s.value(): + return binary_numeric_operation>(configuration); case Instructions::i32x4_gt_u.value(): + return binary_numeric_operation>(configuration); case Instructions::i32x4_le_s.value(): + return binary_numeric_operation>(configuration); case Instructions::i32x4_le_u.value(): + return binary_numeric_operation>(configuration); case Instructions::i32x4_ge_s.value(): + return binary_numeric_operation>(configuration); case Instructions::i32x4_ge_u.value(): + return binary_numeric_operation>(configuration); case Instructions::f32x4_eq.value(): + return binary_numeric_operation>(configuration); case Instructions::f32x4_ne.value(): + return binary_numeric_operation>(configuration); case Instructions::f32x4_lt.value(): + return binary_numeric_operation>(configuration); case Instructions::f32x4_gt.value(): + return binary_numeric_operation>(configuration); case Instructions::f32x4_le.value(): + return binary_numeric_operation>(configuration); case Instructions::f32x4_ge.value(): + return binary_numeric_operation>(configuration); case Instructions::f64x2_eq.value(): + return binary_numeric_operation>(configuration); case Instructions::f64x2_ne.value(): + return binary_numeric_operation>(configuration); case Instructions::f64x2_lt.value(): + return binary_numeric_operation>(configuration); case Instructions::f64x2_gt.value(): + return binary_numeric_operation>(configuration); case Instructions::f64x2_le.value(): + return binary_numeric_operation>(configuration); case Instructions::f64x2_ge.value(): + return binary_numeric_operation>(configuration); case Instructions::v128_not.value(): case Instructions::v128_and.value(): case Instructions::v128_andnot.value(): diff --git a/Userland/Libraries/LibWasm/AbstractMachine/Operators.h b/Userland/Libraries/LibWasm/AbstractMachine/Operators.h index 35e862685d..20542e7dce 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/Operators.h +++ b/Userland/Libraries/LibWasm/AbstractMachine/Operators.h @@ -267,6 +267,63 @@ struct VectorReplaceLane { } }; +template typename SetSign = MakeSigned> +struct VectorCmpOp { + auto operator()(u128 c1, u128 c2) const + { + using ElementType = NativeIntegralType<128 / VectorSize>; + auto result = bit_cast>(c1); + auto other = bit_cast>(c2); + Op op; + for (size_t i = 0; i < VectorSize; ++i) + result[i] = op(result[i], other[i]) ? static_cast>(-1) : 0; + return bit_cast(result); + } + + static StringView name() + { + switch (VectorSize) { + case 16: + return "vec(8x16).cmp"sv; + case 8: + return "vec(16x8).cmp"sv; + case 4: + return "vec(32x4).cmp"sv; + case 2: + return "vec(64x2).cmp"sv; + default: + VERIFY_NOT_REACHED(); + } + } +}; + +template +struct VectorFloatCmpOp { + auto operator()(u128 c1, u128 c2) const + { + auto first = bit_cast>>(c1); + auto other = bit_cast>>(c2); + using ElementType = NativeIntegralType<128 / VectorSize>; + Native128ByteVectorOf result; + Op op; + for (size_t i = 0; i < VectorSize; ++i) + result[i] = op(first[i], other[i]) ? static_cast(-1) : 0; + return bit_cast(result); + } + + static StringView name() + { + switch (VectorSize) { + case 4: + return "vecf(32x4).cmp"sv; + case 2: + return "vecf(64x2).cmp"sv; + default: + VERIFY_NOT_REACHED(); + } + } +}; + struct Minimum { template auto operator()(Lhs lhs, Rhs rhs) const