Procházet zdrojové kódy

LibJS/JIT: Compile the JumpNullish bytecode instruction

Andreas Kling před 1 rokem
rodič
revize
d6756decb9

+ 23 - 0
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<NativeExecutable> Compiler::compile(Bytecode::Executable& bytecode_execut
             case Bytecode::Instruction::Type::JumpConditional:
                 compiler.compile_jump_conditional(static_cast<Bytecode::Op::JumpConditional const&>(op));
                 break;
+            case Bytecode::Instruction::Type::JumpNullish:
+                compiler.compile_jump_nullish(static_cast<Bytecode::Op::JumpNullish const&>(op));
+                break;
             case Bytecode::Instruction::Type::Increment:
                 compiler.compile_increment(static_cast<Bytecode::Op::Increment const&>(op));
                 break;

+ 1 - 0
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&);