LibJS/JIT: Add increment instruction

Instead of using `Add` with an immediate of 1 use the `Inc` instruction
This commit is contained in:
Stephan Vedder 2023-11-07 16:56:02 +01:00 committed by Andreas Kling
parent e122039c99
commit 0e69f744df
Notes: sideshowbarker 2024-07-17 01:46:43 +09:00
2 changed files with 26 additions and 19 deletions

View file

@ -742,6 +742,21 @@ struct X86_64Assembler {
}
}
void inc32(Operand op, Optional<Label&> overflow_label)
{
if (op.is_register_or_memory()) {
emit_rex_for_slash(op, REX_W::No);
emit8(0xff);
emit_modrm_slash(0, op);
} else {
VERIFY_NOT_REACHED();
}
if (overflow_label.has_value()) {
jump_if(Condition::Overflow, *overflow_label);
}
}
void add(Operand dst, Operand src)
{
if (dst.is_register_or_memory() && src.type == Operand::Type::Reg) {

View file

@ -356,31 +356,23 @@ void Compiler::compile_increment(Bytecode::Op::Increment const&)
Assembler::Label slow_case {};
branch_if_int32(ARG1, [&] {
// GPR0 = ARG1 & 0xffffffff;
// GPR0 = ARG1
m_assembler.mov(
Assembler::Operand::Register(GPR0),
Assembler::Operand::Register(ARG1));
m_assembler.mov(
Assembler::Operand::Register(GPR1),
Assembler::Operand::Imm(0xffffffff));
m_assembler.bitwise_and(
// GPR0++;
m_assembler.inc32(
Assembler::Operand::Register(GPR0),
Assembler::Operand::Register(GPR1));
// if (GPR0 == 0x7fffffff) goto slow_case;
m_assembler.jump_if(
Assembler::Operand::Register(GPR0),
Assembler::Condition::EqualTo,
Assembler::Operand::Imm(0x7fffffff),
slow_case);
// ARG1 += 1;
m_assembler.add(
Assembler::Operand::Register(ARG1),
Assembler::Operand::Imm(1));
// accumulator = ARG1;
store_accumulator(ARG1);
// accumulator = GPR0 | SHIFTED_INT32_TAG;
m_assembler.mov(
Assembler::Operand::Register(GPR1),
Assembler::Operand::Imm(SHIFTED_INT32_TAG));
m_assembler.bitwise_or(
Assembler::Operand::Register(GPR0),
Assembler::Operand::Register(GPR1));
store_accumulator(GPR0);
m_assembler.jump(end);
});