mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01: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
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -113,6 +113,7 @@ private:
|
|||
O(BitwiseAnd, bitwise_and) \
|
||||
O(BitwiseOr, bitwise_or) \
|
||||
O(BitwiseXor, bitwise_xor) \
|
||||
O(Div, div) \
|
||||
O(GreaterThan, greater_than) \
|
||||
O(GreaterThanEquals, greater_than_equals) \
|
||||
O(LeftShift, left_shift) \
|
||||
|
|
@ -124,7 +125,6 @@ private:
|
|||
O(UnsignedRightShift, unsigned_right_shift)
|
||||
|
||||
#define JS_ENUMERATE_COMMON_BINARY_OPS_WITHOUT_FAST_PATH(O) \
|
||||
O(Div, div) \
|
||||
O(Exp, exp) \
|
||||
O(Mod, mod) \
|
||||
O(In, in) \
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user