Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: runtime/vm/intrinsifier_ia32.cc

Issue 2379733002: Recognize and optimize a.runtimeType == b.runtimeType pattern. (Closed)
Patch Set: port to all arch, make AOT opt non-speculative Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 1667 matching lines...) Expand 10 before | Expand all | Expand 10 after
1678 __ cmpl(EAX, Address(ESP, + 2 * kWordSize)); 1678 __ cmpl(EAX, Address(ESP, + 2 * kWordSize));
1679 __ j(EQUAL, &is_true, Assembler::kNearJump); 1679 __ j(EQUAL, &is_true, Assembler::kNearJump);
1680 __ LoadObject(EAX, Bool::False()); 1680 __ LoadObject(EAX, Bool::False());
1681 __ ret(); 1681 __ ret();
1682 __ Bind(&is_true); 1682 __ Bind(&is_true);
1683 __ LoadObject(EAX, Bool::True()); 1683 __ LoadObject(EAX, Bool::True());
1684 __ ret(); 1684 __ ret();
1685 } 1685 }
1686 1686
1687 1687
1688 static void RangeCheck(Assembler* assembler,
1689 Register reg,
1690 intptr_t low,
1691 intptr_t high,
1692 Condition cc,
1693 Label* target) {
1694 __ subl(reg, Immediate(low));
1695 __ cmpl(reg, Immediate(high - low));
1696 __ j(cc, target);
1697 }
1698
1699
1700 const Condition kIfNotInRange = ABOVE;
1701 const Condition kIfInRange = BELOW_EQUAL;
1702
1703
1704 static void JumpIfInteger(Assembler* assembler,
1705 Register cid,
1706 Label* target) {
1707 RangeCheck(assembler, cid, kSmiCid, kBigintCid, kIfInRange, target);
1708 }
1709
1710
1711 static void JumpIfNotInteger(Assembler* assembler,
1712 Register cid,
1713 Label* target) {
1714 RangeCheck(assembler, cid, kSmiCid, kBigintCid, kIfNotInRange, target);
1715 }
1716
1717
1718 static void JumpIfString(Assembler* assembler,
1719 Register cid,
1720 Label* target) {
1721 RangeCheck(assembler,
1722 cid,
1723 kOneByteStringCid,
1724 kExternalTwoByteStringCid,
1725 kIfInRange,
1726 target);
1727 }
1728
1729
1730 static void JumpIfNotString(Assembler* assembler,
1731 Register cid,
1732 Label* target) {
1733 RangeCheck(assembler,
1734 cid,
1735 kOneByteStringCid,
1736 kExternalTwoByteStringCid,
1737 kIfNotInRange,
1738 target);
1739 }
1740
1741
1688 // Return type quickly for simple types (not parameterized and not signature). 1742 // Return type quickly for simple types (not parameterized and not signature).
1689 void Intrinsifier::ObjectRuntimeType(Assembler* assembler) { 1743 void Intrinsifier::ObjectRuntimeType(Assembler* assembler) {
1690 Label fall_through; 1744 Label fall_through, use_canonical_type, not_double, not_integer;
1691 __ movl(EAX, Address(ESP, + 1 * kWordSize)); 1745 __ movl(EAX, Address(ESP, + 1 * kWordSize));
1692 __ LoadClassIdMayBeSmi(EDI, EAX); 1746 __ LoadClassIdMayBeSmi(EDI, EAX);
1747
1693 __ cmpl(EDI, Immediate(kClosureCid)); 1748 __ cmpl(EDI, Immediate(kClosureCid));
1694 __ j(EQUAL, &fall_through, Assembler::kNearJump); // Instance is a closure. 1749 __ j(EQUAL, &fall_through); // Instance is a closure.
1750
1751 __ cmpl(EDI, Immediate(kNumPredefinedCids));
1752 __ j(ABOVE, &use_canonical_type);
1753
1754 // If object is a instance of _Double return double type.
1755 __ cmpl(EDI, Immediate(kDoubleCid));
1756 __ j(NOT_EQUAL, &not_double);
1757
1758 __ LoadIsolate(EAX);
1759 __ movl(EAX, Address(EAX, Isolate::object_store_offset()));
1760 __ movl(EAX, Address(EAX, ObjectStore::double_type_offset()));
1761 __ ret();
1762
1763 __ Bind(&not_double);
1764 // If object is an integer (smi, mint or bigint) return int type.
1765 __ movl(EAX, EDI);
1766 JumpIfNotInteger(assembler, EAX, &not_integer);
1767
1768 __ LoadIsolate(EAX);
1769 __ movl(EAX, Address(EAX, Isolate::object_store_offset()));
1770 __ movl(EAX, Address(EAX, ObjectStore::int_type_offset()));
1771 __ ret();
1772
1773 __ Bind(&not_integer);
1774 // If object is a string (one byte, two byte or external variants) return
1775 // string type.
1776 __ movl(EAX, EDI);
1777 JumpIfNotString(assembler, EAX, &use_canonical_type);
1778
1779 __ LoadIsolate(EAX);
1780 __ movl(EAX, Address(EAX, Isolate::object_store_offset()));
1781 __ movl(EAX, Address(EAX, ObjectStore::string_type_offset()));
1782 __ ret();
1783
1784 // Object is neither double, nor integer, nor string.
1785 __ Bind(&use_canonical_type);
1695 __ LoadClassById(EBX, EDI); 1786 __ LoadClassById(EBX, EDI);
1696 // EBX: class of instance (EAX).
1697
1698 __ movzxw(EDI, FieldAddress(EBX, Class::num_type_arguments_offset())); 1787 __ movzxw(EDI, FieldAddress(EBX, Class::num_type_arguments_offset()));
1699 __ cmpl(EDI, Immediate(0)); 1788 __ cmpl(EDI, Immediate(0));
1700 __ j(NOT_EQUAL, &fall_through, Assembler::kNearJump); 1789 __ j(NOT_EQUAL, &fall_through, Assembler::kNearJump);
1701 __ movl(EAX, FieldAddress(EBX, Class::canonical_type_offset())); 1790 __ movl(EAX, FieldAddress(EBX, Class::canonical_type_offset()));
1702 __ CompareObject(EAX, Object::null_object()); 1791 __ CompareObject(EAX, Object::null_object());
1703 __ j(EQUAL, &fall_through, Assembler::kNearJump); // Not yet set. 1792 __ j(EQUAL, &fall_through, Assembler::kNearJump); // Not yet set.
1704 __ ret(); 1793 __ ret();
1705 1794
1706 __ Bind(&fall_through); 1795 __ Bind(&fall_through);
1707 } 1796 }
1708 1797
1709 1798
1799 void Intrinsifier::ObjectHaveSameRuntimeType(Assembler* assembler) {
1800 Label fall_through, different_cids, equal, not_equal, not_integer;
1801
1802 __ movl(EAX, Address(ESP, + 1 * kWordSize));
1803 __ LoadClassIdMayBeSmi(EDI, EAX);
1804
1805 // Check if left hand size is a closure. Closures are handled in the runtime.
1806 __ cmpl(EDI, Immediate(kClosureCid));
1807 __ j(EQUAL, &fall_through);
1808
1809 __ movl(EAX, Address(ESP, + 2 * kWordSize));
1810 __ LoadClassIdMayBeSmi(EBX, EAX);
1811
1812 // Check whether class ids match. If class ids don't match objects can still
1813 // have the same runtime type (e.g. multiple string implementation classes
1814 // map to a single String type).
1815 __ cmpl(EDI, EBX);
1816 __ j(NOT_EQUAL, &different_cids);
1817
1818 // Objects have the same class and neither is a closure.
1819 // Check if there are no type arguments. In this case we can return true.
1820 // Otherwise fall through into the runtime to handle comparison.
1821 __ LoadClassById(EBX, EDI);
1822 __ movzxw(EBX, FieldAddress(EBX, Class::num_type_arguments_offset()));
regis 2016/10/08 09:10:37 ditto
Vyacheslav Egorov (Google) 2016/10/24 20:23:03 Acknowledged.
1823 __ cmpl(EBX, Immediate(0));
1824 __ j(NOT_EQUAL, &fall_through, Assembler::kNearJump);
1825
1826 __ Bind(&equal);
1827 __ LoadObject(EAX, Bool::True());
1828 __ ret();
1829
1830 // Class ids are different. Check if we are comparing runtime types of
1831 // two strings (with different representations) or two integers.
1832 __ Bind(&different_cids);
1833 __ cmpl(EDI, Immediate(kNumPredefinedCids));
1834 __ j(ABOVE_EQUAL, &not_equal);
1835
1836 __ movl(EAX, EDI);
1837 JumpIfNotInteger(assembler, EAX, &not_integer);
1838
1839 // First object is an integer. Check if the second is an integer too.
1840 // Otherwise types are unequal because only integers have the same runtime
1841 // type as other integers.
1842 JumpIfInteger(assembler, EBX, &equal);
1843 __ jmp(&not_equal);
1844
1845 __ Bind(&not_integer);
1846 // Check if the first object is a string. If it is not then
1847 // objects don't have the same runtime type because they have
1848 // different class ids and they are not strings or integers.
1849 JumpIfNotString(assembler, EDI, &not_equal);
1850 // First object is a string. Check if the second is a string too.
1851 JumpIfString(assembler, EBX, &equal);
1852 // Strings only have the same runtime type as other strings.
1853 // Fall-through to the not equal case.
1854
1855 __ Bind(&not_equal);
1856 __ LoadObject(EAX, Bool::False());
1857 __ ret();
1858
1859 __ Bind(&fall_through);
1860 }
1861
1862
1710 void Intrinsifier::String_getHashCode(Assembler* assembler) { 1863 void Intrinsifier::String_getHashCode(Assembler* assembler) {
1711 Label fall_through; 1864 Label fall_through;
1712 __ movl(EAX, Address(ESP, + 1 * kWordSize)); // String object. 1865 __ movl(EAX, Address(ESP, + 1 * kWordSize)); // String object.
1713 __ movl(EAX, FieldAddress(EAX, String::hash_offset())); 1866 __ movl(EAX, FieldAddress(EAX, String::hash_offset()));
1714 __ cmpl(EAX, Immediate(0)); 1867 __ cmpl(EAX, Immediate(0));
1715 __ j(EQUAL, &fall_through, Assembler::kNearJump); 1868 __ j(EQUAL, &fall_through, Assembler::kNearJump);
1716 __ ret(); 1869 __ ret();
1717 __ Bind(&fall_through); 1870 __ Bind(&fall_through);
1718 // Hash not yet computed. 1871 // Hash not yet computed.
1719 } 1872 }
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
2154 __ Bind(&true_label); 2307 __ Bind(&true_label);
2155 __ LoadObject(EAX, Bool::True()); 2308 __ LoadObject(EAX, Bool::True());
2156 __ ret(); 2309 __ ret();
2157 } 2310 }
2158 2311
2159 #undef __ 2312 #undef __
2160 2313
2161 } // namespace dart 2314 } // namespace dart
2162 2315
2163 #endif // defined TARGET_ARCH_IA32 2316 #endif // defined TARGET_ARCH_IA32
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698