From 814b07a9c25a033d71c9cdd3539899b46e09db92 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 17 Oct 2023 18:03:17 +0200 Subject: [PATCH] LibJS/JIT: Add Assembler::jump_if_equal() And also factor out cmp() so we don't have to repeat it. --- Userland/Libraries/LibJS/JIT/Assembler.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibJS/JIT/Assembler.h b/Userland/Libraries/LibJS/JIT/Assembler.h index 3e55192c2b..bb13c42ee9 100644 --- a/Userland/Libraries/LibJS/JIT/Assembler.h +++ b/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);