| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 1747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1758 Vector<JumpTarget*> case_targets, | 1758 Vector<JumpTarget*> case_targets, |
| 1759 Vector<JumpTarget> case_labels) { | 1759 Vector<JumpTarget> case_labels) { |
| 1760 // Notice: Internal references, used by both the jmp instruction and | 1760 // Notice: Internal references, used by both the jmp instruction and |
| 1761 // the table entries, need to be relocated if the buffer grows. This | 1761 // the table entries, need to be relocated if the buffer grows. This |
| 1762 // prevents the forward use of Labels, since a displacement cannot | 1762 // prevents the forward use of Labels, since a displacement cannot |
| 1763 // survive relocation, and it also cannot safely be distinguished | 1763 // survive relocation, and it also cannot safely be distinguished |
| 1764 // from a real address. Instead we put in zero-values as | 1764 // from a real address. Instead we put in zero-values as |
| 1765 // placeholders, and fill in the addresses after the labels have been | 1765 // placeholders, and fill in the addresses after the labels have been |
| 1766 // bound. | 1766 // bound. |
| 1767 | 1767 |
| 1768 VirtualFrame::SpilledScope spilled_scope(this); | 1768 Result switch_value = frame_->Pop(); // supposed Smi |
| 1769 frame_->EmitPop(eax); // supposed Smi | 1769 // If value is not in range [0..length-1] then jump to the default/end label. |
| 1770 // check range of value, if outside [0..length-1] jump to default/end label. | |
| 1771 ASSERT(kSmiTagSize == 1 && kSmiTag == 0); | 1770 ASSERT(kSmiTagSize == 1 && kSmiTag == 0); |
| 1772 | 1771 |
| 1773 // Test whether input is a HeapNumber that is really a Smi | 1772 // Test whether input is a HeapNumber that is really a Smi |
| 1774 JumpTarget is_smi(this); | 1773 JumpTarget is_smi(this); |
| 1775 __ test(eax, Immediate(kSmiTagMask)); | 1774 switch_value.ToRegister(); |
| 1776 is_smi.Branch(equal); | 1775 __ test(switch_value.reg(), Immediate(kSmiTagMask)); |
| 1776 is_smi.Branch(equal, &switch_value, taken); |
| 1777 // It's a heap object, not a Smi or a Failure | 1777 // It's a heap object, not a Smi or a Failure |
| 1778 __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); | 1778 Result temp = allocator()->Allocate(); |
| 1779 __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); | 1779 ASSERT(temp.is_valid()); |
| 1780 __ cmp(ebx, HEAP_NUMBER_TYPE); | 1780 __ mov(temp.reg(), FieldOperand(switch_value.reg(), HeapObject::kMapOffset)); |
| 1781 __ movzx_b(temp.reg(), FieldOperand(temp.reg(), Map::kInstanceTypeOffset)); |
| 1782 __ cmp(temp.reg(), HEAP_NUMBER_TYPE); |
| 1783 temp.Unuse(); |
| 1781 fail_label->Branch(not_equal); | 1784 fail_label->Branch(not_equal); |
| 1782 // eax points to a heap number. | 1785 // Result switch_value is a heap number. |
| 1783 frame_->EmitPush(eax); | 1786 frame_->Push(&switch_value); |
| 1784 frame_->CallRuntime(Runtime::kNumberToSmi, 1); | 1787 Result smi_value = frame_->CallRuntime(Runtime::kNumberToSmi, 1); |
| 1785 is_smi.Bind(); | 1788 is_smi.Bind(&smi_value); |
| 1789 smi_value.ToRegister(); |
| 1786 | 1790 |
| 1787 if (min_index != 0) { | 1791 if (min_index != 0) { |
| 1788 __ sub(Operand(eax), Immediate(min_index << kSmiTagSize)); | 1792 frame_->Spill(smi_value.reg()); |
| 1793 __ sub(Operand(smi_value.reg()), Immediate(min_index << kSmiTagSize)); |
| 1789 } | 1794 } |
| 1790 __ test(eax, Immediate(0x80000000 | kSmiTagMask)); // negative or not Smi | 1795 __ test(smi_value.reg(), Immediate(0x80000000 | kSmiTagMask)); |
| 1796 // Go to slow case if adjusted index is negative or not a Smi. |
| 1791 fail_label->Branch(not_equal, not_taken); | 1797 fail_label->Branch(not_equal, not_taken); |
| 1792 __ cmp(eax, range << kSmiTagSize); | 1798 __ cmp(smi_value.reg(), range << kSmiTagSize); |
| 1793 fail_label->Branch(greater_equal, not_taken); | 1799 fail_label->Branch(greater_equal, not_taken); |
| 1794 | 1800 |
| 1795 // 0 is placeholder. | 1801 // 0 is placeholder. |
| 1796 __ jmp(Operand(eax, eax, times_1, 0x0, RelocInfo::INTERNAL_REFERENCE)); | 1802 // Jump to the address at table_address + 2 * smi_value.reg(). |
| 1797 // calculate address to overwrite later with actual address of table. | 1803 // The target of the jump is read from table_address + 4 * switch_value. |
| 1804 // The Smi encoding of smi_value.reg() is 2 * switch_value. |
| 1805 __ jmp(Operand(smi_value.reg(), smi_value.reg(), |
| 1806 times_1, 0x0, RelocInfo::INTERNAL_REFERENCE)); |
| 1807 // Calculate address to overwrite later with actual address of table. |
| 1798 int32_t jump_table_ref = __ pc_offset() - sizeof(int32_t); | 1808 int32_t jump_table_ref = __ pc_offset() - sizeof(int32_t); |
| 1799 | 1809 |
| 1800 __ Align(4); | 1810 __ Align(4); |
| 1801 JumpTarget table_start(this); | 1811 JumpTarget table_start(this); |
| 1812 smi_value.Unuse(); |
| 1802 table_start.Bind(); | 1813 table_start.Bind(); |
| 1803 __ WriteInternalReference(jump_table_ref, *table_start.entry_label()); | 1814 __ WriteInternalReference(jump_table_ref, *table_start.entry_label()); |
| 1804 | 1815 |
| 1805 for (int i = 0; i < range; i++) { | 1816 for (int i = 0; i < range; i++) { |
| 1806 // table entry, 0 is placeholder for case address | 1817 // These are the table entries. 0x0 is the placeholder for case address. |
| 1807 __ dd(0x0, RelocInfo::INTERNAL_REFERENCE); | 1818 __ dd(0x0, RelocInfo::INTERNAL_REFERENCE); |
| 1808 } | 1819 } |
| 1809 | 1820 |
| 1810 GenerateFastCaseSwitchCases(node, case_labels, &table_start); | 1821 GenerateFastCaseSwitchCases(node, case_labels, &table_start); |
| 1811 | 1822 |
| 1812 for (int i = 0, entry_pos = table_start.entry_label()->pos(); | 1823 for (int i = 0, entry_pos = table_start.entry_label()->pos(); |
| 1813 i < range; | 1824 i < range; |
| 1814 i++, entry_pos += sizeof(uint32_t)) { | 1825 i++, entry_pos += sizeof(uint32_t)) { |
| 1815 __ WriteInternalReference(entry_pos, *case_targets[i]->entry_label()); | 1826 __ WriteInternalReference(entry_pos, *case_targets[i]->entry_label()); |
| 1816 } | 1827 } |
| (...skipping 4385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6202 | 6213 |
| 6203 // Slow-case: Go through the JavaScript implementation. | 6214 // Slow-case: Go through the JavaScript implementation. |
| 6204 __ bind(&slow); | 6215 __ bind(&slow); |
| 6205 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); | 6216 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 6206 } | 6217 } |
| 6207 | 6218 |
| 6208 | 6219 |
| 6209 #undef __ | 6220 #undef __ |
| 6210 | 6221 |
| 6211 } } // namespace v8::internal | 6222 } } // namespace v8::internal |
| OLD | NEW |