Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 40830da5de3d57fed8dcff3c0314b9b7986e2420
https://github.com/WebKit/WebKit/commit/40830da5de3d57fed8dcff3c0314b9b7986e2420
Author: Yusuke Suzuki <[email protected]>
Date: 2025-12-18 (Thu, 18 Dec 2025)
Changed paths:
M Source/JavaScriptCore/runtime/JSBigInt.cpp
M Source/JavaScriptCore/runtime/JSBigInt.h
Log Message:
-----------
[JSC] JSBigInt division / remainder should have a fast path for same size
https://bugs.webkit.org/show_bug.cgi?id=304380
rdar://166757372
Reviewed by Keith Miller.
When there is `a / b`, if `a < b`, then the result is 0.
If `a == b`, the result is 1. And if `a > b` but `a` has the same number
of digits as `b`, then the quotient/result is one Digit.
By leveraging this, we can largely simplify the division algorithm.
This patch adds divideSameSize and remainderSameSize. And they completely
avoid any Vector allocation for temporary storage and compute the result
in an in-place manner.
Because we are pruning a path for `a < b` and `a == b` before, same size
division is very common. So this is worth optimizing.
We also clean up a bit of span functions to remove assertions. We use
size_t and RELEASE_ASSERT to confirm these assertions are always true.
* Source/JavaScriptCore/runtime/JSBigInt.cpp:
(JSC::normalize):
(JSC::JSBigInt::multiplySingle):
(JSC::JSBigInt::multiplyTextbook):
(JSC::JSBigInt::divideSingle):
(JSC::JSBigInt::addAndReturnCarry):
(JSC::JSBigInt::subtractAndReturnBorrow):
(JSC::JSBigInt::leftShift):
(JSC::JSBigInt::rightShift):
(JSC::JSBigInt::divideTextbook):
(JSC::estimateQhat):
(JSC::JSBigInt::divideSameSize):
(JSC::JSBigInt::remainderSameSize):
(JSC::JSBigInt::divideImpl):
(JSC::JSBigInt::remainderImpl):
(JSC::JSBigInt::multiplyAdd):
(JSC::JSBigInt::addTextbook):
(JSC::JSBigInt::subTextbook):
(JSC::JSBigInt::absoluteBitwiseOp):
(JSC::JSBigInt::absoluteAndNot):
(JSC::JSBigInt::absoluteAddOne):
(JSC::JSBigInt::absoluteSubOne):
(JSC::JSBigInt::leftShiftByAbsolute):
(JSC::JSBigInt::rightShiftByAbsolute):
* Source/JavaScriptCore/runtime/JSBigInt.h:
Canonical link: https://commits.webkit.org/304712@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications