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

LibJS/JIT: Add builtin for Math.log()

Note that we still call out to a C++ helper, but by having a builtin,
we still avoid the cost of a full JS function call.
This commit is contained in:
Andreas Kling 2023-11-24 09:31:23 +01:00
parent a6106ca221
commit 1d8a601f96
4 changed files with 28 additions and 5 deletions

View file

@ -18,6 +18,7 @@
#include <LibJS/Runtime/ECMAScriptFunctionObject.h>
#include <LibJS/Runtime/FunctionEnvironment.h>
#include <LibJS/Runtime/GlobalEnvironment.h>
#include <LibJS/Runtime/MathObject.h>
#include <LibJS/Runtime/ObjectEnvironment.h>
#include <LibJS/Runtime/VM.h>
#include <LibJS/Runtime/ValueInlines.h>
@ -2623,6 +2624,19 @@ void Compiler::compile_builtin(Bytecode::Builtin builtin, Assembler::Label& slow
}
}
static Value cxx_math_log(VM& vm, Value, Value value)
{
return TRY_OR_SET_EXCEPTION(MathObject::log_impl(vm, value));
}
void Compiler::compile_builtin_math_log(Assembler::Label&, Assembler::Label& end)
{
native_call((void*)cxx_math_log);
store_accumulator(RET);
check_exception();
m_assembler.jump(end);
}
void Compiler::compile_builtin_math_abs(Assembler::Label& slow_case, Assembler::Label& end)
{
branch_if_int32(ARG2, [&] {