| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #include "vm/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 16390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16401 result.EnsureLength(2, space); | 16401 result.EnsureLength(2, space); |
| 16402 result.SetUsed(2); | 16402 result.SetUsed(2); |
| 16403 result.SetDigitAt(0, static_cast<uint32_t>(value)); | 16403 result.SetDigitAt(0, static_cast<uint32_t>(value)); |
| 16404 result.SetDigitAt(1, static_cast<uint32_t>(value >> 32)); | 16404 result.SetDigitAt(1, static_cast<uint32_t>(value >> 32)); |
| 16405 result.Clamp(); | 16405 result.Clamp(); |
| 16406 return result.raw(); | 16406 return result.raw(); |
| 16407 } | 16407 } |
| 16408 | 16408 |
| 16409 | 16409 |
| 16410 RawBigint* Bigint::NewFromShiftedInt64(int64_t value, intptr_t shift, | 16410 RawBigint* Bigint::NewFromShiftedInt64(int64_t value, intptr_t shift, |
| 16411 Heap::Space space) { | 16411 Heap::Space space) { |
| 16412 ASSERT(kBitsPerDigit == 32); | 16412 ASSERT(kBitsPerDigit == 32); |
| 16413 ASSERT(shift >= 0); | 16413 ASSERT(shift >= 0); |
| 16414 const Bigint& result = Bigint::Handle(New(space)); | 16414 const Bigint& result = Bigint::Handle(New(space)); |
| 16415 const intptr_t digit_shift = shift / kBitsPerDigit; | 16415 const intptr_t digit_shift = shift / kBitsPerDigit; |
| 16416 const intptr_t bit_shift = shift % kBitsPerDigit; | 16416 const intptr_t bit_shift = shift % kBitsPerDigit; |
| 16417 result.EnsureLength(3 + digit_shift, space); | 16417 result.EnsureLength(3 + digit_shift, space); |
| 16418 result.SetUsed(3 + digit_shift); | 16418 result.SetUsed(3 + digit_shift); |
| 16419 uint64_t abs_value; | 16419 uint64_t abs_value; |
| 16420 if (value < 0) { | 16420 if (value < 0) { |
| 16421 result.SetNeg(true); | 16421 result.SetNeg(true); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 16432 static_cast<uint32_t>(abs_value >> (32 - bit_shift))); | 16432 static_cast<uint32_t>(abs_value >> (32 - bit_shift))); |
| 16433 result.SetDigitAt(2 + digit_shift, | 16433 result.SetDigitAt(2 + digit_shift, |
| 16434 (bit_shift == 0) ? 0 | 16434 (bit_shift == 0) ? 0 |
| 16435 : static_cast<uint32_t>(abs_value >> (64 - bit_shift))); | 16435 : static_cast<uint32_t>(abs_value >> (64 - bit_shift))); |
| 16436 result.Clamp(); | 16436 result.Clamp(); |
| 16437 return result.raw(); | 16437 return result.raw(); |
| 16438 } | 16438 } |
| 16439 | 16439 |
| 16440 | 16440 |
| 16441 void Bigint::EnsureLength(intptr_t length, Heap::Space space) const { | 16441 void Bigint::EnsureLength(intptr_t length, Heap::Space space) const { |
| 16442 ASSERT(length >= 0); | 16442 ASSERT(length > 0); |
| 16443 TypedData& old_digits = TypedData::Handle(digits()); | 16443 TypedData& old_digits = TypedData::Handle(digits()); |
| 16444 if ((length > 0) && (length > old_digits.Length())) { | 16444 if (length > old_digits.Length()) { |
| 16445 TypedData& new_digits = TypedData::Handle( | 16445 TypedData& new_digits = TypedData::Handle( |
| 16446 TypedData::New(kTypedDataUint32ArrayCid, length + kExtraDigits, space)); | 16446 TypedData::New(kTypedDataUint32ArrayCid, length + kExtraDigits, space)); |
| 16447 if (old_digits.Length() > 0) { | 16447 set_digits(new_digits); |
| 16448 if (Used() > 0) { |
| 16448 TypedData::Copy(new_digits, TypedData::data_offset(), | 16449 TypedData::Copy(new_digits, TypedData::data_offset(), |
| 16449 old_digits, TypedData::data_offset(), | 16450 old_digits, TypedData::data_offset(), |
| 16450 old_digits.LengthInBytes()); | 16451 (Used() + 1)*kBytesPerDigit); // Copy leading zero. |
| 16451 } | 16452 } |
| 16452 set_digits(new_digits); | |
| 16453 } | 16453 } |
| 16454 } | 16454 } |
| 16455 | 16455 |
| 16456 | 16456 |
| 16457 void Bigint::Clamp() const { | 16457 void Bigint::Clamp() const { |
| 16458 intptr_t used = Used(); | 16458 intptr_t used = Used(); |
| 16459 while ((used > 0) && (DigitAt(used - 1) == 0)) { | 16459 if (used > 0) { |
| 16460 --used; | 16460 if (DigitAt(used - 1) == 0) { |
| 16461 do { |
| 16462 --used; |
| 16463 } while ((used > 0) && (DigitAt(used - 1) == 0)); |
| 16464 SetUsed(used); |
| 16465 } |
| 16466 SetDigitAt(used, 0); // Set leading zero for 64-bit processing. |
| 16461 } | 16467 } |
| 16462 SetUsed(used); | |
| 16463 } | 16468 } |
| 16464 | 16469 |
| 16465 | 16470 |
| 16466 bool Bigint::IsClamped() const { | 16471 bool Bigint::IsClamped() const { |
| 16467 intptr_t used = Used(); | 16472 intptr_t used = Used(); |
| 16468 return (used == 0) || (DigitAt(used - 1) > 0); | 16473 return (used == 0) || (DigitAt(used - 1) > 0); |
| 16469 } | 16474 } |
| 16470 | 16475 |
| 16471 | 16476 |
| 16472 RawBigint* Bigint::NewFromCString(const char* str, Heap::Space space) { | 16477 RawBigint* Bigint::NewFromCString(const char* str, Heap::Space space) { |
| (...skipping 3948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20421 return tag_label.ToCString(); | 20426 return tag_label.ToCString(); |
| 20422 } | 20427 } |
| 20423 | 20428 |
| 20424 | 20429 |
| 20425 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 20430 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 20426 Instance::PrintJSONImpl(stream, ref); | 20431 Instance::PrintJSONImpl(stream, ref); |
| 20427 } | 20432 } |
| 20428 | 20433 |
| 20429 | 20434 |
| 20430 } // namespace dart | 20435 } // namespace dart |
| OLD | NEW |