From c882498d4450c4c2e46d77a8ab36afc4eb412c00 Mon Sep 17 00:00:00 2001 From: Diego <96022404+dzfrias@users.noreply.github.com> Date: Wed, 3 Jul 2024 18:33:55 -0700 Subject: [PATCH] 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. --- .../LibWasm/AbstractMachine/BytecodeInterpreter.cpp | 4 ++-- Userland/Libraries/LibWasm/AbstractMachine/Operators.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp index 96a556b0694..167e5ad47c3 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp @@ -519,10 +519,10 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi configuration.stack().push(Value(ValueType { ValueType::I64 }, instruction.arguments().get())); return; case Instructions::f32_const.value(): - configuration.stack().push(Value(ValueType { ValueType::F32 }, static_cast(instruction.arguments().get()))); + configuration.stack().push(Value(Value::AnyValueType(instruction.arguments().get()))); return; case Instructions::f64_const.value(): - configuration.stack().push(Value(ValueType { ValueType::F64 }, instruction.arguments().get())); + configuration.stack().push(Value(Value::AnyValueType(instruction.arguments().get()))); return; case Instructions::block.value(): { size_t arity = 0; diff --git a/Userland/Libraries/LibWasm/AbstractMachine/Operators.h b/Userland/Libraries/LibWasm/AbstractMachine/Operators.h index c0b5a529818..4364bee6537 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/Operators.h +++ b/Userland/Libraries/LibWasm/AbstractMachine/Operators.h @@ -652,8 +652,8 @@ struct Convert { template ResultT operator()(Lhs lhs) const { - auto signed_interpretation = bit_cast>(lhs); - return static_cast(signed_interpretation); + auto interpretation = bit_cast(lhs); + return static_cast(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(lhs); }