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:
parent
6493acf2f4
commit
c882498d44
Notes:
sideshowbarker
2024-07-17 03:30:41 +09:00
Author: https://github.com/dzfrias Commit: https://github.com/LadybirdBrowser/ladybird/commit/c882498d44 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/459 Reviewed-by: https://github.com/alimpfard
2 changed files with 5 additions and 5 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue