| 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 16385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16396 result.EnsureLength(2, space); | 16396 result.EnsureLength(2, space); |
| 16397 result.SetUsed(2); | 16397 result.SetUsed(2); |
| 16398 result.SetDigitAt(0, static_cast<uint32_t>(value)); | 16398 result.SetDigitAt(0, static_cast<uint32_t>(value)); |
| 16399 result.SetDigitAt(1, static_cast<uint32_t>(value >> 32)); | 16399 result.SetDigitAt(1, static_cast<uint32_t>(value >> 32)); |
| 16400 result.Clamp(); | 16400 result.Clamp(); |
| 16401 return result.raw(); | 16401 return result.raw(); |
| 16402 } | 16402 } |
| 16403 | 16403 |
| 16404 | 16404 |
| 16405 RawBigint* Bigint::NewFromShiftedInt64(int64_t value, intptr_t shift, | 16405 RawBigint* Bigint::NewFromShiftedInt64(int64_t value, intptr_t shift, |
| 16406 Heap::Space space) { | 16406 Heap::Space space) { |
| 16407 ASSERT(kBitsPerDigit == 32); | 16407 ASSERT(kBitsPerDigit == 32); |
| 16408 ASSERT(shift >= 0); | 16408 ASSERT(shift >= 0); |
| 16409 const Bigint& result = Bigint::Handle(New(space)); | 16409 const Bigint& result = Bigint::Handle(New(space)); |
| 16410 const intptr_t digit_shift = shift / kBitsPerDigit; | 16410 const intptr_t digit_shift = shift / kBitsPerDigit; |
| 16411 const intptr_t bit_shift = shift % kBitsPerDigit; | 16411 const intptr_t bit_shift = shift % kBitsPerDigit; |
| 16412 result.EnsureLength(3 + digit_shift, space); | 16412 result.EnsureLength(3 + digit_shift, space); |
| 16413 result.SetUsed(3 + digit_shift); | 16413 result.SetUsed(3 + digit_shift); |
| 16414 uint64_t abs_value; | 16414 uint64_t abs_value; |
| 16415 if (value < 0) { | 16415 if (value < 0) { |
| 16416 result.SetNeg(true); | 16416 result.SetNeg(true); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 16427 static_cast<uint32_t>(abs_value >> (32 - bit_shift))); | 16427 static_cast<uint32_t>(abs_value >> (32 - bit_shift))); |
| 16428 result.SetDigitAt(2 + digit_shift, | 16428 result.SetDigitAt(2 + digit_shift, |
| 16429 (bit_shift == 0) ? 0 | 16429 (bit_shift == 0) ? 0 |
| 16430 : static_cast<uint32_t>(abs_value >> (64 - bit_shift))); | 16430 : static_cast<uint32_t>(abs_value >> (64 - bit_shift))); |
| 16431 result.Clamp(); | 16431 result.Clamp(); |
| 16432 return result.raw(); | 16432 return result.raw(); |
| 16433 } | 16433 } |
| 16434 | 16434 |
| 16435 | 16435 |
| 16436 void Bigint::EnsureLength(intptr_t length, Heap::Space space) const { | 16436 void Bigint::EnsureLength(intptr_t length, Heap::Space space) const { |
| 16437 ASSERT(length >= 0); | 16437 ASSERT(length > 0); |
| 16438 TypedData& old_digits = TypedData::Handle(digits()); | 16438 TypedData& old_digits = TypedData::Handle(digits()); |
| 16439 if ((length > 0) && (length > old_digits.Length())) { | 16439 if (length > old_digits.Length()) { |
| 16440 TypedData& new_digits = TypedData::Handle( | 16440 TypedData& new_digits = TypedData::Handle( |
| 16441 TypedData::New(kTypedDataUint32ArrayCid, length + kExtraDigits, space)); | 16441 TypedData::New(kTypedDataUint32ArrayCid, length + kExtraDigits, space)); |
| 16442 if (old_digits.Length() > 0) { | 16442 set_digits(new_digits); |
| 16443 if (Used() > 0) { |
| 16443 TypedData::Copy(new_digits, TypedData::data_offset(), | 16444 TypedData::Copy(new_digits, TypedData::data_offset(), |
| 16444 old_digits, TypedData::data_offset(), | 16445 old_digits, TypedData::data_offset(), |
| 16445 old_digits.LengthInBytes()); | 16446 (Used() + 1)*kBytesPerDigit); // Copy leading zero. |
| 16446 } | 16447 } |
| 16447 set_digits(new_digits); | |
| 16448 } | 16448 } |
| 16449 } | 16449 } |
| 16450 | 16450 |
| 16451 | 16451 |
| 16452 void Bigint::Clamp() const { | 16452 void Bigint::Clamp() const { |
| 16453 intptr_t used = Used(); | 16453 intptr_t used = Used(); |
| 16454 while ((used > 0) && (DigitAt(used - 1) == 0)) { | 16454 if (used > 0) { |
| 16455 --used; | 16455 if (DigitAt(used - 1) == 0) { |
| 16456 do { |
| 16457 --used; |
| 16458 } while ((used > 0) && (DigitAt(used - 1) == 0)); |
| 16459 SetUsed(used); |
| 16460 } |
| 16461 SetDigitAt(used, 0); // Set leading zero for 64-bit processing. |
| 16456 } | 16462 } |
| 16457 SetUsed(used); | |
| 16458 } | 16463 } |
| 16459 | 16464 |
| 16460 | 16465 |
| 16461 bool Bigint::IsClamped() const { | 16466 bool Bigint::IsClamped() const { |
| 16462 intptr_t used = Used(); | 16467 intptr_t used = Used(); |
| 16463 return (used == 0) || (DigitAt(used - 1) > 0); | 16468 return (used == 0) || (DigitAt(used - 1) > 0); |
| 16464 } | 16469 } |
| 16465 | 16470 |
| 16466 | 16471 |
| 16467 RawBigint* Bigint::NewFromCString(const char* str, Heap::Space space) { | 16472 RawBigint* Bigint::NewFromCString(const char* str, Heap::Space space) { |
| (...skipping 3948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20416 return tag_label.ToCString(); | 20421 return tag_label.ToCString(); |
| 20417 } | 20422 } |
| 20418 | 20423 |
| 20419 | 20424 |
| 20420 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 20425 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 20421 Instance::PrintJSONImpl(stream, ref); | 20426 Instance::PrintJSONImpl(stream, ref); |
| 20422 } | 20427 } |
| 20423 | 20428 |
| 20424 | 20429 |
| 20425 } // namespace dart | 20430 } // namespace dart |
| OLD | NEW |