From e41f0d9dec258297d62e649bd939a23a50e6f998 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 12 Nov 2023 14:42:37 +0100 Subject: [PATCH] LibJS/JIT: Add fast path for loose equality check between 2 objects There are more fast paths to be added here, just starting with this one since it's heavy on Kraken/ai-astar.js :^) --- Userland/Libraries/LibJS/JIT/Compiler.cpp | 45 +++++++++++++++++++++++ Userland/Libraries/LibJS/JIT/Compiler.h | 1 - 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index d332e369dc..9097e00ff8 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -618,6 +618,51 @@ static ThrowCompletionOr strict_equals(VM&, Value src1, Value src2) return Value(is_strictly_equal(src1, src2)); } +static Value cxx_loosely_equals(VM& vm, Value lhs, Value rhs) +{ + return TRY_OR_SET_EXCEPTION(loosely_equals(vm, lhs, rhs)); +} + +void Compiler::compile_loosely_equals(Bytecode::Op::LooselyEquals const& op) +{ + Assembler::Label end; + + load_vm_register(ARG1, op.lhs()); + load_accumulator(ARG2); + + // Fast path if both sides are objects. + branch_if_object(ARG1, [&] { + branch_if_object(ARG2, [&] { + Assembler::Label true_case; + + m_assembler.jump_if( + Assembler::Operand::Register(ARG1), + Assembler::Condition::EqualTo, + Assembler::Operand::Register(ARG2), + true_case); + + m_assembler.mov( + Assembler::Operand::Register(GPR0), + Assembler::Operand::Imm(Value(false).encoded())); + store_accumulator(GPR0); + m_assembler.jump(end); + + true_case.link(m_assembler); + m_assembler.mov( + Assembler::Operand::Register(GPR0), + Assembler::Operand::Imm(Value(true).encoded())); + store_accumulator(GPR0); + m_assembler.jump(end); + }); + }); + + native_call((void*)cxx_loosely_equals); + store_accumulator(RET); + check_exception(); + + end.link(m_assembler); +} + # define DO_COMPILE_COMMON_BINARY_OP(TitleCaseName, snake_case_name) \ static Value cxx_##snake_case_name(VM& vm, Value lhs, Value rhs) \ { \ diff --git a/Userland/Libraries/LibJS/JIT/Compiler.h b/Userland/Libraries/LibJS/JIT/Compiler.h index ae14ae046a..32a883c085 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.h +++ b/Userland/Libraries/LibJS/JIT/Compiler.h @@ -51,7 +51,6 @@ private: O(In, in) \ O(InstanceOf, instance_of) \ O(LooselyInequals, loosely_inequals) \ - O(LooselyEquals, loosely_equals) \ O(StrictlyInequals, strict_inequals) \ O(StrictlyEquals, strict_equals)