Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(510)

Unified Diff: runtime/lib/bigint.dart

Issue 603493002: Revert r40623, "Refactor bigint _sqrTo in preparation of intrinsification." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/vm/intrinsifier_arm.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/bigint.dart
diff --git a/runtime/lib/bigint.dart b/runtime/lib/bigint.dart
index 52228effea62fc1072991a4b6af2a4eaa018e67a..92cdde039994b7735cb6ff01d301c4c5f0756f06 100644
--- a/runtime/lib/bigint.dart
+++ b/runtime/lib/bigint.dart
@@ -815,46 +815,34 @@ class _Bigint extends _IntegerImplementation implements int {
args[MA_CARRY_OUT] = c;
}
- // Square and accumulate.
+ // Multiply and accumulate with carry in.
// Input:
- // x_digits[i..used-1]: digits of operand being squared.
- // a_digits[2*i..i+used-1]: accumulator digits.
+ // x: multiplier digit, 0 <= x < 2*DIGIT_BASE (i.e. 33-bit multiplier).
+ // m_digits[i..i+n-1]: multiplicand digits.
+ // a_digits[j..j+n-1]: accumulator digits.
+ // c: carry in.
// Operation:
- // a_digits[2*i..i+used-1] += x_digits[i]*x_digits[i] +
- // 2*x_digits[i]*x_digits[i+1..used-1].
- static void _sqrAdd(Uint32List x_digits, int i,
- Uint32List a_digits, int used) {
- int x = x_digits[i];
- if (x == 0) return;
- int j = 2*i;
- int c = 0;
+ // a_digits[j..j+n-1] += x*m_digits[i..i+n-1] + c.
+ // Output:
+ // carry out.
+ // TODO(regis): Use an argument buffer as in _mulAdd.
+ static int _mulAddc(int x, Uint32List m_digits, int i,
+ Uint32List a_digits, int j, int c, int n) {
+ if (x == 0 && c == 0) {
+ // No-op if both x and c are 0.
+ return 0;
+ }
int xl = x & DIGIT2_MASK;
int xh = x >> DIGIT2_BITS;
- int m = 2*xh*xl;
- int l = xl*xl + ((m & DIGIT2_MASK) << DIGIT2_BITS) + a_digits[j];
- c = (l >> DIGIT_BITS) + (m >> DIGIT2_BITS) + xh*xh;
- a_digits[j] = l & DIGIT_MASK;
- x <<= 1;
- xl = x & DIGIT2_MASK;
- xh = x >> DIGIT2_BITS;
- int n = used - i - 1;
- int k = i + 1;
- j++;
while (--n >= 0) {
- int l = x_digits[k] & DIGIT2_MASK;
- int h = x_digits[k++] >> DIGIT2_BITS;
+ int l = m_digits[i] & DIGIT2_MASK;
+ int h = m_digits[i++] >> DIGIT2_BITS;
int m = xh*l + h*xl;
l = xl*l + ((m & DIGIT2_MASK) << DIGIT2_BITS) + a_digits[j] + c;
c = (l >> DIGIT_BITS) + (m >> DIGIT2_BITS) + xh*h;
a_digits[j++] = l & DIGIT_MASK;
}
- c += a_digits[i + used];
- if (c >= DIGIT_BASE) {
- a_digits[i + used] = c - DIGIT_BASE;
- a_digits[i + used + 1] = 1;
- } else {
- a_digits[i + used] = c;
- }
+ return c;
}
// r = this * a.
@@ -892,7 +880,18 @@ class _Bigint extends _IntegerImplementation implements int {
r_digits[i] = 0;
}
for (i = 0; i < used - 1; ++i) {
- _sqrAdd(digits, i, r_digits, used);
+ _MulAddArgs[MA_MULTIPLIER] = digits[i];
+ _mulAdd(_MulAddArgs, digits, i, r_digits, 2*i, 1);
+ var c = _MulAddArgs[MA_CARRY_OUT];
+ var d = r_digits[i + used];
+ d += _mulAddc(digits[i] << 1, digits, i + 1,
+ r_digits, 2*i + 1, c, used - i - 1);
+ if (d >= DIGIT_BASE) {
+ r_digits[i + used] = d - DIGIT_BASE;
+ r_digits[i + used + 1] = 1;
+ } else {
+ r_digits[i + used] = d;
+ }
}
if (r_used > 0) {
_MulAddArgs[MA_MULTIPLIER] = digits[i];
« no previous file with comments | « no previous file | runtime/vm/intrinsifier_arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698