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 |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #include "v8.h" | 28 #include "v8.h" |
29 | 29 |
30 #if defined(V8_TARGET_ARCH_IA32) | 30 #if V8_TARGET_ARCH_IA32 |
31 | 31 |
32 #include "ia32/lithium-codegen-ia32.h" | 32 #include "ia32/lithium-codegen-ia32.h" |
33 #include "ic.h" | 33 #include "ic.h" |
34 #include "code-stubs.h" | 34 #include "code-stubs.h" |
35 #include "deoptimizer.h" | 35 #include "deoptimizer.h" |
36 #include "stub-cache.h" | 36 #include "stub-cache.h" |
37 #include "codegen.h" | 37 #include "codegen.h" |
38 | 38 |
39 namespace v8 { | 39 namespace v8 { |
40 namespace internal { | 40 namespace internal { |
(...skipping 1725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1766 Handle<Object> handle = instr->value(); | 1766 Handle<Object> handle = instr->value(); |
1767 AllowDeferredHandleDereference smi_check; | 1767 AllowDeferredHandleDereference smi_check; |
1768 if (handle->IsHeapObject()) { | 1768 if (handle->IsHeapObject()) { |
1769 __ LoadHeapObject(reg, Handle<HeapObject>::cast(handle)); | 1769 __ LoadHeapObject(reg, Handle<HeapObject>::cast(handle)); |
1770 } else { | 1770 } else { |
1771 __ Set(reg, Immediate(handle)); | 1771 __ Set(reg, Immediate(handle)); |
1772 } | 1772 } |
1773 } | 1773 } |
1774 | 1774 |
1775 | 1775 |
1776 void LCodeGen::DoFixedArrayBaseLength( | |
1777 LFixedArrayBaseLength* instr) { | |
1778 Register result = ToRegister(instr->result()); | |
1779 Register array = ToRegister(instr->value()); | |
1780 __ mov(result, FieldOperand(array, FixedArrayBase::kLengthOffset)); | |
1781 } | |
1782 | |
1783 | |
1784 void LCodeGen::DoMapEnumLength(LMapEnumLength* instr) { | 1776 void LCodeGen::DoMapEnumLength(LMapEnumLength* instr) { |
1785 Register result = ToRegister(instr->result()); | 1777 Register result = ToRegister(instr->result()); |
1786 Register map = ToRegister(instr->value()); | 1778 Register map = ToRegister(instr->value()); |
1787 __ EnumLength(result, map); | 1779 __ EnumLength(result, map); |
1788 } | 1780 } |
1789 | 1781 |
1790 | 1782 |
1791 void LCodeGen::DoElementsKind(LElementsKind* instr) { | 1783 void LCodeGen::DoElementsKind(LElementsKind* instr) { |
1792 Register result = ToRegister(instr->result()); | 1784 Register result = ToRegister(instr->result()); |
1793 Register input = ToRegister(instr->value()); | 1785 Register input = ToRegister(instr->value()); |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2037 __ add(Operand(esp), Immediate(kDoubleSize)); | 2029 __ add(Operand(esp), Immediate(kDoubleSize)); |
2038 break; | 2030 break; |
2039 } | 2031 } |
2040 default: | 2032 default: |
2041 UNREACHABLE(); | 2033 UNREACHABLE(); |
2042 break; | 2034 break; |
2043 } | 2035 } |
2044 } | 2036 } |
2045 | 2037 |
2046 | 2038 |
| 2039 void LCodeGen::DoNegateNoSSE2D(LNegateNoSSE2D* instr) { |
| 2040 __ push(Immediate(-1)); |
| 2041 __ fild_s(Operand(esp, 0)); |
| 2042 __ add(esp, Immediate(kPointerSize)); |
| 2043 __ fmulp(); |
| 2044 CurrentInstructionReturnsX87Result(); |
| 2045 } |
| 2046 |
| 2047 |
| 2048 |
2047 void LCodeGen::DoArithmeticT(LArithmeticT* instr) { | 2049 void LCodeGen::DoArithmeticT(LArithmeticT* instr) { |
2048 ASSERT(ToRegister(instr->context()).is(esi)); | 2050 ASSERT(ToRegister(instr->context()).is(esi)); |
2049 ASSERT(ToRegister(instr->left()).is(edx)); | 2051 ASSERT(ToRegister(instr->left()).is(edx)); |
2050 ASSERT(ToRegister(instr->right()).is(eax)); | 2052 ASSERT(ToRegister(instr->right()).is(eax)); |
2051 ASSERT(ToRegister(instr->result()).is(eax)); | 2053 ASSERT(ToRegister(instr->result()).is(eax)); |
2052 | 2054 |
2053 BinaryOpStub stub(instr->op(), NO_OVERWRITE); | 2055 BinaryOpStub stub(instr->op(), NO_OVERWRITE); |
2054 CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); | 2056 CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
2055 __ nop(); // Signals no inlined code. | 2057 __ nop(); // Signals no inlined code. |
2056 } | 2058 } |
2057 | 2059 |
2058 | 2060 |
2059 int LCodeGen::GetNextEmittedBlock() const { | 2061 int LCodeGen::GetNextEmittedBlock() const { |
2060 for (int i = current_block_ + 1; i < graph()->blocks()->length(); ++i) { | 2062 for (int i = current_block_ + 1; i < graph()->blocks()->length(); ++i) { |
2061 if (!chunk_->GetLabel(i)->HasReplacement()) return i; | 2063 if (!chunk_->GetLabel(i)->HasReplacement()) return i; |
2062 } | 2064 } |
2063 return -1; | 2065 return -1; |
2064 } | 2066 } |
2065 | 2067 |
2066 | 2068 |
2067 template<class InstrType> | 2069 template<class InstrType> |
2068 void LCodeGen::EmitBranch(InstrType instr, Condition cc) { | 2070 void LCodeGen::EmitBranch(InstrType instr, Condition cc) { |
| 2071 int left_block = instr->TrueDestination(chunk_); |
2069 int right_block = instr->FalseDestination(chunk_); | 2072 int right_block = instr->FalseDestination(chunk_); |
2070 int left_block = instr->TrueDestination(chunk_); | |
2071 | 2073 |
2072 int next_block = GetNextEmittedBlock(); | 2074 int next_block = GetNextEmittedBlock(); |
2073 | 2075 |
2074 if (right_block == left_block) { | 2076 if (right_block == left_block || cc == no_condition) { |
2075 EmitGoto(left_block); | 2077 EmitGoto(left_block); |
2076 } else if (left_block == next_block) { | 2078 } else if (left_block == next_block) { |
2077 __ j(NegateCondition(cc), chunk_->GetAssemblyLabel(right_block)); | 2079 __ j(NegateCondition(cc), chunk_->GetAssemblyLabel(right_block)); |
2078 } else if (right_block == next_block) { | 2080 } else if (right_block == next_block) { |
2079 __ j(cc, chunk_->GetAssemblyLabel(left_block)); | 2081 __ j(cc, chunk_->GetAssemblyLabel(left_block)); |
2080 } else { | 2082 } else { |
2081 __ j(cc, chunk_->GetAssemblyLabel(left_block)); | 2083 __ j(cc, chunk_->GetAssemblyLabel(left_block)); |
2082 __ jmp(chunk_->GetAssemblyLabel(right_block)); | 2084 __ jmp(chunk_->GetAssemblyLabel(right_block)); |
2083 } | 2085 } |
2084 } | 2086 } |
2085 | 2087 |
2086 | 2088 |
| 2089 void LCodeGen::DoIsNumberAndBranch(LIsNumberAndBranch* instr) { |
| 2090 Representation r = instr->hydrogen()->value()->representation(); |
| 2091 if (r.IsSmiOrInteger32() || r.IsDouble()) { |
| 2092 EmitBranch(instr, no_condition); |
| 2093 } else { |
| 2094 ASSERT(r.IsTagged()); |
| 2095 Register reg = ToRegister(instr->value()); |
| 2096 HType type = instr->hydrogen()->value()->type(); |
| 2097 if (type.IsTaggedNumber()) { |
| 2098 EmitBranch(instr, no_condition); |
| 2099 } |
| 2100 __ JumpIfSmi(reg, instr->TrueLabel(chunk_)); |
| 2101 __ cmp(FieldOperand(reg, HeapObject::kMapOffset), |
| 2102 factory()->heap_number_map()); |
| 2103 EmitBranch(instr, equal); |
| 2104 } |
| 2105 } |
| 2106 |
| 2107 |
2087 void LCodeGen::DoBranch(LBranch* instr) { | 2108 void LCodeGen::DoBranch(LBranch* instr) { |
2088 Representation r = instr->hydrogen()->value()->representation(); | 2109 Representation r = instr->hydrogen()->value()->representation(); |
2089 if (r.IsSmiOrInteger32()) { | 2110 if (r.IsSmiOrInteger32()) { |
2090 ASSERT(!info()->IsStub()); | 2111 ASSERT(!info()->IsStub()); |
2091 Register reg = ToRegister(instr->value()); | 2112 Register reg = ToRegister(instr->value()); |
2092 __ test(reg, Operand(reg)); | 2113 __ test(reg, Operand(reg)); |
2093 EmitBranch(instr, not_zero); | 2114 EmitBranch(instr, not_zero); |
2094 } else if (r.IsDouble()) { | 2115 } else if (r.IsDouble()) { |
2095 ASSERT(!info()->IsStub()); | 2116 ASSERT(!info()->IsStub()); |
2096 CpuFeatureScope scope(masm(), SSE2); | 2117 CpuFeatureScope scope(masm(), SSE2); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2257 break; | 2278 break; |
2258 case Token::IN: | 2279 case Token::IN: |
2259 case Token::INSTANCEOF: | 2280 case Token::INSTANCEOF: |
2260 default: | 2281 default: |
2261 UNREACHABLE(); | 2282 UNREACHABLE(); |
2262 } | 2283 } |
2263 return cond; | 2284 return cond; |
2264 } | 2285 } |
2265 | 2286 |
2266 | 2287 |
2267 void LCodeGen::DoCmpIDAndBranch(LCmpIDAndBranch* instr) { | 2288 void LCodeGen::DoCompareNumericAndBranch(LCompareNumericAndBranch* instr) { |
2268 LOperand* left = instr->left(); | 2289 LOperand* left = instr->left(); |
2269 LOperand* right = instr->right(); | 2290 LOperand* right = instr->right(); |
2270 Condition cc = TokenToCondition(instr->op(), instr->is_double()); | 2291 Condition cc = TokenToCondition(instr->op(), instr->is_double()); |
2271 | 2292 |
2272 if (left->IsConstantOperand() && right->IsConstantOperand()) { | 2293 if (left->IsConstantOperand() && right->IsConstantOperand()) { |
2273 // We can statically evaluate the comparison. | 2294 // We can statically evaluate the comparison. |
2274 double left_val = ToDouble(LConstantOperand::cast(left)); | 2295 double left_val = ToDouble(LConstantOperand::cast(left)); |
2275 double right_val = ToDouble(LConstantOperand::cast(right)); | 2296 double right_val = ToDouble(LConstantOperand::cast(right)); |
2276 int next_block = EvalComparison(instr->op(), left_val, right_val) ? | 2297 int next_block = EvalComparison(instr->op(), left_val, right_val) ? |
2277 instr->TrueDestination(chunk_) : instr->FalseDestination(chunk_); | 2298 instr->TrueDestination(chunk_) : instr->FalseDestination(chunk_); |
(...skipping 1500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3778 __ cvtsi2sd(xmm_scratch, output_reg); | 3799 __ cvtsi2sd(xmm_scratch, output_reg); |
3779 __ ucomisd(input_reg, xmm_scratch); | 3800 __ ucomisd(input_reg, xmm_scratch); |
3780 __ j(equal, &done, Label::kNear); | 3801 __ j(equal, &done, Label::kNear); |
3781 __ sub(output_reg, Immediate(1)); | 3802 __ sub(output_reg, Immediate(1)); |
3782 DeoptimizeIf(overflow, instr->environment()); | 3803 DeoptimizeIf(overflow, instr->environment()); |
3783 | 3804 |
3784 __ bind(&done); | 3805 __ bind(&done); |
3785 } | 3806 } |
3786 } | 3807 } |
3787 | 3808 |
| 3809 |
3788 void LCodeGen::DoMathRound(LMathRound* instr) { | 3810 void LCodeGen::DoMathRound(LMathRound* instr) { |
3789 CpuFeatureScope scope(masm(), SSE2); | 3811 CpuFeatureScope scope(masm(), SSE2); |
3790 Register output_reg = ToRegister(instr->result()); | 3812 Register output_reg = ToRegister(instr->result()); |
3791 XMMRegister input_reg = ToDoubleRegister(instr->value()); | 3813 XMMRegister input_reg = ToDoubleRegister(instr->value()); |
3792 XMMRegister xmm_scratch = xmm0; | 3814 XMMRegister xmm_scratch = xmm0; |
3793 XMMRegister input_temp = ToDoubleRegister(instr->temp()); | 3815 XMMRegister input_temp = ToDoubleRegister(instr->temp()); |
3794 ExternalReference one_half = ExternalReference::address_of_one_half(); | 3816 ExternalReference one_half = ExternalReference::address_of_one_half(); |
3795 ExternalReference minus_one_half = | 3817 ExternalReference minus_one_half = |
3796 ExternalReference::address_of_minus_one_half(); | 3818 ExternalReference::address_of_minus_one_half(); |
3797 | 3819 |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4168 | 4190 |
4169 | 4191 |
4170 void LCodeGen::DoCallNewArray(LCallNewArray* instr) { | 4192 void LCodeGen::DoCallNewArray(LCallNewArray* instr) { |
4171 ASSERT(ToRegister(instr->context()).is(esi)); | 4193 ASSERT(ToRegister(instr->context()).is(esi)); |
4172 ASSERT(ToRegister(instr->constructor()).is(edi)); | 4194 ASSERT(ToRegister(instr->constructor()).is(edi)); |
4173 ASSERT(ToRegister(instr->result()).is(eax)); | 4195 ASSERT(ToRegister(instr->result()).is(eax)); |
4174 | 4196 |
4175 __ Set(eax, Immediate(instr->arity())); | 4197 __ Set(eax, Immediate(instr->arity())); |
4176 __ mov(ebx, instr->hydrogen()->property_cell()); | 4198 __ mov(ebx, instr->hydrogen()->property_cell()); |
4177 ElementsKind kind = instr->hydrogen()->elements_kind(); | 4199 ElementsKind kind = instr->hydrogen()->elements_kind(); |
4178 bool disable_allocation_sites = | 4200 AllocationSiteOverrideMode override_mode = |
4179 (AllocationSiteInfo::GetMode(kind) == TRACK_ALLOCATION_SITE); | 4201 (AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE) |
| 4202 ? DISABLE_ALLOCATION_SITES |
| 4203 : DONT_OVERRIDE; |
| 4204 ContextCheckMode context_mode = CONTEXT_CHECK_NOT_REQUIRED; |
4180 | 4205 |
4181 if (instr->arity() == 0) { | 4206 if (instr->arity() == 0) { |
4182 ArrayNoArgumentConstructorStub stub(kind, disable_allocation_sites); | 4207 ArrayNoArgumentConstructorStub stub(kind, context_mode, override_mode); |
4183 CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); | 4208 CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
4184 } else if (instr->arity() == 1) { | 4209 } else if (instr->arity() == 1) { |
4185 Label done; | 4210 Label done; |
4186 if (IsFastPackedElementsKind(kind)) { | 4211 if (IsFastPackedElementsKind(kind)) { |
4187 Label packed_case; | 4212 Label packed_case; |
4188 // We might need a change here | 4213 // We might need a change here |
4189 // look at the first argument | 4214 // look at the first argument |
4190 __ mov(ecx, Operand(esp, 0)); | 4215 __ mov(ecx, Operand(esp, 0)); |
4191 __ test(ecx, ecx); | 4216 __ test(ecx, ecx); |
4192 __ j(zero, &packed_case); | 4217 __ j(zero, &packed_case); |
4193 | 4218 |
4194 ElementsKind holey_kind = GetHoleyElementsKind(kind); | 4219 ElementsKind holey_kind = GetHoleyElementsKind(kind); |
4195 ArraySingleArgumentConstructorStub stub(holey_kind, | 4220 ArraySingleArgumentConstructorStub stub(holey_kind, context_mode, |
4196 disable_allocation_sites); | 4221 override_mode); |
4197 CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); | 4222 CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
4198 __ jmp(&done); | 4223 __ jmp(&done); |
4199 __ bind(&packed_case); | 4224 __ bind(&packed_case); |
4200 } | 4225 } |
4201 | 4226 |
4202 ArraySingleArgumentConstructorStub stub(kind, disable_allocation_sites); | 4227 ArraySingleArgumentConstructorStub stub(kind, context_mode, override_mode); |
4203 CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); | 4228 CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
4204 __ bind(&done); | 4229 __ bind(&done); |
4205 } else { | 4230 } else { |
4206 ArrayNArgumentsConstructorStub stub(kind, disable_allocation_sites); | 4231 ArrayNArgumentsConstructorStub stub(kind, context_mode, override_mode); |
4207 CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); | 4232 CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
4208 } | 4233 } |
4209 } | 4234 } |
4210 | 4235 |
4211 | 4236 |
4212 void LCodeGen::DoCallRuntime(LCallRuntime* instr) { | 4237 void LCodeGen::DoCallRuntime(LCallRuntime* instr) { |
4213 CallRuntime(instr->function(), instr->arity(), instr); | 4238 CallRuntime(instr->function(), instr->arity(), instr); |
4214 } | 4239 } |
4215 | 4240 |
4216 | 4241 |
(...skipping 2331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6548 FixedArray::kHeaderSize - kPointerSize)); | 6573 FixedArray::kHeaderSize - kPointerSize)); |
6549 __ bind(&done); | 6574 __ bind(&done); |
6550 } | 6575 } |
6551 | 6576 |
6552 | 6577 |
6553 #undef __ | 6578 #undef __ |
6554 | 6579 |
6555 } } // namespace v8::internal | 6580 } } // namespace v8::internal |
6556 | 6581 |
6557 #endif // V8_TARGET_ARCH_IA32 | 6582 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |