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

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

Issue 2453463006: Revert "Revert "Recognize and optimize a.runtimeType == b.runtimeType pattern."" (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « runtime/vm/intrinsifier_arm64.cc ('k') | runtime/vm/intrinsifier_mips.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1691 matching lines...) Expand 10 before | Expand all | Expand 10 after
1702 __ cmpl(EAX, Address(ESP, + 2 * kWordSize)); 1702 __ cmpl(EAX, Address(ESP, + 2 * kWordSize));
1703 __ j(EQUAL, &is_true, Assembler::kNearJump); 1703 __ j(EQUAL, &is_true, Assembler::kNearJump);
1704 __ LoadObject(EAX, Bool::False()); 1704 __ LoadObject(EAX, Bool::False());
1705 __ ret(); 1705 __ ret();
1706 __ Bind(&is_true); 1706 __ Bind(&is_true);
1707 __ LoadObject(EAX, Bool::True()); 1707 __ LoadObject(EAX, Bool::True());
1708 __ ret(); 1708 __ ret();
1709 } 1709 }
1710 1710
1711 1711
1712 static void RangeCheck(Assembler* assembler,
1713 Register reg,
1714 intptr_t low,
1715 intptr_t high,
1716 Condition cc,
1717 Label* target) {
1718 __ subl(reg, Immediate(low));
1719 __ cmpl(reg, Immediate(high - low));
1720 __ j(cc, target);
1721 }
1722
1723
1724 const Condition kIfNotInRange = ABOVE;
1725 const Condition kIfInRange = BELOW_EQUAL;
1726
1727
1728 static void JumpIfInteger(Assembler* assembler,
1729 Register cid,
1730 Label* target) {
1731 RangeCheck(assembler, cid, kSmiCid, kBigintCid, kIfInRange, target);
1732 }
1733
1734
1735 static void JumpIfNotInteger(Assembler* assembler,
1736 Register cid,
1737 Label* target) {
1738 RangeCheck(assembler, cid, kSmiCid, kBigintCid, kIfNotInRange, target);
1739 }
1740
1741
1742 static void JumpIfString(Assembler* assembler,
1743 Register cid,
1744 Label* target) {
1745 RangeCheck(assembler,
1746 cid,
1747 kOneByteStringCid,
1748 kExternalTwoByteStringCid,
1749 kIfInRange,
1750 target);
1751 }
1752
1753
1754 static void JumpIfNotString(Assembler* assembler,
1755 Register cid,
1756 Label* target) {
1757 RangeCheck(assembler,
1758 cid,
1759 kOneByteStringCid,
1760 kExternalTwoByteStringCid,
1761 kIfNotInRange,
1762 target);
1763 }
1764
1765
1712 // Return type quickly for simple types (not parameterized and not signature). 1766 // Return type quickly for simple types (not parameterized and not signature).
1713 void Intrinsifier::ObjectRuntimeType(Assembler* assembler) { 1767 void Intrinsifier::ObjectRuntimeType(Assembler* assembler) {
1714 Label fall_through; 1768 Label fall_through, use_canonical_type, not_double, not_integer;
1715 __ movl(EAX, Address(ESP, + 1 * kWordSize)); 1769 __ movl(EAX, Address(ESP, + 1 * kWordSize));
1716 __ LoadClassIdMayBeSmi(EDI, EAX); 1770 __ LoadClassIdMayBeSmi(EDI, EAX);
1771
1717 __ cmpl(EDI, Immediate(kClosureCid)); 1772 __ cmpl(EDI, Immediate(kClosureCid));
1718 __ j(EQUAL, &fall_through, Assembler::kNearJump); // Instance is a closure. 1773 __ j(EQUAL, &fall_through); // Instance is a closure.
1774
1775 __ cmpl(EDI, Immediate(kNumPredefinedCids));
1776 __ j(ABOVE, &use_canonical_type);
1777
1778 // If object is a instance of _Double return double type.
1779 __ cmpl(EDI, Immediate(kDoubleCid));
1780 __ j(NOT_EQUAL, &not_double);
1781
1782 __ LoadIsolate(EAX);
1783 __ movl(EAX, Address(EAX, Isolate::object_store_offset()));
1784 __ movl(EAX, Address(EAX, ObjectStore::double_type_offset()));
1785 __ ret();
1786
1787 __ Bind(&not_double);
1788 // If object is an integer (smi, mint or bigint) return int type.
1789 __ movl(EAX, EDI);
1790 JumpIfNotInteger(assembler, EAX, &not_integer);
1791
1792 __ LoadIsolate(EAX);
1793 __ movl(EAX, Address(EAX, Isolate::object_store_offset()));
1794 __ movl(EAX, Address(EAX, ObjectStore::int_type_offset()));
1795 __ ret();
1796
1797 __ Bind(&not_integer);
1798 // If object is a string (one byte, two byte or external variants) return
1799 // string type.
1800 __ movl(EAX, EDI);
1801 JumpIfNotString(assembler, EAX, &use_canonical_type);
1802
1803 __ LoadIsolate(EAX);
1804 __ movl(EAX, Address(EAX, Isolate::object_store_offset()));
1805 __ movl(EAX, Address(EAX, ObjectStore::string_type_offset()));
1806 __ ret();
1807
1808 // Object is neither double, nor integer, nor string.
1809 __ Bind(&use_canonical_type);
1719 __ LoadClassById(EBX, EDI); 1810 __ LoadClassById(EBX, EDI);
1720 // EBX: class of instance (EAX).
1721
1722 __ movzxw(EDI, FieldAddress(EBX, Class::num_type_arguments_offset())); 1811 __ movzxw(EDI, FieldAddress(EBX, Class::num_type_arguments_offset()));
1723 __ cmpl(EDI, Immediate(0)); 1812 __ cmpl(EDI, Immediate(0));
1724 __ j(NOT_EQUAL, &fall_through, Assembler::kNearJump); 1813 __ j(NOT_EQUAL, &fall_through, Assembler::kNearJump);
1725 __ movl(EAX, FieldAddress(EBX, Class::canonical_type_offset())); 1814 __ movl(EAX, FieldAddress(EBX, Class::canonical_type_offset()));
1726 __ CompareObject(EAX, Object::null_object()); 1815 __ CompareObject(EAX, Object::null_object());
1727 __ j(EQUAL, &fall_through, Assembler::kNearJump); // Not yet set. 1816 __ j(EQUAL, &fall_through, Assembler::kNearJump); // Not yet set.
1728 __ ret(); 1817 __ ret();
1729 1818
1730 __ Bind(&fall_through); 1819 __ Bind(&fall_through);
1731 } 1820 }
1732 1821
1733 1822
1823 void Intrinsifier::ObjectHaveSameRuntimeType(Assembler* assembler) {
1824 Label fall_through, different_cids, equal, not_equal, not_integer;
1825
1826 __ movl(EAX, Address(ESP, + 1 * kWordSize));
1827 __ LoadClassIdMayBeSmi(EDI, EAX);
1828
1829 // Check if left hand size is a closure. Closures are handled in the runtime.
1830 __ cmpl(EDI, Immediate(kClosureCid));
1831 __ j(EQUAL, &fall_through);
1832
1833 __ movl(EAX, Address(ESP, + 2 * kWordSize));
1834 __ LoadClassIdMayBeSmi(EBX, EAX);
1835
1836 // Check whether class ids match. If class ids don't match objects can still
1837 // have the same runtime type (e.g. multiple string implementation classes
1838 // map to a single String type).
1839 __ cmpl(EDI, EBX);
1840 __ j(NOT_EQUAL, &different_cids);
1841
1842 // Objects have the same class and neither is a closure.
1843 // Check if there are no type arguments. In this case we can return true.
1844 // Otherwise fall through into the runtime to handle comparison.
1845 __ LoadClassById(EBX, EDI);
1846 __ movzxw(EBX, FieldAddress(EBX, Class::num_type_arguments_offset()));
1847 __ cmpl(EBX, Immediate(0));
1848 __ j(NOT_EQUAL, &fall_through, Assembler::kNearJump);
1849
1850 __ Bind(&equal);
1851 __ LoadObject(EAX, Bool::True());
1852 __ ret();
1853
1854 // Class ids are different. Check if we are comparing runtime types of
1855 // two strings (with different representations) or two integers.
1856 __ Bind(&different_cids);
1857 __ cmpl(EDI, Immediate(kNumPredefinedCids));
1858 __ j(ABOVE_EQUAL, &not_equal);
1859
1860 __ movl(EAX, EDI);
1861 JumpIfNotInteger(assembler, EAX, &not_integer);
1862
1863 // First object is an integer. Check if the second is an integer too.
1864 // Otherwise types are unequal because only integers have the same runtime
1865 // type as other integers.
1866 JumpIfInteger(assembler, EBX, &equal);
1867 __ jmp(&not_equal);
1868
1869 __ Bind(&not_integer);
1870 // Check if the first object is a string. If it is not then
1871 // objects don't have the same runtime type because they have
1872 // different class ids and they are not strings or integers.
1873 JumpIfNotString(assembler, EDI, &not_equal);
1874 // First object is a string. Check if the second is a string too.
1875 JumpIfString(assembler, EBX, &equal);
1876 // Strings only have the same runtime type as other strings.
1877 // Fall-through to the not equal case.
1878
1879 __ Bind(&not_equal);
1880 __ LoadObject(EAX, Bool::False());
1881 __ ret();
1882
1883 __ Bind(&fall_through);
1884 }
1885
1886
1734 void Intrinsifier::String_getHashCode(Assembler* assembler) { 1887 void Intrinsifier::String_getHashCode(Assembler* assembler) {
1735 Label fall_through; 1888 Label fall_through;
1736 __ movl(EAX, Address(ESP, + 1 * kWordSize)); // String object. 1889 __ movl(EAX, Address(ESP, + 1 * kWordSize)); // String object.
1737 __ movl(EAX, FieldAddress(EAX, String::hash_offset())); 1890 __ movl(EAX, FieldAddress(EAX, String::hash_offset()));
1738 __ cmpl(EAX, Immediate(0)); 1891 __ cmpl(EAX, Immediate(0));
1739 __ j(EQUAL, &fall_through, Assembler::kNearJump); 1892 __ j(EQUAL, &fall_through, Assembler::kNearJump);
1740 __ ret(); 1893 __ ret();
1741 __ Bind(&fall_through); 1894 __ Bind(&fall_through);
1742 // Hash not yet computed. 1895 // Hash not yet computed.
1743 } 1896 }
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
2178 __ Bind(&true_label); 2331 __ Bind(&true_label);
2179 __ LoadObject(EAX, Bool::True()); 2332 __ LoadObject(EAX, Bool::True());
2180 __ ret(); 2333 __ ret();
2181 } 2334 }
2182 2335
2183 #undef __ 2336 #undef __
2184 2337
2185 } // namespace dart 2338 } // namespace dart
2186 2339
2187 #endif // defined TARGET_ARCH_IA32 2340 #endif // defined TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « runtime/vm/intrinsifier_arm64.cc ('k') | runtime/vm/intrinsifier_mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698