Просмотр исходного кода

LibJS/JIT: Add Assembler::jump_if_equal()

And also factor out cmp() so we don't have to repeat it.
Andreas Kling 1 год назад
Родитель
Сommit
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);
     }
 
-    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) {
             emit8(0x48
                 | ((to_underlying(lhs.reg) >= 8) ? 1 << 2 : 0)
@@ -248,6 +247,22 @@ struct Assembler {
         } else {
             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)
         emit8(0x0f);