Chromium Code Reviews| 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 length++; // Account for leading zero for 64-bit processing. | |
|
regis
2014/11/20 22:37:23
Here too.
| |
| 16443 TypedData& old_digits = TypedData::Handle(digits()); | 16444 TypedData& old_digits = TypedData::Handle(digits()); |
| 16444 if ((length > 0) && (length > old_digits.Length())) { | 16445 if (length > old_digits.Length()) { |
| 16445 TypedData& new_digits = TypedData::Handle( | 16446 TypedData& new_digits = TypedData::Handle( |
| 16446 TypedData::New(kTypedDataUint32ArrayCid, length + kExtraDigits, space)); | 16447 TypedData::New(kTypedDataUint32ArrayCid, length + kExtraDigits, space)); |
| 16447 if (old_digits.Length() > 0) { | 16448 set_digits(new_digits); |
| 16449 if (Used() > 0) { | |
| 16448 TypedData::Copy(new_digits, TypedData::data_offset(), | 16450 TypedData::Copy(new_digits, TypedData::data_offset(), |
| 16449 old_digits, TypedData::data_offset(), | 16451 old_digits, TypedData::data_offset(), |
| 16450 old_digits.LengthInBytes()); | 16452 (Used() + 1)*kBytesPerDigit); // Copy leading zero. |
| 16451 } | 16453 } |
| 16452 set_digits(new_digits); | |
| 16453 } | 16454 } |
| 16454 } | 16455 } |
| 16455 | 16456 |
| 16456 | 16457 |
| 16457 void Bigint::Clamp() const { | 16458 void Bigint::Clamp() const { |
| 16458 intptr_t used = Used(); | 16459 intptr_t used = Used(); |
| 16459 while ((used > 0) && (DigitAt(used - 1) == 0)) { | 16460 if (used > 0) { |
| 16460 --used; | 16461 if (DigitAt(used - 1) == 0) { |
| 16462 do { | |
| 16463 --used; | |
| 16464 } while ((used > 0) && (DigitAt(used - 1) == 0)); | |
| 16465 SetUsed(used); | |
| 16466 } | |
| 16467 SetDigitAt(used, 0); // Set leading zero for 64-bit processing. | |
| 16461 } | 16468 } |
| 16462 SetUsed(used); | |
| 16463 } | 16469 } |
| 16464 | 16470 |
| 16465 | 16471 |
| 16466 bool Bigint::IsClamped() const { | 16472 bool Bigint::IsClamped() const { |
| 16467 intptr_t used = Used(); | 16473 intptr_t used = Used(); |
| 16468 return (used == 0) || (DigitAt(used - 1) > 0); | 16474 return (used == 0) || (DigitAt(used - 1) > 0); |
| 16469 } | 16475 } |
| 16470 | 16476 |
| 16471 | 16477 |
| 16472 RawBigint* Bigint::NewFromCString(const char* str, Heap::Space space) { | 16478 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(); | 20427 return tag_label.ToCString(); |
| 20422 } | 20428 } |
| 20423 | 20429 |
| 20424 | 20430 |
| 20425 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 20431 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 20426 Instance::PrintJSONImpl(stream, ref); | 20432 Instance::PrintJSONImpl(stream, ref); |
| 20427 } | 20433 } |
| 20428 | 20434 |
| 20429 | 20435 |
| 20430 } // namespace dart | 20436 } // namespace dart |
| OLD | NEW |