mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
LibWasm: Implement bitmask and float conversion instructions
(cherry picked from commit 146646b59741c1300461056e384dae50815d1621)
This commit is contained in:
parent
d00e37fa20
commit
c510c5375f
2 changed files with 59 additions and 8 deletions
|
@ -1700,24 +1700,30 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi
|
||||||
return pop_and_store_lane_n<32>(configuration, instruction);
|
return pop_and_store_lane_n<32>(configuration, instruction);
|
||||||
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():
|
||||||
|
return unary_operation<u128, u128, Operators::VectorFloatConvertOp<4, Operators::SaturatingTruncate<i32>>>(configuration);
|
||||||
|
case Instructions::i32x4_trunc_sat_f32x4_u.value():
|
||||||
|
return unary_operation<u128, u128, Operators::VectorFloatConvertOp<4, Operators::SaturatingTruncate<u32>>>(configuration);
|
||||||
|
case Instructions::i8x16_bitmask.value():
|
||||||
|
return unary_operation<u128, i32, Operators::VectorBitmask<16>>(configuration);
|
||||||
|
case Instructions::i16x8_bitmask.value():
|
||||||
|
return unary_operation<u128, i32, Operators::VectorBitmask<8>>(configuration);
|
||||||
|
case Instructions::i32x4_bitmask.value():
|
||||||
|
return unary_operation<u128, i32, Operators::VectorBitmask<4>>(configuration);
|
||||||
|
case Instructions::i64x2_bitmask.value():
|
||||||
|
return unary_operation<u128, i32, Operators::VectorBitmask<2>>(configuration);
|
||||||
case Instructions::f32x4_demote_f64x2_zero.value():
|
case Instructions::f32x4_demote_f64x2_zero.value():
|
||||||
case Instructions::f64x2_promote_low_f32x4.value():
|
case Instructions::f64x2_promote_low_f32x4.value():
|
||||||
case Instructions::i8x16_bitmask.value():
|
|
||||||
case Instructions::i8x16_narrow_i16x8_s.value():
|
case Instructions::i8x16_narrow_i16x8_s.value():
|
||||||
case Instructions::i8x16_narrow_i16x8_u.value():
|
case Instructions::i8x16_narrow_i16x8_u.value():
|
||||||
case Instructions::i16x8_q15mulr_sat_s.value():
|
case Instructions::i16x8_q15mulr_sat_s.value():
|
||||||
case Instructions::i16x8_bitmask.value():
|
|
||||||
case Instructions::i16x8_narrow_i32x4_s.value():
|
case Instructions::i16x8_narrow_i32x4_s.value():
|
||||||
case Instructions::i16x8_narrow_i32x4_u.value():
|
case Instructions::i16x8_narrow_i32x4_u.value():
|
||||||
case Instructions::i32x4_bitmask.value():
|
|
||||||
case Instructions::i32x4_dot_i16x8_s.value():
|
case Instructions::i32x4_dot_i16x8_s.value():
|
||||||
case Instructions::i64x2_bitmask.value():
|
|
||||||
case Instructions::i32x4_trunc_sat_f32x4_s.value():
|
|
||||||
case Instructions::i32x4_trunc_sat_f32x4_u.value():
|
|
||||||
case Instructions::f32x4_convert_i32x4_s.value():
|
|
||||||
case Instructions::f32x4_convert_i32x4_u.value():
|
|
||||||
case Instructions::i32x4_trunc_sat_f64x2_s_zero.value():
|
case Instructions::i32x4_trunc_sat_f64x2_s_zero.value():
|
||||||
case Instructions::i32x4_trunc_sat_f64x2_u_zero.value():
|
case Instructions::i32x4_trunc_sat_f64x2_u_zero.value():
|
||||||
|
case Instructions::f32x4_convert_i32x4_s.value():
|
||||||
|
case Instructions::f32x4_convert_i32x4_u.value():
|
||||||
case Instructions::f64x2_convert_low_i32x4_s.value():
|
case Instructions::f64x2_convert_low_i32x4_s.value():
|
||||||
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()));
|
dbgln_if(WASM_TRACE_DEBUG, "Instruction '{}' not implemented", instruction_name(instruction.opcode()));
|
||||||
|
|
|
@ -710,6 +710,23 @@ struct VectorIntegerBinaryOp {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<size_t VectorSize>
|
||||||
|
struct VectorBitmask {
|
||||||
|
auto operator()(u128 lhs) const
|
||||||
|
{
|
||||||
|
using VectorType = NativeVectorType<128 / VectorSize, VectorSize, MakeSigned>;
|
||||||
|
auto value = bit_cast<VectorType>(lhs);
|
||||||
|
u32 result = 0;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < VectorSize; ++i)
|
||||||
|
result |= static_cast<u32>(value[i] < 0) << i;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static StringView name() { return "bitmask"sv; }
|
||||||
|
};
|
||||||
|
|
||||||
template<size_t VectorSize, typename Op, template<typename> typename SetSign = MakeSigned>
|
template<size_t VectorSize, typename Op, template<typename> typename SetSign = MakeSigned>
|
||||||
struct VectorIntegerUnaryOp {
|
struct VectorIntegerUnaryOp {
|
||||||
auto operator()(u128 lhs) const
|
auto operator()(u128 lhs) const
|
||||||
|
@ -799,6 +816,34 @@ struct VectorFloatUnaryOp {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<size_t VectorSize, typename Op>
|
||||||
|
struct VectorFloatConvertOp {
|
||||||
|
auto operator()(u128 lhs) const
|
||||||
|
{
|
||||||
|
using VectorInput = NativeFloatingVectorType<128, VectorSize, NativeFloatingType<128 / VectorSize>>;
|
||||||
|
using VectorResult = NativeVectorType<128 / VectorSize, VectorSize, MakeUnsigned>;
|
||||||
|
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:
|
||||||
|
return "vecf(32x4).cvt_op"sv;
|
||||||
|
case 2:
|
||||||
|
return "vecf(64x2).cvt_op"sv;
|
||||||
|
default:
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct Floor {
|
struct Floor {
|
||||||
template<typename Lhs>
|
template<typename Lhs>
|
||||||
auto operator()(Lhs lhs) const
|
auto operator()(Lhs lhs) const
|
||||||
|
|
Loading…
Add table
Reference in a new issue