Title: [231546] trunk/Source/_javascript_Core
Revision
231546
Author
[email protected]
Date
2018-05-08 23:01:19 -0700 (Tue, 08 May 2018)

Log Message

[BigInt] Simplifying JSBigInt by using bool addition
https://bugs.webkit.org/show_bug.cgi?id=185374

Reviewed by Alex Christensen.

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):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (231545 => 231546)


--- trunk/Source/_javascript_Core/ChangeLog	2018-05-09 05:50:39 UTC (rev 231545)
+++ trunk/Source/_javascript_Core/ChangeLog	2018-05-09 06:01:19 UTC (rev 231546)
@@ -1,3 +1,29 @@
+2018-05-07  Yusuke Suzuki  <[email protected]>
+
+        [BigInt] Simplifying JSBigInt by using bool addition
+        https://bugs.webkit.org/show_bug.cgi?id=185374
+
+        Reviewed by Alex Christensen.
+
+        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-08  Michael Saboff  <[email protected]>
 
         Replace multiple Watchpoint Set fireAll() methods with templates

Modified: trunk/Source/_javascript_Core/runtime/JSBigInt.cpp (231545 => 231546)


--- trunk/Source/_javascript_Core/runtime/JSBigInt.cpp	2018-05-09 05:50:39 UTC (rev 231545)
+++ trunk/Source/_javascript_Core/runtime/JSBigInt.cpp	2018-05-09 06:01:19 UTC (rev 231546)
@@ -230,7 +230,7 @@
     return toStringGeneric(state, this, radix);
 }
 
-bool JSBigInt::isZero()
+inline bool JSBigInt::isZero()
 {
     ASSERT(length() || !sign());
     return length() == 0;
@@ -237,7 +237,7 @@
 }
 
 // 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 @@
 
 // {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 @@
 }
 
 // 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 @@
 
 // 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 @@
     return true;
 }
 
-size_t JSBigInt::offsetOfData()
+inline size_t JSBigInt::offsetOfData()
 {
     return WTF::roundUpToMultipleOf<sizeof(Digit)>(sizeof(JSBigInt));
 }
@@ -816,18 +797,18 @@
     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;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to