mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-19 23:53:20 +00:00
LibJS: Add fast path for division of two numbers
We already had fast paths for Add, Sub and Mul. Might as well do Div. 1.18x speed-up on this micro-benchmark: (() => { let a = 1234; for (let i = 0; i < 100_000_000; ++i) a / a; })()
This commit is contained in:
parent
755c8d8cd6
commit
a76f420207
Notes:
github-actions[bot]
2025-10-11 18:09:55 +00:00
Author: https://github.com/awesomekling
Commit: a76f420207
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6450
2 changed files with 16 additions and 1 deletions
|
@ -2003,6 +2003,21 @@ ThrowCompletionOr<void> Mul::execute_impl(Bytecode::Interpreter& interpreter) co
|
|||
return {};
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> Div::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
auto& vm = interpreter.vm();
|
||||
auto const lhs = interpreter.get(m_lhs);
|
||||
auto const rhs = interpreter.get(m_rhs);
|
||||
|
||||
if (lhs.is_number() && rhs.is_number()) [[likely]] {
|
||||
interpreter.set(m_dst, Value(lhs.as_double() / rhs.as_double()));
|
||||
return {};
|
||||
}
|
||||
|
||||
interpreter.set(m_dst, TRY(div(vm, lhs, rhs)));
|
||||
return {};
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> Sub::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
auto& vm = interpreter.vm();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue