From d6756decb9adc7858ab3fa318ae3fd359d7e0e1d Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 27 Oct 2023 16:22:27 +0200 Subject: [PATCH] LibJS/JIT: Compile the JumpNullish bytecode instruction --- Userland/Libraries/LibJS/JIT/Compiler.cpp | 23 +++++++++++++++++++++++ Userland/Libraries/LibJS/JIT/Compiler.h | 1 + 2 files changed, 24 insertions(+) diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index 8d5e6cfd55..4e2e4ee23a 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -183,6 +183,26 @@ void Compiler::compile_jump_conditional(Bytecode::Op::JumpConditional const& op) m_assembler.jump(label_for(op.true_target()->block())); } +void Compiler::compile_jump_nullish(Bytecode::Op::JumpNullish const& op) +{ + load_vm_register(GPR0, Bytecode::Register::accumulator()); + + m_assembler.shift_right( + Assembler::Operand::Register(GPR0), + Assembler::Operand::Imm8(48)); + + m_assembler.bitwise_and( + Assembler::Operand::Register(GPR0), + Assembler::Operand::Imm32(IS_NULLISH_EXTRACT_PATTERN)); + + m_assembler.jump_if_equal( + Assembler::Operand::Register(GPR0), + Assembler::Operand::Imm32(IS_NULLISH_PATTERN), + label_for(op.true_target()->block())); + + m_assembler.jump(label_for(op.false_target()->block())); +} + [[maybe_unused]] static Value cxx_increment(VM& vm, Value value) { auto old_value = TRY_OR_SET_EXCEPTION(value.to_numeric(vm)); @@ -958,6 +978,9 @@ OwnPtr Compiler::compile(Bytecode::Executable& bytecode_execut case Bytecode::Instruction::Type::JumpConditional: compiler.compile_jump_conditional(static_cast(op)); break; + case Bytecode::Instruction::Type::JumpNullish: + compiler.compile_jump_nullish(static_cast(op)); + break; case Bytecode::Instruction::Type::Increment: compiler.compile_increment(static_cast(op)); break; diff --git a/Userland/Libraries/LibJS/JIT/Compiler.h b/Userland/Libraries/LibJS/JIT/Compiler.h index bba8980ee8..5606854b57 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.h +++ b/Userland/Libraries/LibJS/JIT/Compiler.h @@ -45,6 +45,7 @@ private: void compile_typeof_local(Bytecode::Op::TypeofLocal const&); void compile_jump(Bytecode::Op::Jump const&); void compile_jump_conditional(Bytecode::Op::JumpConditional const&); + void compile_jump_nullish(Bytecode::Op::JumpNullish const&); void compile_increment(Bytecode::Op::Increment const&); void compile_decrement(Bytecode::Op::Decrement const&); void compile_enter_unwind_context(Bytecode::Op::EnterUnwindContext const&);