瀏覽代碼

LibJS/JIT: Add Assembler::jump_if_equal()

And also factor out cmp() so we don't have to repeat it.
Andreas Kling 1 年之前
父節點
當前提交
814b07a9c2
共有 1 個文件被更改,包括 17 次插入2 次删除
  1. 17 2
      Userland/Libraries/LibJS/JIT/Assembler.h

+ 17 - 2
Userland/Libraries/LibJS/JIT/Assembler.h

@@ -231,9 +231,8 @@ struct Assembler {
         jump(true_target);
         jump(true_target);
     }
     }
 
 
-    void jump_if_not_equal(Operand lhs, Operand rhs, Label& label)
+    void cmp(Operand lhs, Operand rhs)
     {
     {
-        // cmp lhs, rhs
         if (lhs.type == Operand::Type::Reg && rhs.type == Operand::Type::Reg) {
         if (lhs.type == Operand::Type::Reg && rhs.type == Operand::Type::Reg) {
             emit8(0x48
             emit8(0x48
                 | ((to_underlying(lhs.reg) >= 8) ? 1 << 2 : 0)
                 | ((to_underlying(lhs.reg) >= 8) ? 1 << 2 : 0)
@@ -248,6 +247,22 @@ struct Assembler {
         } else {
         } else {
             VERIFY_NOT_REACHED();
             VERIFY_NOT_REACHED();
         }
         }
+    }
+
+    void jump_if_equal(Operand lhs, Operand rhs, Label& label)
+    {
+        cmp(lhs, rhs);
+
+        // je label (RIP-relative 32-bit offset)
+        emit8(0x0f);
+        emit8(0x84);
+        emit32(0xdeadbeef);
+        label.offset_in_instruction_stream = m_output.size();
+    }
+
+    void jump_if_not_equal(Operand lhs, Operand rhs, Label& label)
+    {
+        cmp(lhs, rhs);
 
 
         // jne label (RIP-relative 32-bit offset)
         // jne label (RIP-relative 32-bit offset)
         emit8(0x0f);
         emit8(0x0f);