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

Side by Side Diff: runtime/lib/bigint.dart

Issue 1058523003: Move zero-ing code out of shift intrinsic (not needed if destination is new). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/method_recognizer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // Copyright 2009 The Go Authors. All rights reserved. 5 // Copyright 2009 The Go Authors. All rights reserved.
6 // Use of this source code is governed by a BSD-style 6 // Use of this source code is governed by a BSD-style
7 // license that can be found in the LICENSE file. 7 // license that can be found in the LICENSE file.
8 8
9 /* 9 /*
10 * Copyright (c) 2003-2005 Tom Wu 10 * Copyright (c) 2003-2005 Tom Wu
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 final cbs = _DIGIT_BITS - bs; 264 final cbs = _DIGIT_BITS - bs;
265 final bm = (1 << cbs) - 1; 265 final bm = (1 << cbs) - 1;
266 var c = 0; 266 var c = 0;
267 var i = x_used; 267 var i = x_used;
268 while (--i >= 0) { 268 while (--i >= 0) {
269 final d = x_digits[i]; 269 final d = x_digits[i];
270 r_digits[i + ds + 1] = (d >> cbs) | c; 270 r_digits[i + ds + 1] = (d >> cbs) | c;
271 c = (d & bm) << bs; 271 c = (d & bm) << bs;
272 } 272 }
273 r_digits[ds] = c; 273 r_digits[ds] = c;
274 i = ds;
275 while (--i >= 0) {
276 r_digits[i] = 0;
277 }
278 } 274 }
279 275
280 // Return this << n. 276 // Return this << n.
281 _Bigint _lShift(int n) { 277 _Bigint _lShift(int n) {
282 final ds = n ~/ _DIGIT_BITS; 278 final ds = n ~/ _DIGIT_BITS;
283 final bs = n % _DIGIT_BITS; 279 final bs = n % _DIGIT_BITS;
284 if (bs == 0) { 280 if (bs == 0) {
285 return _dlShift(ds); 281 return _dlShift(ds);
286 } 282 }
287 var r_used = _used + ds + 1; 283 var r_used = _used + ds + 1;
288 var r_digits = new Uint32List(r_used + 2 + (r_used & 1)); // +2 for 64-bit. 284 var r_digits = new Uint32List(r_used + 2 + (r_used & 1)); // +2 for 64-bit.
289 _lsh(_digits, _used, n, r_digits); 285 _lsh(_digits, _used, n, r_digits);
290 return new _Bigint(_neg, r_used, r_digits); 286 return new _Bigint(_neg, r_used, r_digits);
291 } 287 }
292 288
293 // r_digits[0..r_used-1] = x_digits[0..x_used-1] << n. 289 // r_digits[0..r_used-1] = x_digits[0..x_used-1] << n.
294 // Return r_used. 290 // Return r_used.
295 static int _lShiftDigits(Uint32List x_digits, int x_used, int n, 291 static int _lShiftDigits(Uint32List x_digits, int x_used, int n,
296 Uint32List r_digits) { 292 Uint32List r_digits) {
297 final ds = n ~/ _DIGIT_BITS; 293 final ds = n ~/ _DIGIT_BITS;
298 final bs = n % _DIGIT_BITS; 294 final bs = n % _DIGIT_BITS;
299 if (bs == 0) { 295 if (bs == 0) {
300 return _dlShiftDigits(x_digits, x_used, ds, r_digits); 296 return _dlShiftDigits(x_digits, x_used, ds, r_digits);
301 } 297 }
302 var r_used = x_used + ds + 1; 298 var r_used = x_used + ds + 1;
303 assert(r_digits.length >= r_used + 2 + (r_used & 1)); // +2 for 64-bit. 299 assert(r_digits.length >= r_used + 2 + (r_used & 1)); // +2 for 64-bit.
304 _lsh(x_digits, x_used, n, r_digits); 300 _lsh(x_digits, x_used, n, r_digits);
301 var i = ds;
302 while (--i >= 0) {
303 r_digits[i] = 0;
304 }
305 if (r_digits[r_used - 1] == 0) { 305 if (r_digits[r_used - 1] == 0) {
306 r_used--; // Clamp result. 306 r_used--; // Clamp result.
307 } else if (r_used.isOdd) { 307 } else if (r_used.isOdd) {
308 r_digits[r_used] = 0; 308 r_digits[r_used] = 0;
309 } 309 }
310 return r_used; 310 return r_used;
311 } 311 }
312 312
313 // r_digits[0..r_used-1] = x_digits[0..x_used-1] >> n. 313 // r_digits[0..r_used-1] = x_digits[0..x_used-1] >> n.
314 static void _rsh(Uint32List x_digits, int x_used, int n, 314 static void _rsh(Uint32List x_digits, int x_used, int n,
(...skipping 1447 matching lines...) Expand 10 before | Expand all | Expand 10 after
1762 1762
1763 int _mul(Uint32List x_digits, int x_used, 1763 int _mul(Uint32List x_digits, int x_used,
1764 Uint32List y_digits, int y_used, 1764 Uint32List y_digits, int y_used,
1765 Uint32List r_digits) { 1765 Uint32List r_digits) {
1766 var r_used = _Bigint._mulDigits(x_digits, x_used, 1766 var r_used = _Bigint._mulDigits(x_digits, x_used,
1767 y_digits, y_used, 1767 y_digits, y_used,
1768 r_digits); 1768 r_digits);
1769 return _reduce(r_digits, r_used); 1769 return _reduce(r_digits, r_used);
1770 } 1770 }
1771 } 1771 }
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/method_recognizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698