WebKit Bugzilla
Attachment 339711 Details for
Bug 185374
: [BigInt] Simplifying JSBigInt by using bool addition
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-185374-20180507195434.patch (text/plain), 5.46 KB, created by
Yusuke Suzuki
on 2018-05-07 03:54:35 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Yusuke Suzuki
Created:
2018-05-07 03:54:35 PDT
Size:
5.46 KB
patch
obsolete
>Subversion Revision: 231404 >diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog >index fb2176fa3b51d9f8651b978d2fc78ae7bba88687..e9436a155167dbe95a9a7e859f4286e31cf5268e 100644 >--- a/Source/JavaScriptCore/ChangeLog >+++ b/Source/JavaScriptCore/ChangeLog >@@ -1,3 +1,29 @@ >+2018-05-07 Yusuke Suzuki <utatane.tea@gmail.com> >+ >+ [BigInt] Simplifying JSBigInt by using bool addition >+ https://bugs.webkit.org/show_bug.cgi?id=185374 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Since using TWO_DIGIT does not produce good code, we remove this part from digitAdd and digitSub. >+ Just adding overflow flag to carry/borrow produces setb + add in x86. >+ >+ Also we annotate small helper functions and accessors with `inline` not to call these functions >+ inside internalMultiplyAdd loop. >+ >+ * runtime/JSBigInt.cpp: >+ (JSC::JSBigInt::isZero): >+ (JSC::JSBigInt::inplaceMultiplyAdd): >+ (JSC::JSBigInt::digitAdd): >+ (JSC::JSBigInt::digitSub): >+ (JSC::JSBigInt::digitMul): >+ (JSC::JSBigInt::digitPow): >+ (JSC::JSBigInt::digitDiv): >+ (JSC::JSBigInt::offsetOfData): >+ (JSC::JSBigInt::dataStorage): >+ (JSC::JSBigInt::digit): >+ (JSC::JSBigInt::setDigit): >+ > 2018-05-06 Yusuke Suzuki <utatane.tea@gmail.com> > > [JSC] Remove "using namespace std;" from JSC, bmalloc, WTF >diff --git a/Source/JavaScriptCore/runtime/JSBigInt.cpp b/Source/JavaScriptCore/runtime/JSBigInt.cpp >index 3d1e9f183afb09e3cb825aabf2a047980f107993..46c2a6ce57fd337a39da73b80909bfce36231dc8 100644 >--- a/Source/JavaScriptCore/runtime/JSBigInt.cpp >+++ b/Source/JavaScriptCore/runtime/JSBigInt.cpp >@@ -230,14 +230,14 @@ String JSBigInt::toString(ExecState& state, int radix) > return toStringGeneric(state, this, radix); > } > >-bool JSBigInt::isZero() >+inline bool JSBigInt::isZero() > { > ASSERT(length() || !sign()); > return length() == 0; > } > > // Multiplies {this} with {factor} and adds {summand} to the result. >-void JSBigInt::inplaceMultiplyAdd(uintptr_t factor, uintptr_t summand) >+inline void JSBigInt::inplaceMultiplyAdd(uintptr_t factor, uintptr_t summand) > { > STATIC_ASSERT(sizeof(factor) == sizeof(Digit)); > STATIC_ASSERT(sizeof(summand) == sizeof(Digit)); >@@ -257,43 +257,24 @@ typedef __uint128_t TwoDigit; > > // {carry} must point to an initialized Digit and will either be incremented > // by one or left alone. >-JSBigInt::Digit JSBigInt::digitAdd(Digit a, Digit b, Digit& carry) >+inline JSBigInt::Digit JSBigInt::digitAdd(Digit a, Digit b, Digit& carry) > { >-#if HAVE_TWO_DIGIT >- TwoDigit result = static_cast<TwoDigit>(a) + static_cast<TwoDigit>(b); >- carry += result >> digitBits; >- >- return static_cast<Digit>(result); >-#else > Digit result = a + b; >- >- if (result < a) >- carry += 1; >- >+ carry += static_cast<bool>(result < a); > return result; >-#endif > } > > // {borrow} must point to an initialized Digit and will either be incremented > // by one or left alone. >-JSBigInt::Digit JSBigInt::digitSub(Digit a, Digit b, Digit& borrow) >+inline JSBigInt::Digit JSBigInt::digitSub(Digit a, Digit b, Digit& borrow) > { >-#if HAVE_TWO_DIGIT >- TwoDigit result = static_cast<TwoDigit>(a) - static_cast<TwoDigit>(b); >- borrow += (result >> digitBits) & 1; >- >- return static_cast<Digit>(result); >-#else > Digit result = a - b; >- if (result > a) >- borrow += 1; >- >- return static_cast<Digit>(result); >-#endif >+ borrow += static_cast<bool>(result > a); >+ return result; > } > > // Returns the low half of the result. High half is in {high}. >-JSBigInt::Digit JSBigInt::digitMul(Digit a, Digit b, Digit& high) >+inline JSBigInt::Digit JSBigInt::digitMul(Digit a, Digit b, Digit& high) > { > #if HAVE_TWO_DIGIT > TwoDigit result = static_cast<TwoDigit>(a) * static_cast<TwoDigit>(b); >@@ -332,7 +313,7 @@ JSBigInt::Digit JSBigInt::digitMul(Digit a, Digit b, Digit& high) > } > > // Raises {base} to the power of {exponent}. Does not check for overflow. >-JSBigInt::Digit JSBigInt::digitPow(Digit base, Digit exponent) >+inline JSBigInt::Digit JSBigInt::digitPow(Digit base, Digit exponent) > { > Digit result = 1ull; > while (exponent > 0) { >@@ -348,7 +329,7 @@ JSBigInt::Digit JSBigInt::digitPow(Digit base, Digit exponent) > > // Returns the quotient. > // quotient = (high << digitBits + low - remainder) / divisor >-JSBigInt::Digit JSBigInt::digitDiv(Digit high, Digit low, Digit divisor, Digit& remainder) >+inline JSBigInt::Digit JSBigInt::digitDiv(Digit high, Digit low, Digit divisor, Digit& remainder) > { > ASSERT(high < divisor); > #if CPU(X86_64) && COMPILER(GCC_OR_CLANG) >@@ -712,7 +693,7 @@ bool JSBigInt::getPrimitiveNumber(ExecState* state, double& number, JSValue& res > return true; > } > >-size_t JSBigInt::offsetOfData() >+inline size_t JSBigInt::offsetOfData() > { > return WTF::roundUpToMultipleOf<sizeof(Digit)>(sizeof(JSBigInt)); > } >@@ -816,18 +797,18 @@ JSBigInt* JSBigInt::parseInt(ExecState* state, VM& vm, CharType* data, int lengt > return nullptr; > } > >-JSBigInt::Digit* JSBigInt::dataStorage() >+inline JSBigInt::Digit* JSBigInt::dataStorage() > { > return reinterpret_cast<Digit*>(reinterpret_cast<char*>(this) + offsetOfData()); > } > >-JSBigInt::Digit JSBigInt::digit(int n) >+inline JSBigInt::Digit JSBigInt::digit(int n) > { > ASSERT(n >= 0 && n < length()); > return dataStorage()[n]; > } > >-void JSBigInt::setDigit(int n, Digit value) >+inline void JSBigInt::setDigit(int n, Digit value) > { > ASSERT(n >= 0 && n < length()); > dataStorage()[n] = value;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
achristensen
:
review+
ews-watchlist
:
commit-queue-
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 185374
: 339711 |
339719