From 2c7e2e351aa2c40daedfd8ddac3ef868ebac0f2c Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Mon, 30 Aug 2021 16:21:21 +0430 Subject: [PATCH] LibWasm: Implement fx.nearest using nearbyint() instead of round() This instruction wants RoundingMode::ToEven, so let's use the correct function. --- .../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 a8f0301bdd..d472da2f96 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp @@ -824,7 +824,7 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi case Instructions::f32_trunc.value(): return unary_operation(configuration); case Instructions::f32_nearest.value(): - return unary_operation(configuration); + return unary_operation(configuration); case Instructions::f32_sqrt.value(): return unary_operation(configuration); case Instructions::f32_add.value(): @@ -852,7 +852,7 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi case Instructions::f64_trunc.value(): return unary_operation(configuration); case Instructions::f64_nearest.value(): - return unary_operation(configuration); + return unary_operation(configuration); case Instructions::f64_sqrt.value(): return unary_operation(configuration); case Instructions::f64_add.value(): diff --git a/Userland/Libraries/LibWasm/AbstractMachine/Operators.h b/Userland/Libraries/LibWasm/AbstractMachine/Operators.h index ecb13f37e7..aac34ce7c6 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/Operators.h +++ b/Userland/Libraries/LibWasm/AbstractMachine/Operators.h @@ -271,14 +271,14 @@ struct Truncate { static StringView name() { return "truncate"; } }; -struct Round { +struct NearbyIntegral { template auto operator()(Lhs lhs) const { if constexpr (IsSame) - return roundf(lhs); + return nearbyintf(lhs); else if constexpr (IsSame) - return round(lhs); + return nearbyint(lhs); else VERIFY_NOT_REACHED(); }