diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-06-09 17:12:56 +0430 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-06-09 23:05:32 +0430 |
commit | a4c4dd928b1ac19f61fc0400a1f36e7ff4d223ee (patch) | |
tree | bfc50e26bd11af6e75d2f03f6fac2294be281176 /Userland/Libraries/LibWasm | |
parent | ccc79149d48f42e8090bffc5aad24f7cbf3fff81 (diff) | |
download | serenity-a4c4dd928b1ac19f61fc0400a1f36e7ff4d223ee.zip |
LibWasm: Implement spec-compliant float min/max ops
Diffstat (limited to 'Userland/Libraries/LibWasm')
-rw-r--r-- | Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp index 699aed649a..ed295dafd8 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp @@ -396,6 +396,34 @@ ALWAYS_INLINE static i32 ctz(T value) VERIFY_NOT_REACHED(); } +template<typename T> +ALWAYS_INLINE static T float_max(T lhs, T rhs) +{ + if (isnan(lhs)) + return lhs; + if (isnan(rhs)) + return rhs; + if (isinf(lhs)) + return lhs > 0 ? lhs : rhs; + if (isinf(rhs)) + return rhs > 0 ? rhs : lhs; + return max(lhs, rhs); +} + +template<typename T> +ALWAYS_INLINE static T float_min(T lhs, T rhs) +{ + if (isnan(lhs)) + return lhs; + if (isnan(rhs)) + return rhs; + if (isinf(lhs)) + return lhs > 0 ? rhs : lhs; + if (isinf(rhs)) + return rhs > 0 ? lhs : rhs; + return min(lhs, rhs); +} + void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPointer& ip, Instruction const& instruction) { dbgln_if(WASM_TRACE_DEBUG, "Executing instruction {} at ip {}", instruction_name(instruction.opcode()), ip.value()); @@ -843,9 +871,9 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi case Instructions::f32_div.value(): BINARY_NUMERIC_OPERATION(float, /, float); case Instructions::f32_min.value(): - BINARY_PREFIX_NUMERIC_OPERATION(float, min, float); + BINARY_PREFIX_NUMERIC_OPERATION(float, float_min, float); case Instructions::f32_max.value(): - BINARY_PREFIX_NUMERIC_OPERATION(float, max, float); + BINARY_PREFIX_NUMERIC_OPERATION(float, float_max, float); case Instructions::f32_copysign.value(): BINARY_PREFIX_NUMERIC_OPERATION(float, copysignf, float); case Instructions::f64_abs.value(): @@ -871,9 +899,9 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi case Instructions::f64_div.value(): BINARY_NUMERIC_OPERATION(double, /, double); case Instructions::f64_min.value(): - BINARY_PREFIX_NUMERIC_OPERATION(double, min, double); + BINARY_PREFIX_NUMERIC_OPERATION(double, float_min, double); case Instructions::f64_max.value(): - BINARY_PREFIX_NUMERIC_OPERATION(double, max, double); + BINARY_PREFIX_NUMERIC_OPERATION(double, float_max, double); case Instructions::f64_copysign.value(): BINARY_PREFIX_NUMERIC_OPERATION(double, copysign, double); case Instructions::i32_wrap_i64.value(): |