mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-22 09:18:55 +00:00
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: 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>()));
|
configuration.stack().push(Value(ValueType { ValueType::I64 }, instruction.arguments().get<i64>()));
|
||||||
return;
|
return;
|
||||||
case Instructions::f32_const.value():
|
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;
|
return;
|
||||||
case Instructions::f64_const.value():
|
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;
|
return;
|
||||||
case Instructions::block.value(): {
|
case Instructions::block.value(): {
|
||||||
size_t arity = 0;
|
size_t arity = 0;
|
||||||
|
|
|
@ -652,8 +652,8 @@ struct Convert {
|
||||||
template<typename Lhs>
|
template<typename Lhs>
|
||||||
ResultT operator()(Lhs lhs) const
|
ResultT operator()(Lhs lhs) const
|
||||||
{
|
{
|
||||||
auto signed_interpretation = bit_cast<MakeSigned<Lhs>>(lhs);
|
auto interpretation = bit_cast<Lhs>(lhs);
|
||||||
return static_cast<ResultT>(signed_interpretation);
|
return static_cast<ResultT>(interpretation);
|
||||||
}
|
}
|
||||||
|
|
||||||
static StringView name() { return "convert"sv; }
|
static StringView name() { return "convert"sv; }
|
||||||
|
@ -688,7 +688,7 @@ struct Demote {
|
||||||
return nanf(""); // FIXME: Ensure canonical NaN remains canonical
|
return nanf(""); // FIXME: Ensure canonical NaN remains canonical
|
||||||
|
|
||||||
if (isinf(lhs))
|
if (isinf(lhs))
|
||||||
return __builtin_huge_valf();
|
return copysignf(__builtin_huge_valf(), lhs);
|
||||||
|
|
||||||
return static_cast<float>(lhs);
|
return static_cast<float>(lhs);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue