| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1782 __ PrepareCallCFunction(2, scratch); | 1782 __ PrepareCallCFunction(2, scratch); |
| 1783 __ li(a1, Operand(index)); | 1783 __ li(a1, Operand(index)); |
| 1784 __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); | 1784 __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); |
| 1785 __ bind(&done); | 1785 __ bind(&done); |
| 1786 } | 1786 } |
| 1787 } | 1787 } |
| 1788 | 1788 |
| 1789 | 1789 |
| 1790 void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) { | 1790 void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) { |
| 1791 Register string = ToRegister(instr->string()); | 1791 Register string = ToRegister(instr->string()); |
| 1792 Register index = ToRegister(instr->index()); | 1792 LOperand* index_op = instr->index(); |
| 1793 Register value = ToRegister(instr->value()); | 1793 Register value = ToRegister(instr->value()); |
| 1794 Register scratch = scratch0(); | 1794 Register scratch = scratch0(); |
| 1795 String::Encoding encoding = instr->encoding(); | 1795 String::Encoding encoding = instr->encoding(); |
| 1796 | 1796 |
| 1797 if (FLAG_debug_code) { | 1797 if (FLAG_debug_code) { |
| 1798 __ lw(at, FieldMemOperand(string, HeapObject::kMapOffset)); | 1798 __ lw(scratch, FieldMemOperand(string, HeapObject::kMapOffset)); |
| 1799 __ lbu(at, FieldMemOperand(at, Map::kInstanceTypeOffset)); | 1799 __ lbu(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
| 1800 | 1800 |
| 1801 __ And(at, at, Operand(kStringRepresentationMask | kStringEncodingMask)); | 1801 __ And(scratch, scratch, |
| 1802 Operand(kStringRepresentationMask | kStringEncodingMask)); |
| 1802 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; | 1803 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; |
| 1803 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; | 1804 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; |
| 1804 __ Subu(at, at, Operand(encoding == String::ONE_BYTE_ENCODING | 1805 __ Subu(at, scratch, Operand(encoding == String::ONE_BYTE_ENCODING |
| 1805 ? one_byte_seq_type : two_byte_seq_type)); | 1806 ? one_byte_seq_type : two_byte_seq_type)); |
| 1806 __ Check(eq, kUnexpectedStringType, at, Operand(zero_reg)); | 1807 __ Check(eq, kUnexpectedStringType, at, Operand(zero_reg)); |
| 1807 } | 1808 } |
| 1808 | 1809 |
| 1809 __ Addu(scratch, | 1810 if (index_op->IsConstantOperand()) { |
| 1810 string, | 1811 int constant_index = ToInteger32(LConstantOperand::cast(index_op)); |
| 1811 Operand(SeqString::kHeaderSize - kHeapObjectTag)); | 1812 if (encoding == String::ONE_BYTE_ENCODING) { |
| 1812 if (encoding == String::ONE_BYTE_ENCODING) { | 1813 __ sb(value, |
| 1813 __ Addu(at, scratch, index); | 1814 FieldMemOperand(string, SeqString::kHeaderSize + constant_index)); |
| 1814 __ sb(value, MemOperand(at)); | 1815 } else { |
| 1816 __ sh(value, |
| 1817 FieldMemOperand(string, SeqString::kHeaderSize + constant_index * 2)); |
| 1818 } |
| 1815 } else { | 1819 } else { |
| 1816 __ sll(at, index, 1); | 1820 Register index = ToRegister(index_op); |
| 1817 __ Addu(at, scratch, at); | 1821 if (encoding == String::ONE_BYTE_ENCODING) { |
| 1818 __ sh(value, MemOperand(at)); | 1822 __ Addu(scratch, string, Operand(index)); |
| 1823 __ sb(value, FieldMemOperand(scratch, SeqString::kHeaderSize)); |
| 1824 } else { |
| 1825 __ sll(scratch, index, 1); |
| 1826 __ Addu(scratch, string, scratch); |
| 1827 __ sh(value, FieldMemOperand(scratch, SeqString::kHeaderSize)); |
| 1828 } |
| 1819 } | 1829 } |
| 1820 } | 1830 } |
| 1821 | 1831 |
| 1822 | 1832 |
| 1823 void LCodeGen::DoThrow(LThrow* instr) { | 1833 void LCodeGen::DoThrow(LThrow* instr) { |
| 1824 Register input_reg = EmitLoadRegister(instr->value(), at); | 1834 Register input_reg = EmitLoadRegister(instr->value(), at); |
| 1825 __ push(input_reg); | 1835 __ push(input_reg); |
| 1826 CallRuntime(Runtime::kThrow, 1, instr); | 1836 CallRuntime(Runtime::kThrow, 1, instr); |
| 1827 | 1837 |
| 1828 if (FLAG_debug_code) { | 1838 if (FLAG_debug_code) { |
| (...skipping 1977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3806 __ CallStub(&stub); | 3816 __ CallStub(&stub); |
| 3807 } else { | 3817 } else { |
| 3808 ASSERT(exponent_type.IsDouble()); | 3818 ASSERT(exponent_type.IsDouble()); |
| 3809 MathPowStub stub(MathPowStub::DOUBLE); | 3819 MathPowStub stub(MathPowStub::DOUBLE); |
| 3810 __ CallStub(&stub); | 3820 __ CallStub(&stub); |
| 3811 } | 3821 } |
| 3812 } | 3822 } |
| 3813 | 3823 |
| 3814 | 3824 |
| 3815 void LCodeGen::DoRandom(LRandom* instr) { | 3825 void LCodeGen::DoRandom(LRandom* instr) { |
| 3816 class DeferredDoRandom V8_FINAL : public LDeferredCode { | 3826 // Assert that the register size is indeed the size of each seed. |
| 3817 public: | |
| 3818 DeferredDoRandom(LCodeGen* codegen, LRandom* instr) | |
| 3819 : LDeferredCode(codegen), instr_(instr) { } | |
| 3820 virtual void Generate() V8_OVERRIDE { codegen()->DoDeferredRandom(instr_); } | |
| 3821 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } | |
| 3822 private: | |
| 3823 LRandom* instr_; | |
| 3824 }; | |
| 3825 | |
| 3826 DeferredDoRandom* deferred = new(zone()) DeferredDoRandom(this, instr); | |
| 3827 // Having marked this instruction as a call we can use any | |
| 3828 // registers. | |
| 3829 ASSERT(ToDoubleRegister(instr->result()).is(f0)); | |
| 3830 ASSERT(ToRegister(instr->global_object()).is(a0)); | |
| 3831 | |
| 3832 static const int kSeedSize = sizeof(uint32_t); | 3827 static const int kSeedSize = sizeof(uint32_t); |
| 3833 STATIC_ASSERT(kPointerSize == kSeedSize); | 3828 STATIC_ASSERT(kPointerSize == kSeedSize); |
| 3834 | 3829 |
| 3835 __ lw(a0, FieldMemOperand(a0, GlobalObject::kNativeContextOffset)); | 3830 // Load native context. |
| 3831 Register global_object = ToRegister(instr->global_object()); |
| 3832 Register native_context = global_object; |
| 3833 __ lw(native_context, FieldMemOperand( |
| 3834 global_object, GlobalObject::kNativeContextOffset)); |
| 3835 |
| 3836 // Load state (FixedArray of the native context's random seeds). |
| 3836 static const int kRandomSeedOffset = | 3837 static const int kRandomSeedOffset = |
| 3837 FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize; | 3838 FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize; |
| 3838 __ lw(a2, FieldMemOperand(a0, kRandomSeedOffset)); | 3839 Register state = native_context; |
| 3839 // a2: FixedArray of the native context's random seeds | 3840 __ lw(state, FieldMemOperand(native_context, kRandomSeedOffset)); |
| 3840 | 3841 |
| 3841 // Load state[0]. | 3842 // Load state[0]. |
| 3842 __ lw(a1, FieldMemOperand(a2, ByteArray::kHeaderSize)); | 3843 Register state0 = ToRegister(instr->scratch()); |
| 3843 __ Branch(deferred->entry(), eq, a1, Operand(zero_reg)); | 3844 __ lw(state0, FieldMemOperand(state, ByteArray::kHeaderSize)); |
| 3844 // Load state[1]. | 3845 // Load state[1]. |
| 3845 __ lw(a0, FieldMemOperand(a2, ByteArray::kHeaderSize + kSeedSize)); | 3846 Register state1 = ToRegister(instr->scratch2()); |
| 3846 // a1: state[0]. | 3847 __ lw(state1, FieldMemOperand(state, ByteArray::kHeaderSize + kSeedSize)); |
| 3847 // a0: state[1]. | |
| 3848 | 3848 |
| 3849 // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16) | 3849 // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16) |
| 3850 __ And(a3, a1, Operand(0xFFFF)); | 3850 Register scratch3 = ToRegister(instr->scratch3()); |
| 3851 __ li(t0, Operand(18273)); | 3851 Register scratch4 = scratch0(); |
| 3852 __ Mul(a3, a3, t0); | 3852 __ And(scratch3, state0, Operand(0xFFFF)); |
| 3853 __ srl(a1, a1, 16); | 3853 __ li(scratch4, Operand(18273)); |
| 3854 __ Addu(a1, a3, a1); | 3854 __ Mul(scratch3, scratch3, scratch4); |
| 3855 __ srl(state0, state0, 16); |
| 3856 __ Addu(state0, scratch3, state0); |
| 3855 // Save state[0]. | 3857 // Save state[0]. |
| 3856 __ sw(a1, FieldMemOperand(a2, ByteArray::kHeaderSize)); | 3858 __ sw(state0, FieldMemOperand(state, ByteArray::kHeaderSize)); |
| 3857 | 3859 |
| 3858 // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16) | 3860 // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16) |
| 3859 __ And(a3, a0, Operand(0xFFFF)); | 3861 __ And(scratch3, state1, Operand(0xFFFF)); |
| 3860 __ li(t0, Operand(36969)); | 3862 __ li(scratch4, Operand(36969)); |
| 3861 __ Mul(a3, a3, t0); | 3863 __ Mul(scratch3, scratch3, scratch4); |
| 3862 __ srl(a0, a0, 16), | 3864 __ srl(state1, state1, 16), |
| 3863 __ Addu(a0, a3, a0); | 3865 __ Addu(state1, scratch3, state1); |
| 3864 // Save state[1]. | 3866 // Save state[1]. |
| 3865 __ sw(a0, FieldMemOperand(a2, ByteArray::kHeaderSize + kSeedSize)); | 3867 __ sw(state1, FieldMemOperand(state, ByteArray::kHeaderSize + kSeedSize)); |
| 3866 | 3868 |
| 3867 // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF) | 3869 // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF) |
| 3868 __ And(a0, a0, Operand(0x3FFFF)); | 3870 Register random = scratch4; |
| 3869 __ sll(a1, a1, 14); | 3871 __ And(random, state1, Operand(0x3FFFF)); |
| 3870 __ Addu(v0, a0, a1); | 3872 __ sll(state0, state0, 14); |
| 3871 | 3873 __ Addu(random, random, state0); |
| 3872 __ bind(deferred->exit()); | |
| 3873 | 3874 |
| 3874 // 0x41300000 is the top half of 1.0 x 2^20 as a double. | 3875 // 0x41300000 is the top half of 1.0 x 2^20 as a double. |
| 3875 __ li(a2, Operand(0x41300000)); | 3876 __ li(scratch3, Operand(0x41300000)); |
| 3876 // Move 0x41300000xxxxxxxx (x = random bits in v0) to FPU. | 3877 // Move 0x41300000xxxxxxxx (x = random bits in v0) to FPU. |
| 3877 __ Move(f12, v0, a2); | 3878 DoubleRegister result = ToDoubleRegister(instr->result()); |
| 3879 __ Move(result, random, scratch3); |
| 3878 // Move 0x4130000000000000 to FPU. | 3880 // Move 0x4130000000000000 to FPU. |
| 3879 __ Move(f14, zero_reg, a2); | 3881 DoubleRegister scratch5 = double_scratch0(); |
| 3880 // Subtract to get the result. | 3882 __ Move(scratch5, zero_reg, scratch3); |
| 3881 __ sub_d(f0, f12, f14); | 3883 __ sub_d(result, result, scratch5); |
| 3882 } | 3884 } |
| 3883 | 3885 |
| 3884 | 3886 |
| 3885 void LCodeGen::DoDeferredRandom(LRandom* instr) { | |
| 3886 __ PrepareCallCFunction(1, scratch0()); | |
| 3887 __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1); | |
| 3888 // Return value is in v0. | |
| 3889 } | |
| 3890 | |
| 3891 | |
| 3892 void LCodeGen::DoMathExp(LMathExp* instr) { | 3887 void LCodeGen::DoMathExp(LMathExp* instr) { |
| 3893 DoubleRegister input = ToDoubleRegister(instr->value()); | 3888 DoubleRegister input = ToDoubleRegister(instr->value()); |
| 3894 DoubleRegister result = ToDoubleRegister(instr->result()); | 3889 DoubleRegister result = ToDoubleRegister(instr->result()); |
| 3895 DoubleRegister double_scratch1 = ToDoubleRegister(instr->double_temp()); | 3890 DoubleRegister double_scratch1 = ToDoubleRegister(instr->double_temp()); |
| 3896 DoubleRegister double_scratch2 = double_scratch0(); | 3891 DoubleRegister double_scratch2 = double_scratch0(); |
| 3897 Register temp1 = ToRegister(instr->temp1()); | 3892 Register temp1 = ToRegister(instr->temp1()); |
| 3898 Register temp2 = ToRegister(instr->temp2()); | 3893 Register temp2 = ToRegister(instr->temp2()); |
| 3899 | 3894 |
| 3900 MathExpGenerator::EmitMathExp( | 3895 MathExpGenerator::EmitMathExp( |
| 3901 masm(), input, result, double_scratch1, double_scratch2, | 3896 masm(), input, result, double_scratch1, double_scratch2, |
| (...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4942 private: | 4937 private: |
| 4943 LTaggedToI* instr_; | 4938 LTaggedToI* instr_; |
| 4944 }; | 4939 }; |
| 4945 | 4940 |
| 4946 LOperand* input = instr->value(); | 4941 LOperand* input = instr->value(); |
| 4947 ASSERT(input->IsRegister()); | 4942 ASSERT(input->IsRegister()); |
| 4948 ASSERT(input->Equals(instr->result())); | 4943 ASSERT(input->Equals(instr->result())); |
| 4949 | 4944 |
| 4950 Register input_reg = ToRegister(input); | 4945 Register input_reg = ToRegister(input); |
| 4951 | 4946 |
| 4952 DeferredTaggedToI* deferred = new(zone()) DeferredTaggedToI(this, instr); | 4947 if (instr->hydrogen()->value()->representation().IsSmi()) { |
| 4948 __ SmiUntag(input_reg); |
| 4949 } else { |
| 4950 DeferredTaggedToI* deferred = new(zone()) DeferredTaggedToI(this, instr); |
| 4953 | 4951 |
| 4954 // Let the deferred code handle the HeapObject case. | 4952 // Let the deferred code handle the HeapObject case. |
| 4955 __ JumpIfNotSmi(input_reg, deferred->entry()); | 4953 __ JumpIfNotSmi(input_reg, deferred->entry()); |
| 4956 | 4954 |
| 4957 // Smi to int32 conversion. | 4955 // Smi to int32 conversion. |
| 4958 __ SmiUntag(input_reg); | 4956 __ SmiUntag(input_reg); |
| 4959 __ bind(deferred->exit()); | 4957 __ bind(deferred->exit()); |
| 4958 } |
| 4960 } | 4959 } |
| 4961 | 4960 |
| 4962 | 4961 |
| 4963 void LCodeGen::DoNumberUntagD(LNumberUntagD* instr) { | 4962 void LCodeGen::DoNumberUntagD(LNumberUntagD* instr) { |
| 4964 LOperand* input = instr->value(); | 4963 LOperand* input = instr->value(); |
| 4965 ASSERT(input->IsRegister()); | 4964 ASSERT(input->IsRegister()); |
| 4966 LOperand* result = instr->result(); | 4965 LOperand* result = instr->result(); |
| 4967 ASSERT(result->IsDoubleRegister()); | 4966 ASSERT(result->IsDoubleRegister()); |
| 4968 | 4967 |
| 4969 Register input_reg = ToRegister(input); | 4968 Register input_reg = ToRegister(input); |
| (...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5788 __ Subu(scratch, result, scratch); | 5787 __ Subu(scratch, result, scratch); |
| 5789 __ lw(result, FieldMemOperand(scratch, | 5788 __ lw(result, FieldMemOperand(scratch, |
| 5790 FixedArray::kHeaderSize - kPointerSize)); | 5789 FixedArray::kHeaderSize - kPointerSize)); |
| 5791 __ bind(&done); | 5790 __ bind(&done); |
| 5792 } | 5791 } |
| 5793 | 5792 |
| 5794 | 5793 |
| 5795 #undef __ | 5794 #undef __ |
| 5796 | 5795 |
| 5797 } } // namespace v8::internal | 5796 } } // namespace v8::internal |
| OLD | NEW |