| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/bootstrap_natives.h" | 5 #include "vm/bootstrap_natives.h" |
| 6 | 6 |
| 7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/dart_entry.h" | 8 #include "vm/dart_entry.h" |
| 9 #include "vm/exceptions.h" | 9 #include "vm/exceptions.h" |
| 10 #include "vm/native_entry.h" | 10 #include "vm/native_entry.h" |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 return BigintOperations::ShiftLeft( | 470 return BigintOperations::ShiftLeft( |
| 471 Bigint::Handle(AsBigint(left)), right.Value()); | 471 Bigint::Handle(AsBigint(left)), right.Value()); |
| 472 } else { | 472 } else { |
| 473 int64_t left_64 = left.Value(); | 473 int64_t left_64 = left.Value(); |
| 474 return Integer::New(left_64 << right.Value()); | 474 return Integer::New(left_64 << right.Value()); |
| 475 } | 475 } |
| 476 } | 476 } |
| 477 } | 477 } |
| 478 result = left.Value() << right.Value(); | 478 result = left.Value() << right.Value(); |
| 479 break; | 479 break; |
| 480 case Token::kSAR: { | 480 case Token::kSHR: { |
| 481 int shift_amount = (right.Value() > 0x1F) ? 0x1F : right.Value(); | 481 int shift_amount = (right.Value() > 0x1F) ? 0x1F : right.Value(); |
| 482 result = left.Value() >> shift_amount; | 482 result = left.Value() >> shift_amount; |
| 483 break; | 483 break; |
| 484 } | 484 } |
| 485 default: | 485 default: |
| 486 UNIMPLEMENTED(); | 486 UNIMPLEMENTED(); |
| 487 } | 487 } |
| 488 ASSERT(Smi::IsValid(result)); | 488 ASSERT(Smi::IsValid(result)); |
| 489 return Smi::New(result); | 489 return Smi::New(result); |
| 490 } | 490 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 504 return SmiShiftOperation(kind, smi_value, amount); | 504 return SmiShiftOperation(kind, smi_value, amount); |
| 505 } | 505 } |
| 506 Bigint& big_value = Bigint::Handle(); | 506 Bigint& big_value = Bigint::Handle(); |
| 507 if (value.IsMint()) { | 507 if (value.IsMint()) { |
| 508 const int64_t mint_value = value.AsInt64Value(); | 508 const int64_t mint_value = value.AsInt64Value(); |
| 509 const int count = HighestBit(mint_value); | 509 const int count = HighestBit(mint_value); |
| 510 if ((count + amount.Value()) < Mint::kBits) { | 510 if ((count + amount.Value()) < Mint::kBits) { |
| 511 switch (kind) { | 511 switch (kind) { |
| 512 case Token::kSHL: | 512 case Token::kSHL: |
| 513 return Integer::New(mint_value << amount.Value()); | 513 return Integer::New(mint_value << amount.Value()); |
| 514 case Token::kSAR: | 514 case Token::kSHR: |
| 515 return Integer::New(mint_value >> amount.Value()); | 515 return Integer::New(mint_value >> amount.Value()); |
| 516 default: | 516 default: |
| 517 UNIMPLEMENTED(); | 517 UNIMPLEMENTED(); |
| 518 } | 518 } |
| 519 } else { | 519 } else { |
| 520 // Overflow in shift, use Bigints | 520 // Overflow in shift, use Bigints |
| 521 big_value = BigintOperations::NewFromInt64(mint_value); | 521 big_value = BigintOperations::NewFromInt64(mint_value); |
| 522 } | 522 } |
| 523 } else { | 523 } else { |
| 524 ASSERT(value.IsBigint()); | 524 ASSERT(value.IsBigint()); |
| 525 big_value ^= value.raw(); | 525 big_value ^= value.raw(); |
| 526 } | 526 } |
| 527 switch (kind) { | 527 switch (kind) { |
| 528 case Token::kSHL: | 528 case Token::kSHL: |
| 529 return BigintOperations::ShiftLeft(big_value, amount.Value()); | 529 return BigintOperations::ShiftLeft(big_value, amount.Value()); |
| 530 case Token::kSAR: | 530 case Token::kSHR: |
| 531 return BigintOperations::ShiftRight(big_value, amount.Value()); | 531 return BigintOperations::ShiftRight(big_value, amount.Value()); |
| 532 default: | 532 default: |
| 533 UNIMPLEMENTED(); | 533 UNIMPLEMENTED(); |
| 534 } | 534 } |
| 535 return Integer::null(); | 535 return Integer::null(); |
| 536 } | 536 } |
| 537 | 537 |
| 538 | 538 |
| 539 DEFINE_NATIVE_ENTRY(Smi_sarFromInt, 2) { | 539 DEFINE_NATIVE_ENTRY(Smi_sarFromInt, 2) { |
| 540 const Smi& amount = Smi::CheckedHandle(arguments->At(0)); | 540 const Smi& amount = Smi::CheckedHandle(arguments->At(0)); |
| 541 GET_NATIVE_ARGUMENT(Integer, value, arguments->At(1)); | 541 GET_NATIVE_ARGUMENT(Integer, value, arguments->At(1)); |
| 542 ASSERT(CheckInteger(amount)); | 542 ASSERT(CheckInteger(amount)); |
| 543 ASSERT(CheckInteger(value)); | 543 ASSERT(CheckInteger(value)); |
| 544 Integer& result = Integer::Handle( | 544 Integer& result = Integer::Handle( |
| 545 ShiftOperationHelper(Token::kSAR, value, amount)); | 545 ShiftOperationHelper(Token::kSHR, value, amount)); |
| 546 arguments->SetReturn(Integer::Handle(AsInteger(result))); | 546 arguments->SetReturn(Integer::Handle(AsInteger(result))); |
| 547 } | 547 } |
| 548 | 548 |
| 549 | 549 |
| 550 | 550 |
| 551 DEFINE_NATIVE_ENTRY(Smi_shlFromInt, 2) { | 551 DEFINE_NATIVE_ENTRY(Smi_shlFromInt, 2) { |
| 552 const Smi& amount = Smi::CheckedHandle(arguments->At(0)); | 552 const Smi& amount = Smi::CheckedHandle(arguments->At(0)); |
| 553 GET_NATIVE_ARGUMENT(Integer, value, arguments->At(1)); | 553 GET_NATIVE_ARGUMENT(Integer, value, arguments->At(1)); |
| 554 ASSERT(CheckInteger(amount)); | 554 ASSERT(CheckInteger(amount)); |
| 555 ASSERT(CheckInteger(value)); | 555 ASSERT(CheckInteger(value)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 | 589 |
| 590 DEFINE_NATIVE_ENTRY(Bigint_bitNegate, 1) { | 590 DEFINE_NATIVE_ENTRY(Bigint_bitNegate, 1) { |
| 591 const Bigint& value = Bigint::CheckedHandle(arguments->At(0)); | 591 const Bigint& value = Bigint::CheckedHandle(arguments->At(0)); |
| 592 const Bigint& result = Bigint::Handle(BigintOperations::BitNot(value)); | 592 const Bigint& result = Bigint::Handle(BigintOperations::BitNot(value)); |
| 593 ASSERT(CheckInteger(value)); | 593 ASSERT(CheckInteger(value)); |
| 594 ASSERT(CheckInteger(result)); | 594 ASSERT(CheckInteger(result)); |
| 595 arguments->SetReturn(Integer::Handle(AsInteger(result))); | 595 arguments->SetReturn(Integer::Handle(AsInteger(result))); |
| 596 } | 596 } |
| 597 | 597 |
| 598 } // namespace dart | 598 } // namespace dart |
| OLD | NEW |