1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:27:35 +00:00

LibJS: Add an inline JIT fast path when ToNumeric has nothing to do

In most cases, this op will do nothing, as it is running on an the
accumulator while it already contains a number. Let's avoid doing that
native call.
This commit is contained in:
Zaggy1024 2023-10-29 07:36:39 -05:00 committed by Andreas Kling
parent a2b0154661
commit dfaf645302
2 changed files with 21 additions and 0 deletions

View file

@ -237,6 +237,19 @@ void Compiler::compile_jump_undefined(Bytecode::Op::JumpUndefined const& op)
return BigInt::create(vm, old_value.as_bigint().big_integer().plus(Crypto::SignedBigInteger { 1 }));
}
void Compiler::jump_if_int32(Assembler::Reg reg, Assembler::Label& label)
{
// GPR0 = reg >> 48;
m_assembler.mov(Assembler::Operand::Register(GPR0), Assembler::Operand::Register(reg));
m_assembler.shift_right(Assembler::Operand::Register(GPR0), Assembler::Operand::Imm(48));
m_assembler.jump_if(
Assembler::Operand::Register(GPR0),
Assembler::Condition::EqualTo,
Assembler::Operand::Imm(INT32_TAG),
label);
}
template<typename Codegen>
void Compiler::branch_if_int32(Assembler::Reg reg, Codegen codegen)
{
@ -909,10 +922,16 @@ static Value cxx_to_numeric(VM& vm, Value value)
void Compiler::compile_to_numeric(Bytecode::Op::ToNumeric const&)
{
Assembler::Label fast_case {};
load_vm_register(ARG1, Bytecode::Register::accumulator());
jump_if_int32(ARG1, fast_case);
native_call((void*)cxx_to_numeric);
store_vm_register(Bytecode::Register::accumulator(), RET);
check_exception();
fast_case.link(m_assembler);
}
static Value cxx_resolve_this_binding(VM& vm)