| 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/globals.h" // Needed here to get TARGET_ARCH_X64. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. |
| 6 #if defined(TARGET_ARCH_X64) | 6 #if defined(TARGET_ARCH_X64) |
| 7 | 7 |
| 8 #include "vm/intrinsifier.h" | 8 #include "vm/intrinsifier.h" |
| 9 | 9 |
| 10 #include "vm/assembler.h" | 10 #include "vm/assembler.h" |
| (...skipping 1461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1472 __ j(EQUAL, &is_true, Assembler::kNearJump); | 1472 __ j(EQUAL, &is_true, Assembler::kNearJump); |
| 1473 __ LoadObject(RAX, Bool::False()); | 1473 __ LoadObject(RAX, Bool::False()); |
| 1474 __ ret(); | 1474 __ ret(); |
| 1475 __ Bind(&is_true); | 1475 __ Bind(&is_true); |
| 1476 __ LoadObject(RAX, Bool::True()); | 1476 __ LoadObject(RAX, Bool::True()); |
| 1477 __ ret(); | 1477 __ ret(); |
| 1478 return true; | 1478 return true; |
| 1479 } | 1479 } |
| 1480 | 1480 |
| 1481 | 1481 |
| 1482 static intptr_t GetOffsetForField(const char* class_name_p, | |
| 1483 const char* field_name_p) { | |
| 1484 const String& class_name = String::Handle(Symbols::New(class_name_p)); | |
| 1485 const String& field_name = String::Handle(Symbols::New(field_name_p)); | |
| 1486 const Library& core_lib = Library::Handle(Library::CoreLibrary()); | |
| 1487 const Class& cls = | |
| 1488 Class::Handle(core_lib.LookupClassAllowPrivate(class_name)); | |
| 1489 ASSERT(!cls.IsNull()); | |
| 1490 const Field& field = Field::ZoneHandle(cls.LookupInstanceField(field_name)); | |
| 1491 ASSERT(!field.IsNull()); | |
| 1492 return field.Offset(); | |
| 1493 } | |
| 1494 | |
| 1495 | |
| 1496 static const char* kFixedSizeArrayIteratorClassName = "_FixedSizeArrayIterator"; | |
| 1497 | |
| 1498 // Class 'FixedSizeArrayIterator': | |
| 1499 // T next() { | |
| 1500 // return _array[_pos++]; | |
| 1501 // } | |
| 1502 // Intrinsify: return _array[_pos++]; | |
| 1503 // TODO(srdjan): Throw a 'StateError' exception if the iterator | |
| 1504 // has no more elements. | |
| 1505 bool Intrinsifier::FixedSizeArrayIterator_next(Assembler* assembler) { | |
| 1506 Label fall_through; | |
| 1507 const intptr_t array_offset = | |
| 1508 GetOffsetForField(kFixedSizeArrayIteratorClassName, "_array"); | |
| 1509 const intptr_t pos_offset = | |
| 1510 GetOffsetForField(kFixedSizeArrayIteratorClassName, "_pos"); | |
| 1511 ASSERT((array_offset >= 0) && (pos_offset >= 0)); | |
| 1512 // Receiver is not NULL. | |
| 1513 __ movq(RAX, Address(RSP, + 1 * kWordSize)); // Receiver. | |
| 1514 __ movq(RCX, FieldAddress(RAX, pos_offset)); // Field _pos. | |
| 1515 // '_pos' cannot be greater than array length and therefore is always Smi. | |
| 1516 #if defined(DEBUG) | |
| 1517 Label pos_ok; | |
| 1518 __ testq(RCX, Immediate(kSmiTagMask)); | |
| 1519 __ j(ZERO, &pos_ok, Assembler::kNearJump); | |
| 1520 __ Stop("pos must be Smi"); | |
| 1521 __ Bind(&pos_ok); | |
| 1522 #endif | |
| 1523 // Check that we are not trying to call 'next' when 'hasNext' is false. | |
| 1524 __ movq(RAX, FieldAddress(RAX, array_offset)); // Field _array. | |
| 1525 __ cmpq(RCX, FieldAddress(RAX, Array::length_offset())); // Range check. | |
| 1526 __ j(ABOVE_EQUAL, &fall_through, Assembler::kNearJump); | |
| 1527 | |
| 1528 // RCX is Smi, i.e, times 2. | |
| 1529 ASSERT(kSmiTagShift == 1); | |
| 1530 __ movq(RDI, FieldAddress(RAX, RCX, TIMES_4, sizeof(RawArray))); // Result. | |
| 1531 const Immediate value = Immediate(reinterpret_cast<int64_t>(Smi::New(1))); | |
| 1532 __ addq(RCX, value); // _pos++. | |
| 1533 __ j(OVERFLOW, &fall_through, Assembler::kNearJump); | |
| 1534 __ movq(RAX, Address(RSP, + 1 * kWordSize)); // Receiver. | |
| 1535 __ StoreIntoObjectNoBarrier(RAX, | |
| 1536 FieldAddress(RAX, pos_offset), | |
| 1537 RCX); // Store _pos. | |
| 1538 __ movq(RAX, RDI); | |
| 1539 __ ret(); | |
| 1540 __ Bind(&fall_through); | |
| 1541 return false; | |
| 1542 } | |
| 1543 | |
| 1544 | |
| 1545 // Class 'FixedSizeArrayIterator': | |
| 1546 // bool get hasNext { | |
| 1547 // return _length > _pos; | |
| 1548 // } | |
| 1549 bool Intrinsifier::FixedSizeArrayIterator_getHasNext(Assembler* assembler) { | |
| 1550 Label fall_through, is_true; | |
| 1551 const intptr_t length_offset = | |
| 1552 GetOffsetForField(kFixedSizeArrayIteratorClassName, "_length"); | |
| 1553 const intptr_t pos_offset = | |
| 1554 GetOffsetForField(kFixedSizeArrayIteratorClassName, "_pos"); | |
| 1555 __ movq(RAX, Address(RSP, + 1 * kWordSize)); // Receiver. | |
| 1556 __ movq(RCX, FieldAddress(RAX, length_offset)); // Field _length. | |
| 1557 __ movq(RAX, FieldAddress(RAX, pos_offset)); // Field _pos. | |
| 1558 __ movq(RDI, RAX); | |
| 1559 __ orq(RDI, RCX); | |
| 1560 __ testq(RDI, Immediate(kSmiTagMask)); | |
| 1561 __ j(NOT_ZERO, &fall_through, Assembler::kNearJump); // Non-smi _length/_pos. | |
| 1562 __ cmpq(RCX, RAX); // _length > _pos. | |
| 1563 __ j(GREATER, &is_true, Assembler::kNearJump); | |
| 1564 __ LoadObject(RAX, Bool::False()); | |
| 1565 __ ret(); | |
| 1566 __ Bind(&is_true); | |
| 1567 __ LoadObject(RAX, Bool::True()); | |
| 1568 __ ret(); | |
| 1569 __ Bind(&fall_through); | |
| 1570 return false; | |
| 1571 } | |
| 1572 | |
| 1573 | |
| 1574 bool Intrinsifier::String_getHashCode(Assembler* assembler) { | 1482 bool Intrinsifier::String_getHashCode(Assembler* assembler) { |
| 1575 Label fall_through; | 1483 Label fall_through; |
| 1576 __ movq(RAX, Address(RSP, + 1 * kWordSize)); // String object. | 1484 __ movq(RAX, Address(RSP, + 1 * kWordSize)); // String object. |
| 1577 __ movq(RAX, FieldAddress(RAX, String::hash_offset())); | 1485 __ movq(RAX, FieldAddress(RAX, String::hash_offset())); |
| 1578 __ cmpq(RAX, Immediate(0)); | 1486 __ cmpq(RAX, Immediate(0)); |
| 1579 __ j(EQUAL, &fall_through, Assembler::kNearJump); | 1487 __ j(EQUAL, &fall_through, Assembler::kNearJump); |
| 1580 __ ret(); | 1488 __ ret(); |
| 1581 __ Bind(&fall_through); | 1489 __ Bind(&fall_through); |
| 1582 // Hash not yet computed. | 1490 // Hash not yet computed. |
| 1583 return false; | 1491 return false; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1627 __ LoadObject(RAX, Bool::True()); | 1535 __ LoadObject(RAX, Bool::True()); |
| 1628 __ ret(); | 1536 __ ret(); |
| 1629 return true; | 1537 return true; |
| 1630 } | 1538 } |
| 1631 | 1539 |
| 1632 #undef __ | 1540 #undef __ |
| 1633 | 1541 |
| 1634 } // namespace dart | 1542 } // namespace dart |
| 1635 | 1543 |
| 1636 #endif // defined TARGET_ARCH_X64 | 1544 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |