OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1745 EmitBranch(true_block, false_block, equal); | 1745 EmitBranch(true_block, false_block, equal); |
1746 } | 1746 } |
1747 | 1747 |
1748 | 1748 |
1749 // Branches to a label or falls through with the answer in the z flag. | 1749 // Branches to a label or falls through with the answer in the z flag. |
1750 // Trashes the temp register and possibly input (if it and temp are aliased). | 1750 // Trashes the temp register and possibly input (if it and temp are aliased). |
1751 void LCodeGen::EmitClassOfTest(Label* is_true, | 1751 void LCodeGen::EmitClassOfTest(Label* is_true, |
1752 Label* is_false, | 1752 Label* is_false, |
1753 Handle<String> class_name, | 1753 Handle<String> class_name, |
1754 Register input, | 1754 Register input, |
1755 Register temp) { | 1755 Register temp, |
| 1756 Register scratch) { |
1756 __ JumpIfSmi(input, is_false); | 1757 __ JumpIfSmi(input, is_false); |
1757 __ CmpObjectType(input, FIRST_SPEC_OBJECT_TYPE, temp); | |
1758 __ j(below, is_false); | |
1759 | 1758 |
1760 // Map is now in temp. | |
1761 // Functions have class 'Function'. | |
1762 __ CmpInstanceType(temp, FIRST_CALLABLE_SPEC_OBJECT_TYPE); | |
1763 if (class_name->IsEqualTo(CStrVector("Function"))) { | 1759 if (class_name->IsEqualTo(CStrVector("Function"))) { |
1764 __ j(above_equal, is_true); | 1760 // Assuming the following assertions, we can use the same compares to test |
| 1761 // for both being a function type and being in the object type range. |
| 1762 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
| 1763 STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 1764 FIRST_SPEC_OBJECT_TYPE + 1); |
| 1765 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 1766 LAST_SPEC_OBJECT_TYPE - 1); |
| 1767 STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); |
| 1768 __ CmpObjectType(input, FIRST_SPEC_OBJECT_TYPE, temp); |
| 1769 __ j(below, is_false); |
| 1770 __ j(equal, is_true); |
| 1771 __ CmpInstanceType(temp, LAST_SPEC_OBJECT_TYPE); |
| 1772 __ j(equal, is_true); |
1765 } else { | 1773 } else { |
1766 __ j(above_equal, is_false); | 1774 // Faster code path to avoid two compares: subtract lower bound from the |
| 1775 // actual type and do a signed compare with the width of the type range. |
| 1776 __ movq(temp, FieldOperand(input, HeapObject::kMapOffset)); |
| 1777 __ movq(scratch, FieldOperand(temp, Map::kInstanceTypeOffset)); |
| 1778 __ subb(scratch, Immediate(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
| 1779 __ cmpb(scratch, |
| 1780 Immediate(static_cast<int8_t>(LAST_NONCALLABLE_SPEC_OBJECT_TYPE - |
| 1781 FIRST_NONCALLABLE_SPEC_OBJECT_TYPE))); |
| 1782 __ j(above, is_false); |
1767 } | 1783 } |
1768 | 1784 |
| 1785 // Now we are in the FIRST-LAST_NONCALLABLE_SPEC_OBJECT_TYPE range. |
1769 // Check if the constructor in the map is a function. | 1786 // Check if the constructor in the map is a function. |
1770 __ movq(temp, FieldOperand(temp, Map::kConstructorOffset)); | 1787 __ movq(temp, FieldOperand(temp, Map::kConstructorOffset)); |
1771 | 1788 |
1772 // As long as LAST_CALLABLE_SPEC_OBJECT_TYPE is the last type and | |
1773 // FIRST_CALLABLE_SPEC_OBJECT_TYPE comes right after | |
1774 // LAST_NONCALLABLE_SPEC_OBJECT_TYPE, we can avoid checking for the latter. | |
1775 STATIC_ASSERT(LAST_TYPE == LAST_CALLABLE_SPEC_OBJECT_TYPE); | |
1776 STATIC_ASSERT(FIRST_CALLABLE_SPEC_OBJECT_TYPE == | |
1777 LAST_NONCALLABLE_SPEC_OBJECT_TYPE + 1); | |
1778 | |
1779 // Objects with a non-function constructor have class 'Object'. | 1789 // Objects with a non-function constructor have class 'Object'. |
1780 __ CmpObjectType(temp, JS_FUNCTION_TYPE, kScratchRegister); | 1790 __ CmpObjectType(temp, JS_FUNCTION_TYPE, kScratchRegister); |
1781 if (class_name->IsEqualTo(CStrVector("Object"))) { | 1791 if (class_name->IsEqualTo(CStrVector("Object"))) { |
1782 __ j(not_equal, is_true); | 1792 __ j(not_equal, is_true); |
1783 } else { | 1793 } else { |
1784 __ j(not_equal, is_false); | 1794 __ j(not_equal, is_false); |
1785 } | 1795 } |
1786 | 1796 |
1787 // temp now contains the constructor function. Grab the | 1797 // temp now contains the constructor function. Grab the |
1788 // instance class name from there. | 1798 // instance class name from there. |
1789 __ movq(temp, FieldOperand(temp, JSFunction::kSharedFunctionInfoOffset)); | 1799 __ movq(temp, FieldOperand(temp, JSFunction::kSharedFunctionInfoOffset)); |
1790 __ movq(temp, FieldOperand(temp, | 1800 __ movq(temp, FieldOperand(temp, |
1791 SharedFunctionInfo::kInstanceClassNameOffset)); | 1801 SharedFunctionInfo::kInstanceClassNameOffset)); |
1792 // The class name we are testing against is a symbol because it's a literal. | 1802 // The class name we are testing against is a symbol because it's a literal. |
1793 // The name in the constructor is a symbol because of the way the context is | 1803 // The name in the constructor is a symbol because of the way the context is |
1794 // booted. This routine isn't expected to work for random API-created | 1804 // booted. This routine isn't expected to work for random API-created |
1795 // classes and it doesn't have to because you can't access it with natives | 1805 // classes and it doesn't have to because you can't access it with natives |
1796 // syntax. Since both sides are symbols it is sufficient to use an identity | 1806 // syntax. Since both sides are symbols it is sufficient to use an identity |
1797 // comparison. | 1807 // comparison. |
1798 ASSERT(class_name->IsSymbol()); | 1808 ASSERT(class_name->IsSymbol()); |
1799 __ Cmp(temp, class_name); | 1809 __ Cmp(temp, class_name); |
1800 // End with the answer in the z flag. | 1810 // End with the answer in the z flag. |
1801 } | 1811 } |
1802 | 1812 |
1803 | 1813 |
1804 void LCodeGen::DoClassOfTestAndBranch(LClassOfTestAndBranch* instr) { | 1814 void LCodeGen::DoClassOfTestAndBranch(LClassOfTestAndBranch* instr) { |
1805 Register input = ToRegister(instr->InputAt(0)); | 1815 Register input = ToRegister(instr->InputAt(0)); |
1806 Register temp = ToRegister(instr->TempAt(0)); | 1816 Register temp = ToRegister(instr->TempAt(0)); |
| 1817 Register temp2 = ToRegister(instr->TempAt(1)); |
1807 Handle<String> class_name = instr->hydrogen()->class_name(); | 1818 Handle<String> class_name = instr->hydrogen()->class_name(); |
1808 | 1819 |
1809 int true_block = chunk_->LookupDestination(instr->true_block_id()); | 1820 int true_block = chunk_->LookupDestination(instr->true_block_id()); |
1810 int false_block = chunk_->LookupDestination(instr->false_block_id()); | 1821 int false_block = chunk_->LookupDestination(instr->false_block_id()); |
1811 | 1822 |
1812 Label* true_label = chunk_->GetAssemblyLabel(true_block); | 1823 Label* true_label = chunk_->GetAssemblyLabel(true_block); |
1813 Label* false_label = chunk_->GetAssemblyLabel(false_block); | 1824 Label* false_label = chunk_->GetAssemblyLabel(false_block); |
1814 | 1825 |
1815 EmitClassOfTest(true_label, false_label, class_name, input, temp); | 1826 EmitClassOfTest(true_label, false_label, class_name, input, temp, temp2); |
1816 | 1827 |
1817 EmitBranch(true_block, false_block, equal); | 1828 EmitBranch(true_block, false_block, equal); |
1818 } | 1829 } |
1819 | 1830 |
1820 | 1831 |
1821 void LCodeGen::DoCmpMapAndBranch(LCmpMapAndBranch* instr) { | 1832 void LCodeGen::DoCmpMapAndBranch(LCmpMapAndBranch* instr) { |
1822 Register reg = ToRegister(instr->InputAt(0)); | 1833 Register reg = ToRegister(instr->InputAt(0)); |
1823 int true_block = instr->true_block_id(); | 1834 int true_block = instr->true_block_id(); |
1824 int false_block = instr->false_block_id(); | 1835 int false_block = instr->false_block_id(); |
1825 | 1836 |
(...skipping 2148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3974 __ CompareRoot(input, Heap::kUndefinedValueRootIndex); | 3985 __ CompareRoot(input, Heap::kUndefinedValueRootIndex); |
3975 __ j(equal, true_label); | 3986 __ j(equal, true_label); |
3976 __ JumpIfSmi(input, false_label); | 3987 __ JumpIfSmi(input, false_label); |
3977 // Check for undetectable objects => true. | 3988 // Check for undetectable objects => true. |
3978 __ movq(input, FieldOperand(input, HeapObject::kMapOffset)); | 3989 __ movq(input, FieldOperand(input, HeapObject::kMapOffset)); |
3979 __ testb(FieldOperand(input, Map::kBitFieldOffset), | 3990 __ testb(FieldOperand(input, Map::kBitFieldOffset), |
3980 Immediate(1 << Map::kIsUndetectable)); | 3991 Immediate(1 << Map::kIsUndetectable)); |
3981 final_branch_condition = not_zero; | 3992 final_branch_condition = not_zero; |
3982 | 3993 |
3983 } else if (type_name->Equals(heap()->function_symbol())) { | 3994 } else if (type_name->Equals(heap()->function_symbol())) { |
| 3995 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
3984 __ JumpIfSmi(input, false_label); | 3996 __ JumpIfSmi(input, false_label); |
3985 __ CmpObjectType(input, FIRST_CALLABLE_SPEC_OBJECT_TYPE, input); | 3997 __ CmpObjectType(input, JS_FUNCTION_TYPE, input); |
3986 final_branch_condition = above_equal; | 3998 __ j(equal, true_label); |
| 3999 __ CmpInstanceType(input, JS_FUNCTION_PROXY_TYPE); |
| 4000 final_branch_condition = equal; |
3987 | 4001 |
3988 } else if (type_name->Equals(heap()->object_symbol())) { | 4002 } else if (type_name->Equals(heap()->object_symbol())) { |
3989 __ JumpIfSmi(input, false_label); | 4003 __ JumpIfSmi(input, false_label); |
3990 if (!FLAG_harmony_typeof) { | 4004 if (!FLAG_harmony_typeof) { |
3991 __ CompareRoot(input, Heap::kNullValueRootIndex); | 4005 __ CompareRoot(input, Heap::kNullValueRootIndex); |
3992 __ j(equal, true_label); | 4006 __ j(equal, true_label); |
3993 } | 4007 } |
3994 __ CmpObjectType(input, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, input); | 4008 __ CmpObjectType(input, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, input); |
3995 __ j(below, false_label); | 4009 __ j(below, false_label); |
3996 __ CmpInstanceType(input, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); | 4010 __ CmpInstanceType(input, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4148 RegisterEnvironmentForDeoptimization(environment); | 4162 RegisterEnvironmentForDeoptimization(environment); |
4149 ASSERT(osr_pc_offset_ == -1); | 4163 ASSERT(osr_pc_offset_ == -1); |
4150 osr_pc_offset_ = masm()->pc_offset(); | 4164 osr_pc_offset_ = masm()->pc_offset(); |
4151 } | 4165 } |
4152 | 4166 |
4153 #undef __ | 4167 #undef __ |
4154 | 4168 |
4155 } } // namespace v8::internal | 4169 } } // namespace v8::internal |
4156 | 4170 |
4157 #endif // V8_TARGET_ARCH_X64 | 4171 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |