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

Side by Side Diff: runtime/vm/bigint_operations.cc

Issue 14962008: Fix issue 5275: The VM must always generate the most compact form of an integer (Smi, Mint or Bigin… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 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
OLDNEW
1 // Copyright 2012 Google Inc. All Rights Reserved. 1 // Copyright 2012 Google Inc. All Rights Reserved.
2 2
3 #include "vm/bigint_operations.h" 3 #include "vm/bigint_operations.h"
4 4
5 #include "platform/utils.h" 5 #include "platform/utils.h"
6 6
7 #include "vm/double_internals.h" 7 #include "vm/double_internals.h"
8 #include "vm/exceptions.h" 8 #include "vm/exceptions.h"
9 #include "vm/object_store.h" 9 #include "vm/object_store.h"
10 #include "vm/zone.h" 10 #include "vm/zone.h"
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 uint64_t value = 0; 657 uint64_t value = 0;
658 for (int i = bigint.Length() - 1; i >= 0; i--) { 658 for (int i = bigint.Length() - 1; i >= 0; i--) {
659 value <<= kDigitBitSize; 659 value <<= kDigitBitSize;
660 value += static_cast<intptr_t>(bigint.GetChunkAt(i)); 660 value += static_cast<intptr_t>(bigint.GetChunkAt(i));
661 } 661 }
662 return value; 662 return value;
663 } 663 }
664 664
665 665
666 int64_t BigintOperations::ToMint(const Bigint& bigint) { 666 int64_t BigintOperations::ToMint(const Bigint& bigint) {
667 if (bigint.IsZero()) {
668 return 0;
669 }
667 ASSERT(FitsIntoMint(bigint)); 670 ASSERT(FitsIntoMint(bigint));
668 int64_t value = AbsToUint64(bigint); 671 int64_t value = AbsToUint64(bigint);
669 if (bigint.IsNegative()) { 672 if (bigint.IsNegative()) {
670 value = -value; 673 value = -value;
671 } 674 }
672 return value; 675 return value;
673 } 676 }
674 677
675 678
676 bool BigintOperations::AbsFitsIntoUint64(const Bigint& bigint) { 679 bool BigintOperations::AbsFitsIntoUint64(const Bigint& bigint) {
(...skipping 985 matching lines...) Expand 10 before | Expand all | Expand 10 after
1662 int BigintOperations::CountBits(Chunk digit) { 1665 int BigintOperations::CountBits(Chunk digit) {
1663 int result = 0; 1666 int result = 0;
1664 while (digit != 0) { 1667 while (digit != 0) {
1665 digit >>= 1; 1668 digit >>= 1;
1666 result++; 1669 result++;
1667 } 1670 }
1668 return result; 1671 return result;
1669 } 1672 }
1670 1673
1671 } // namespace dart 1674 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698