From 82635083dce6bc8949167d9fbb9038d11aca9b29 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 3 Nov 2023 08:47:35 +0100 Subject: [PATCH] LibJS/JIT: Add fast path for Int32 & Int32 --- Userland/Libraries/LibJS/JIT/Compiler.cpp | 29 +++++++++++++++++++++++ Userland/Libraries/LibJS/JIT/Compiler.h | 1 - 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index 0f3bf2250b..7c11ac4b9b 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -626,6 +626,35 @@ void Compiler::compile_less_than(Bytecode::Op::LessThan const& op) end.link(m_assembler); } +static Value cxx_bitwise_and(VM& vm, Value lhs, Value rhs) +{ + return TRY_OR_SET_EXCEPTION(bitwise_and(vm, lhs, rhs)); +} + +void Compiler::compile_bitwise_and(Bytecode::Op::BitwiseAnd const& op) +{ + load_vm_register(ARG1, op.lhs()); + load_accumulator(ARG2); + + Assembler::Label end {}; + + branch_if_both_int32(ARG1, ARG2, [&] { + // NOTE: Since both sides are Int32, we know that the upper 32 bits are nothing but the INT32_TAG. + // This means we can get away with just a simple 64-bit bitwise and. + m_assembler.bitwise_and( + Assembler::Operand::Register(ARG1), + Assembler::Operand::Register(ARG2)); + + store_accumulator(ARG1); + m_assembler.jump(end); + }); + + native_call((void*)cxx_bitwise_and); + store_accumulator(RET); + check_exception(); + end.link(m_assembler); +} + static ThrowCompletionOr not_(VM&, Value value) { return Value(!value.to_boolean()); diff --git a/Userland/Libraries/LibJS/JIT/Compiler.h b/Userland/Libraries/LibJS/JIT/Compiler.h index ebf5f3b8e8..dfc1a0fdef 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.h +++ b/Userland/Libraries/LibJS/JIT/Compiler.h @@ -54,7 +54,6 @@ private: O(LooselyEquals, abstract_equals) \ O(StrictlyInequals, typed_inequals) \ O(StrictlyEquals, typed_equals) \ - O(BitwiseAnd, bitwise_and) \ O(BitwiseOr, bitwise_or) \ O(BitwiseXor, bitwise_xor) \ O(LeftShift, left_shift) \