mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-24 18:02:20 +00:00
LibWasm: Implement the rest of the SIMD conversions
This commit is contained in:
parent
21c5084d23
commit
4b9649282e
Notes:
github-actions[bot]
2024-07-20 09:18:27 +00:00
Author: https://github.com/dzfrias
Commit: 4b9649282e
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/719
Reviewed-by: https://github.com/alimpfard
2 changed files with 30 additions and 45 deletions
|
@ -1701,9 +1701,9 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi
|
||||||
case Instructions::v128_store64_lane.value():
|
case Instructions::v128_store64_lane.value():
|
||||||
return pop_and_store_lane_n<64>(configuration, instruction);
|
return pop_and_store_lane_n<64>(configuration, instruction);
|
||||||
case Instructions::i32x4_trunc_sat_f32x4_s.value():
|
case Instructions::i32x4_trunc_sat_f32x4_s.value():
|
||||||
return unary_operation<u128, u128, Operators::VectorFloatConvertOp<4, Operators::SaturatingTruncate<i32>>>(configuration);
|
return unary_operation<u128, u128, Operators::VectorConvertOp<4, 4, u32, f32, Operators::SaturatingTruncate<i32>>>(configuration);
|
||||||
case Instructions::i32x4_trunc_sat_f32x4_u.value():
|
case Instructions::i32x4_trunc_sat_f32x4_u.value():
|
||||||
return unary_operation<u128, u128, Operators::VectorFloatConvertOp<4, Operators::SaturatingTruncate<u32>>>(configuration);
|
return unary_operation<u128, u128, Operators::VectorConvertOp<4, 4, u32, f32, Operators::SaturatingTruncate<u32>>>(configuration);
|
||||||
case Instructions::i8x16_bitmask.value():
|
case Instructions::i8x16_bitmask.value():
|
||||||
return unary_operation<u128, i32, Operators::VectorBitmask<16>>(configuration);
|
return unary_operation<u128, i32, Operators::VectorBitmask<16>>(configuration);
|
||||||
case Instructions::i16x8_bitmask.value():
|
case Instructions::i16x8_bitmask.value():
|
||||||
|
@ -1725,18 +1725,21 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi
|
||||||
case Instructions::i16x8_q15mulr_sat_s.value():
|
case Instructions::i16x8_q15mulr_sat_s.value():
|
||||||
return binary_numeric_operation<u128, u128, Operators::VectorIntegerBinaryOp<8, Operators::SaturatingOp<i16, Operators::Q15Mul>, MakeSigned>>(configuration);
|
return binary_numeric_operation<u128, u128, Operators::VectorIntegerBinaryOp<8, Operators::SaturatingOp<i16, Operators::Q15Mul>, MakeSigned>>(configuration);
|
||||||
case Instructions::f32x4_convert_i32x4_s.value():
|
case Instructions::f32x4_convert_i32x4_s.value():
|
||||||
return unary_operation<u128, u128, Operators::VectorIntegerConvertOp<4, Operators::Convert<f32>, MakeSigned>>(configuration);
|
return unary_operation<u128, u128, Operators::VectorConvertOp<4, 4, u32, i32, Operators::Convert<f32>>>(configuration);
|
||||||
case Instructions::f32x4_convert_i32x4_u.value():
|
case Instructions::f32x4_convert_i32x4_u.value():
|
||||||
return unary_operation<u128, u128, Operators::VectorIntegerConvertOp<4, Operators::Convert<f32>, MakeUnsigned>>(configuration);
|
return unary_operation<u128, u128, Operators::VectorConvertOp<4, 4, u32, u32, Operators::Convert<f32>>>(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():
|
|
||||||
case Instructions::f64x2_convert_low_i32x4_s.value():
|
case Instructions::f64x2_convert_low_i32x4_s.value():
|
||||||
|
return unary_operation<u128, u128, Operators::VectorConvertOp<2, 4, u64, i32, Operators::Convert<f64>>>(configuration);
|
||||||
case Instructions::f64x2_convert_low_i32x4_u.value():
|
case Instructions::f64x2_convert_low_i32x4_u.value():
|
||||||
dbgln_if(WASM_TRACE_DEBUG, "Instruction '{}' not implemented", instruction_name(instruction.opcode()));
|
return unary_operation<u128, u128, Operators::VectorConvertOp<2, 4, u64, u32, Operators::Convert<f64>>>(configuration);
|
||||||
m_trap = Trap { ByteString::formatted("Unimplemented instruction {}", instruction_name(instruction.opcode())) };
|
case Instructions::f32x4_demote_f64x2_zero.value():
|
||||||
return;
|
return unary_operation<u128, u128, Operators::VectorConvertOp<4, 2, u32, f64, Operators::Convert<f32>>>(configuration);
|
||||||
|
case Instructions::f64x2_promote_low_f32x4.value():
|
||||||
|
return unary_operation<u128, u128, Operators::VectorConvertOp<2, 4, u64, f32, Operators::Convert<f64>>>(configuration);
|
||||||
|
case Instructions::i32x4_trunc_sat_f64x2_s_zero.value():
|
||||||
|
return unary_operation<u128, u128, Operators::VectorConvertOp<4, 2, u32, f64, Operators::SaturatingTruncate<i32>>>(configuration);
|
||||||
|
case Instructions::i32x4_trunc_sat_f64x2_u_zero.value():
|
||||||
|
return unary_operation<u128, u128, Operators::VectorConvertOp<4, 2, u32, f64, Operators::SaturatingTruncate<u32>>>(configuration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -882,51 +882,33 @@ struct VectorFloatUnaryOp {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<size_t VectorSize, typename Op>
|
template<size_t ResultSize, size_t InputSize, typename ResultType, typename InputType, typename Op>
|
||||||
struct VectorFloatConvertOp {
|
struct VectorConvertOp {
|
||||||
auto operator()(u128 lhs) const
|
auto operator()(u128 lhs) const
|
||||||
{
|
{
|
||||||
using VectorInput = NativeFloatingVectorType<128, VectorSize, NativeFloatingType<128 / VectorSize>>;
|
using VectorInput = NativeVectorType<128 / InputSize, InputSize, MakeUnsigned>;
|
||||||
using VectorResult = NativeVectorType<128 / VectorSize, VectorSize, MakeUnsigned>;
|
using VectorResult = NativeVectorType<128 / ResultSize, ResultSize, MakeUnsigned>;
|
||||||
auto value = bit_cast<VectorInput>(lhs);
|
auto value = bit_cast<VectorInput>(lhs);
|
||||||
VectorResult result;
|
VectorResult result;
|
||||||
Op op;
|
Op op;
|
||||||
for (size_t i = 0; i < VectorSize; ++i) {
|
auto size = min(InputSize, ResultSize);
|
||||||
result[i] = op(value[i]);
|
for (size_t i = 0; i < size; ++i)
|
||||||
|
result[i] = bit_cast<ResultType>(op(bit_cast<InputType>(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<u128>(result);
|
return bit_cast<u128>(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static StringView name()
|
static StringView name()
|
||||||
{
|
{
|
||||||
switch (VectorSize) {
|
switch (ResultSize) {
|
||||||
case 4:
|
|
||||||
return "vecf(32x4).cvt_op"sv;
|
|
||||||
case 2:
|
|
||||||
return "vecf(64x2).cvt_op"sv;
|
|
||||||
default:
|
|
||||||
VERIFY_NOT_REACHED();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<size_t VectorSize, typename Op, template<typename> 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<VectorInput>(lhs);
|
|
||||||
VectorResult result;
|
|
||||||
Op op;
|
|
||||||
for (size_t i = 0; i < VectorSize; ++i)
|
|
||||||
result[i] = op(value[i]);
|
|
||||||
return bit_cast<u128>(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
static StringView name()
|
|
||||||
{
|
|
||||||
switch (VectorSize) {
|
|
||||||
case 4:
|
case 4:
|
||||||
return "vec(32x4).cvt_op"sv;
|
return "vec(32x4).cvt_op"sv;
|
||||||
case 2:
|
case 2:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue