LibWasm: Fix some floating-point conversion issues

NaN bit patterns are now (hopefully) preserved. `static_cast` does not
preserve the bit pattern of a given NaN, so ideally we'd use some other
sort of cast and avoid `static_cast` altogether, but that's a large
change for this commit. For now, this fixes the issues found in spec
tests.
This commit is contained in:
Diego 2024-07-03 18:33:55 -07:00 committed by Ali Mohammad Pur
parent 6493acf2f4
commit c882498d44
Notes: sideshowbarker 2024-07-17 03:30:41 +09:00
2 changed files with 5 additions and 5 deletions

View file

@ -519,10 +519,10 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi
configuration.stack().push(Value(ValueType { ValueType::I64 }, instruction.arguments().get<i64>()));
return;
case Instructions::f32_const.value():
configuration.stack().push(Value(ValueType { ValueType::F32 }, static_cast<double>(instruction.arguments().get<float>())));
configuration.stack().push(Value(Value::AnyValueType(instruction.arguments().get<float>())));
return;
case Instructions::f64_const.value():
configuration.stack().push(Value(ValueType { ValueType::F64 }, instruction.arguments().get<double>()));
configuration.stack().push(Value(Value::AnyValueType(instruction.arguments().get<double>())));
return;
case Instructions::block.value(): {
size_t arity = 0;

View file

@ -652,8 +652,8 @@ struct Convert {
template<typename Lhs>
ResultT operator()(Lhs lhs) const
{
auto signed_interpretation = bit_cast<MakeSigned<Lhs>>(lhs);
return static_cast<ResultT>(signed_interpretation);
auto interpretation = bit_cast<Lhs>(lhs);
return static_cast<ResultT>(interpretation);
}
static StringView name() { return "convert"sv; }
@ -688,7 +688,7 @@ struct Demote {
return nanf(""); // FIXME: Ensure canonical NaN remains canonical
if (isinf(lhs))
return __builtin_huge_valf();
return copysignf(__builtin_huge_valf(), lhs);
return static_cast<float>(lhs);
}