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 // The intrinsic code below is executed before a method has built its frame. | 5 // The intrinsic code below is executed before a method has built its frame. |
6 // The return address is on the stack and the arguments below it. | 6 // The return address is on the stack and the arguments below it. |
7 // Registers EDX (arguments descriptor) and ECX (function) must be preserved. | 7 // Registers EDX (arguments descriptor) and ECX (function) must be preserved. |
8 // Each intrinsification method returns true if the corresponding | 8 // Each intrinsification method returns true if the corresponding |
9 // Dart method was intrinsified. | 9 // Dart method was intrinsified. |
10 | 10 |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 __ StoreIntoObject(EAX, | 240 __ StoreIntoObject(EAX, |
241 FieldAddress(EAX, EBX, TIMES_2, sizeof(RawArray)), | 241 FieldAddress(EAX, EBX, TIMES_2, sizeof(RawArray)), |
242 ECX); | 242 ECX); |
243 // Caller is responsible of preserving the value if necessary. | 243 // Caller is responsible of preserving the value if necessary. |
244 __ ret(); | 244 __ ret(); |
245 __ Bind(&fall_through); | 245 __ Bind(&fall_through); |
246 return false; | 246 return false; |
247 } | 247 } |
248 | 248 |
249 | 249 |
250 static intptr_t GetOffsetForField(const char* class_name_p, | |
251 const char* field_name_p) { | |
252 const String& class_name = String::Handle(Symbols::New(class_name_p)); | |
253 const String& field_name = String::Handle(Symbols::New(field_name_p)); | |
254 const Library& core_lib = Library::Handle(Library::CoreLibrary()); | |
255 const Class& cls = | |
256 Class::Handle(core_lib.LookupClassAllowPrivate(class_name)); | |
257 ASSERT(!cls.IsNull()); | |
258 const Field& field = Field::ZoneHandle(cls.LookupInstanceField(field_name)); | |
259 ASSERT(!field.IsNull()); | |
260 return field.Offset(); | |
261 } | |
262 | |
263 | |
264 // Allocate a GrowableObjectArray using the backing array specified. | 250 // Allocate a GrowableObjectArray using the backing array specified. |
265 // On stack: type argument (+2), data (+1), return-address (+0). | 251 // On stack: type argument (+2), data (+1), return-address (+0). |
266 bool Intrinsifier::GArray_Allocate(Assembler* assembler) { | 252 bool Intrinsifier::GArray_Allocate(Assembler* assembler) { |
267 // This snippet of inlined code uses the following registers: | 253 // This snippet of inlined code uses the following registers: |
268 // EAX, EBX | 254 // EAX, EBX |
269 // and the newly allocated object is returned in EAX. | 255 // and the newly allocated object is returned in EAX. |
270 const intptr_t kTypeArgumentsOffset = 2 * kWordSize; | 256 const intptr_t kTypeArgumentsOffset = 2 * kWordSize; |
271 const intptr_t kArrayOffset = 1 * kWordSize; | 257 const intptr_t kArrayOffset = 1 * kWordSize; |
272 Label fall_through; | 258 Label fall_through; |
273 | 259 |
(...skipping 1338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1612 __ j(EQUAL, &is_true, Assembler::kNearJump); | 1598 __ j(EQUAL, &is_true, Assembler::kNearJump); |
1613 __ LoadObject(EAX, Bool::False()); | 1599 __ LoadObject(EAX, Bool::False()); |
1614 __ ret(); | 1600 __ ret(); |
1615 __ Bind(&is_true); | 1601 __ Bind(&is_true); |
1616 __ LoadObject(EAX, Bool::True()); | 1602 __ LoadObject(EAX, Bool::True()); |
1617 __ ret(); | 1603 __ ret(); |
1618 return true; | 1604 return true; |
1619 } | 1605 } |
1620 | 1606 |
1621 | 1607 |
1622 static const char* kFixedSizeArrayIteratorClassName = "_FixedSizeArrayIterator"; | |
1623 | |
1624 | |
1625 // Class 'FixedSizeArrayIterator': | |
1626 // T next() { | |
1627 // return _array[_pos++]; | |
1628 // } | |
1629 // Intrinsify: return _array[_pos++]; | |
1630 // TODO(srdjan): Throw a 'StateError' exception if the iterator | |
1631 // has no more elements. | |
1632 bool Intrinsifier::FixedSizeArrayIterator_next(Assembler* assembler) { | |
1633 Label fall_through; | |
1634 intptr_t array_offset = | |
1635 GetOffsetForField(kFixedSizeArrayIteratorClassName, "_array"); | |
1636 intptr_t pos_offset = | |
1637 GetOffsetForField(kFixedSizeArrayIteratorClassName, "_pos"); | |
1638 ASSERT(array_offset >= 0 && pos_offset >= 0); | |
1639 // Receiver is not NULL. | |
1640 __ movl(EAX, Address(ESP, + 1 * kWordSize)); // Receiver. | |
1641 __ movl(EBX, FieldAddress(EAX, pos_offset)); // Field _pos. | |
1642 // '_pos' cannot be greater than array length and therefore is always Smi. | |
1643 #if defined(DEBUG) | |
1644 Label pos_ok; | |
1645 __ testl(EBX, Immediate(kSmiTagMask)); | |
1646 __ j(ZERO, &pos_ok, Assembler::kNearJump); | |
1647 __ Stop("pos must be Smi"); | |
1648 __ Bind(&pos_ok); | |
1649 #endif | |
1650 // Check that we are not trying to call 'next' when 'hasNext' is false. | |
1651 __ movl(EAX, FieldAddress(EAX, array_offset)); // Field _array. | |
1652 __ cmpl(EBX, FieldAddress(EAX, Array::length_offset())); // Range check. | |
1653 __ j(ABOVE_EQUAL, &fall_through, Assembler::kNearJump); | |
1654 | |
1655 // EBX is Smi, i.e, times 2. | |
1656 ASSERT(kSmiTagShift == 1); | |
1657 __ movl(EDI, FieldAddress(EAX, EBX, TIMES_2, sizeof(RawArray))); // Result. | |
1658 const Immediate value = Immediate(reinterpret_cast<int32_t>(Smi::New(1))); | |
1659 __ addl(EBX, value); // _pos++. | |
1660 __ j(OVERFLOW, &fall_through, Assembler::kNearJump); | |
1661 __ movl(EAX, Address(ESP, + 1 * kWordSize)); // Receiver. | |
1662 __ StoreIntoObjectNoBarrier(EAX, | |
1663 FieldAddress(EAX, pos_offset), | |
1664 EBX); // Store _pos. | |
1665 __ movl(EAX, EDI); | |
1666 __ ret(); | |
1667 __ Bind(&fall_through); | |
1668 return false; | |
1669 } | |
1670 | |
1671 | |
1672 // Class 'FixedSizeArrayIterator': | |
1673 // bool get hasNext { | |
1674 // return _length > _pos; | |
1675 // } | |
1676 bool Intrinsifier::FixedSizeArrayIterator_getHasNext(Assembler* assembler) { | |
1677 Label fall_through, is_true; | |
1678 intptr_t length_offset = | |
1679 GetOffsetForField(kFixedSizeArrayIteratorClassName, "_length"); | |
1680 intptr_t pos_offset = | |
1681 GetOffsetForField(kFixedSizeArrayIteratorClassName, "_pos"); | |
1682 __ movl(EAX, Address(ESP, + 1 * kWordSize)); // Receiver. | |
1683 __ movl(EBX, FieldAddress(EAX, length_offset)); // Field _length. | |
1684 __ movl(EAX, FieldAddress(EAX, pos_offset)); // Field _pos. | |
1685 __ movl(EDI, EAX); | |
1686 __ orl(EDI, EBX); | |
1687 __ testl(EDI, Immediate(kSmiTagMask)); | |
1688 __ j(NOT_ZERO, &fall_through, Assembler::kNearJump); // Non-smi _length. | |
1689 __ cmpl(EBX, EAX); // _length > _pos. | |
1690 __ j(GREATER, &is_true, Assembler::kNearJump); | |
1691 __ LoadObject(EAX, Bool::False()); | |
1692 __ ret(); | |
1693 __ Bind(&is_true); | |
1694 __ LoadObject(EAX, Bool::True()); | |
1695 __ ret(); | |
1696 __ Bind(&fall_through); | |
1697 return false; | |
1698 } | |
1699 | |
1700 | |
1701 bool Intrinsifier::String_getHashCode(Assembler* assembler) { | 1608 bool Intrinsifier::String_getHashCode(Assembler* assembler) { |
1702 Label fall_through; | 1609 Label fall_through; |
1703 __ movl(EAX, Address(ESP, + 1 * kWordSize)); // String object. | 1610 __ movl(EAX, Address(ESP, + 1 * kWordSize)); // String object. |
1704 __ movl(EAX, FieldAddress(EAX, String::hash_offset())); | 1611 __ movl(EAX, FieldAddress(EAX, String::hash_offset())); |
1705 __ cmpl(EAX, Immediate(0)); | 1612 __ cmpl(EAX, Immediate(0)); |
1706 __ j(EQUAL, &fall_through, Assembler::kNearJump); | 1613 __ j(EQUAL, &fall_through, Assembler::kNearJump); |
1707 __ ret(); | 1614 __ ret(); |
1708 __ Bind(&fall_through); | 1615 __ Bind(&fall_through); |
1709 // Hash not yet computed. | 1616 // Hash not yet computed. |
1710 return false; | 1617 return false; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1753 __ Bind(&is_true); | 1660 __ Bind(&is_true); |
1754 __ LoadObject(EAX, Bool::True()); | 1661 __ LoadObject(EAX, Bool::True()); |
1755 __ ret(); | 1662 __ ret(); |
1756 return true; | 1663 return true; |
1757 } | 1664 } |
1758 | 1665 |
1759 #undef __ | 1666 #undef __ |
1760 } // namespace dart | 1667 } // namespace dart |
1761 | 1668 |
1762 #endif // defined TARGET_ARCH_IA32 | 1669 #endif // defined TARGET_ARCH_IA32 |
OLD | NEW |