mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-15 12:39:13 +00:00
LibJS: Add fast path for division of two numbers
Some checks failed
CI / macOS, arm64, Sanitizer, Clang (push) Has been cancelled
CI / Linux, x86_64, Fuzzers, Clang (push) Has been cancelled
CI / Linux, x86_64, Sanitizer, GNU (push) Has been cancelled
CI / Linux, x86_64, Sanitizer, Clang (push) Has been cancelled
Package the js repl as a binary artifact / Linux, arm64 (push) Has been cancelled
Package the js repl as a binary artifact / macOS, arm64 (push) Has been cancelled
Package the js repl as a binary artifact / Linux, x86_64 (push) Has been cancelled
Run test262 and test-wasm / run_and_update_results (push) Has been cancelled
Lint Code / lint (push) Has been cancelled
Label PRs with merge conflicts / auto-labeler (push) Has been cancelled
Push notes / build (push) Has been cancelled
Some checks failed
CI / macOS, arm64, Sanitizer, Clang (push) Has been cancelled
CI / Linux, x86_64, Fuzzers, Clang (push) Has been cancelled
CI / Linux, x86_64, Sanitizer, GNU (push) Has been cancelled
CI / Linux, x86_64, Sanitizer, Clang (push) Has been cancelled
Package the js repl as a binary artifact / Linux, arm64 (push) Has been cancelled
Package the js repl as a binary artifact / macOS, arm64 (push) Has been cancelled
Package the js repl as a binary artifact / Linux, x86_64 (push) Has been cancelled
Run test262 and test-wasm / run_and_update_results (push) Has been cancelled
Lint Code / lint (push) Has been cancelled
Label PRs with merge conflicts / auto-labeler (push) Has been cancelled
Push notes / build (push) Has been cancelled
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 {};
|
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
|
ThrowCompletionOr<void> Sub::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||||
{
|
{
|
||||||
auto& vm = interpreter.vm();
|
auto& vm = interpreter.vm();
|
||||||
|
|
|
@ -113,6 +113,7 @@ private:
|
||||||
O(BitwiseAnd, bitwise_and) \
|
O(BitwiseAnd, bitwise_and) \
|
||||||
O(BitwiseOr, bitwise_or) \
|
O(BitwiseOr, bitwise_or) \
|
||||||
O(BitwiseXor, bitwise_xor) \
|
O(BitwiseXor, bitwise_xor) \
|
||||||
|
O(Div, div) \
|
||||||
O(GreaterThan, greater_than) \
|
O(GreaterThan, greater_than) \
|
||||||
O(GreaterThanEquals, greater_than_equals) \
|
O(GreaterThanEquals, greater_than_equals) \
|
||||||
O(LeftShift, left_shift) \
|
O(LeftShift, left_shift) \
|
||||||
|
@ -124,7 +125,6 @@ private:
|
||||||
O(UnsignedRightShift, unsigned_right_shift)
|
O(UnsignedRightShift, unsigned_right_shift)
|
||||||
|
|
||||||
#define JS_ENUMERATE_COMMON_BINARY_OPS_WITHOUT_FAST_PATH(O) \
|
#define JS_ENUMERATE_COMMON_BINARY_OPS_WITHOUT_FAST_PATH(O) \
|
||||||
O(Div, div) \
|
|
||||||
O(Exp, exp) \
|
O(Exp, exp) \
|
||||||
O(Mod, mod) \
|
O(Mod, mod) \
|
||||||
O(In, in) \
|
O(In, in) \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue