Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. |
| 6 #if defined(TARGET_ARCH_X64) | 6 #if defined(TARGET_ARCH_X64) |
| 7 | 7 |
| 8 #include "vm/intermediate_language.h" | 8 #include "vm/intermediate_language.h" |
| 9 | 9 |
| 10 #include "lib/error.h" | 10 #include "lib/error.h" |
| (...skipping 2134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2145 FLAG_optimization_counter_threshold * (loop_depth() + 1); | 2145 FLAG_optimization_counter_threshold * (loop_depth() + 1); |
| 2146 __ cmpq(FieldAddress(temp, Function::usage_counter_offset()), | 2146 __ cmpq(FieldAddress(temp, Function::usage_counter_offset()), |
| 2147 Immediate(threshold)); | 2147 Immediate(threshold)); |
| 2148 __ j(GREATER_EQUAL, slow_path->entry_label()); | 2148 __ j(GREATER_EQUAL, slow_path->entry_label()); |
| 2149 } | 2149 } |
| 2150 __ Bind(slow_path->exit_label()); | 2150 __ Bind(slow_path->exit_label()); |
| 2151 } | 2151 } |
| 2152 | 2152 |
| 2153 | 2153 |
| 2154 static void EmitJavascriptOverflowCheck(FlowGraphCompiler* compiler, | 2154 static void EmitJavascriptOverflowCheck(FlowGraphCompiler* compiler, |
| 2155 Range* range, | |
| 2155 Label* overflow, | 2156 Label* overflow, |
| 2156 Register result) { | 2157 Register result) { |
| 2157 if (FLAG_throw_on_javascript_int_overflow) { | 2158 if (FLAG_throw_on_javascript_int_overflow && |
| 2159 !range->IsWithin(-0x20000000000000LL, 0x20000000000000LL)) { | |
|
srdjan
2013/08/02 18:07:22
Ditto for if (FLAG_throw_on_javascript_int_overflo
zra
2013/08/02 18:30:27
Done.
| |
| 2158 ASSERT(overflow != NULL); | 2160 ASSERT(overflow != NULL); |
| 2159 __ cmpq(result, Immediate(-0x20000000000000)); | 2161 __ cmpq(result, Immediate(-0x20000000000000LL)); |
| 2160 __ j(LESS, overflow); | 2162 __ j(LESS, overflow); |
| 2161 __ cmpq(result, Immediate(0x20000000000000)); | 2163 __ cmpq(result, Immediate(0x20000000000000LL)); |
| 2162 __ j(GREATER, overflow); | 2164 __ j(GREATER, overflow); |
| 2163 } | 2165 } |
| 2164 } | 2166 } |
| 2165 | 2167 |
| 2166 | 2168 |
| 2167 static void EmitSmiShiftLeft(FlowGraphCompiler* compiler, | 2169 static void EmitSmiShiftLeft(FlowGraphCompiler* compiler, |
| 2168 BinarySmiOpInstr* shift_left) { | 2170 BinarySmiOpInstr* shift_left) { |
| 2169 const bool is_truncating = shift_left->is_truncating(); | 2171 const bool is_truncating = shift_left->is_truncating(); |
| 2170 const LocationSummary& locs = *shift_left->locs(); | 2172 const LocationSummary& locs = *shift_left->locs(); |
| 2171 Register left = locs.in(0).reg(); | 2173 Register left = locs.in(0).reg(); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 2196 Register temp = locs.temp(0).reg(); | 2198 Register temp = locs.temp(0).reg(); |
| 2197 __ movq(temp, left); | 2199 __ movq(temp, left); |
| 2198 __ shlq(left, Immediate(value)); | 2200 __ shlq(left, Immediate(value)); |
| 2199 __ sarq(left, Immediate(value)); | 2201 __ sarq(left, Immediate(value)); |
| 2200 __ cmpq(left, temp); | 2202 __ cmpq(left, temp); |
| 2201 __ j(NOT_EQUAL, deopt); // Overflow. | 2203 __ j(NOT_EQUAL, deopt); // Overflow. |
| 2202 } | 2204 } |
| 2203 // Shift for result now we know there is no overflow. | 2205 // Shift for result now we know there is no overflow. |
| 2204 __ shlq(left, Immediate(value)); | 2206 __ shlq(left, Immediate(value)); |
| 2205 } | 2207 } |
| 2206 EmitJavascriptOverflowCheck(compiler, deopt, result); | 2208 EmitJavascriptOverflowCheck(compiler, shift_left->range(), deopt, result); |
| 2207 return; | 2209 return; |
| 2208 } | 2210 } |
| 2209 | 2211 |
| 2210 // Right (locs.in(1)) is not constant. | 2212 // Right (locs.in(1)) is not constant. |
| 2211 Register right = locs.in(1).reg(); | 2213 Register right = locs.in(1).reg(); |
| 2212 Range* right_range = shift_left->right()->definition()->range(); | 2214 Range* right_range = shift_left->right()->definition()->range(); |
| 2213 if (shift_left->left()->BindsToConstant() && !is_truncating) { | 2215 if (shift_left->left()->BindsToConstant() && !is_truncating) { |
| 2214 // TODO(srdjan): Implement code below for is_truncating(). | 2216 // TODO(srdjan): Implement code below for is_truncating(). |
| 2215 // If left is constant, we know the maximal allowed size for right. | 2217 // If left is constant, we know the maximal allowed size for right. |
| 2216 const Object& obj = shift_left->left()->BoundConstant(); | 2218 const Object& obj = shift_left->left()->BoundConstant(); |
| 2217 if (obj.IsSmi()) { | 2219 if (obj.IsSmi()) { |
| 2218 const intptr_t left_int = Smi::Cast(obj).Value(); | 2220 const intptr_t left_int = Smi::Cast(obj).Value(); |
| 2219 if (left_int == 0) { | 2221 if (left_int == 0) { |
| 2220 __ cmpq(right, Immediate(0)); | 2222 __ cmpq(right, Immediate(0)); |
| 2221 __ j(NEGATIVE, deopt); | 2223 __ j(NEGATIVE, deopt); |
| 2222 return; | 2224 return; |
| 2223 } | 2225 } |
| 2224 const intptr_t max_right = kSmiBits - Utils::HighestBit(left_int); | 2226 const intptr_t max_right = kSmiBits - Utils::HighestBit(left_int); |
| 2225 const bool right_needs_check = | 2227 const bool right_needs_check = |
| 2226 (right_range == NULL) || | 2228 (right_range == NULL) || |
| 2227 !right_range->IsWithin(0, max_right - 1); | 2229 !right_range->IsWithin(0, max_right - 1); |
| 2228 if (right_needs_check) { | 2230 if (right_needs_check) { |
| 2229 __ cmpq(right, | 2231 __ cmpq(right, |
| 2230 Immediate(reinterpret_cast<int64_t>(Smi::New(max_right)))); | 2232 Immediate(reinterpret_cast<int64_t>(Smi::New(max_right)))); |
| 2231 __ j(ABOVE_EQUAL, deopt); | 2233 __ j(ABOVE_EQUAL, deopt); |
| 2232 } | 2234 } |
| 2233 __ SmiUntag(right); | 2235 __ SmiUntag(right); |
| 2234 __ shlq(left, right); | 2236 __ shlq(left, right); |
| 2235 } | 2237 } |
| 2236 EmitJavascriptOverflowCheck(compiler, deopt, result); | 2238 EmitJavascriptOverflowCheck(compiler, shift_left->range(), deopt, result); |
| 2237 return; | 2239 return; |
| 2238 } | 2240 } |
| 2239 | 2241 |
| 2240 const bool right_needs_check = | 2242 const bool right_needs_check = |
| 2241 (right_range == NULL) || !right_range->IsWithin(0, (Smi::kBits - 1)); | 2243 (right_range == NULL) || !right_range->IsWithin(0, (Smi::kBits - 1)); |
| 2242 ASSERT(right == RCX); // Count must be in RCX | 2244 ASSERT(right == RCX); // Count must be in RCX |
| 2243 if (is_truncating) { | 2245 if (is_truncating) { |
| 2244 if (right_needs_check) { | 2246 if (right_needs_check) { |
| 2245 const bool right_may_be_negative = | 2247 const bool right_may_be_negative = |
| 2246 (right_range == NULL) || | 2248 (right_range == NULL) || |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 2277 __ movq(temp, left); | 2279 __ movq(temp, left); |
| 2278 __ SmiUntag(right); | 2280 __ SmiUntag(right); |
| 2279 // Overflow test (preserve temp and right); | 2281 // Overflow test (preserve temp and right); |
| 2280 __ shlq(left, right); | 2282 __ shlq(left, right); |
| 2281 __ sarq(left, right); | 2283 __ sarq(left, right); |
| 2282 __ cmpq(left, temp); | 2284 __ cmpq(left, temp); |
| 2283 __ j(NOT_EQUAL, deopt); // Overflow. | 2285 __ j(NOT_EQUAL, deopt); // Overflow. |
| 2284 // Shift for result now we know there is no overflow. | 2286 // Shift for result now we know there is no overflow. |
| 2285 __ shlq(left, right); | 2287 __ shlq(left, right); |
| 2286 } | 2288 } |
| 2287 EmitJavascriptOverflowCheck(compiler, deopt, result); | 2289 EmitJavascriptOverflowCheck(compiler, shift_left->range(), deopt, result); |
| 2288 } | 2290 } |
| 2289 | 2291 |
| 2290 | 2292 |
| 2291 static bool CanBeImmediate(const Object& constant) { | 2293 static bool CanBeImmediate(const Object& constant) { |
| 2292 return constant.IsSmi() && | 2294 return constant.IsSmi() && |
| 2293 Immediate(reinterpret_cast<int64_t>(constant.raw())).is_int32(); | 2295 Immediate(reinterpret_cast<int64_t>(constant.raw())).is_int32(); |
| 2294 } | 2296 } |
| 2295 | 2297 |
| 2296 | 2298 |
| 2297 LocationSummary* BinarySmiOpInstr::MakeLocationSummary() const { | 2299 LocationSummary* BinarySmiOpInstr::MakeLocationSummary() const { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2476 | 2478 |
| 2477 __ sarq(left, Immediate(value)); | 2479 __ sarq(left, Immediate(value)); |
| 2478 __ SmiTag(left); | 2480 __ SmiTag(left); |
| 2479 break; | 2481 break; |
| 2480 } | 2482 } |
| 2481 | 2483 |
| 2482 default: | 2484 default: |
| 2483 UNREACHABLE(); | 2485 UNREACHABLE(); |
| 2484 break; | 2486 break; |
| 2485 } | 2487 } |
| 2486 EmitJavascriptOverflowCheck(compiler, deopt, result); | 2488 EmitJavascriptOverflowCheck(compiler, range(), deopt, result); |
| 2487 return; | 2489 return; |
| 2488 } // locs()->in(1).IsConstant(). | 2490 } // locs()->in(1).IsConstant(). |
| 2489 | 2491 |
| 2490 | 2492 |
| 2491 if (locs()->in(1).IsStackSlot()) { | 2493 if (locs()->in(1).IsStackSlot()) { |
| 2492 const Address& right = locs()->in(1).ToStackSlotAddress(); | 2494 const Address& right = locs()->in(1).ToStackSlotAddress(); |
| 2493 switch (op_kind()) { | 2495 switch (op_kind()) { |
| 2494 case Token::kADD: { | 2496 case Token::kADD: { |
| 2495 __ addq(left, right); | 2497 __ addq(left, right); |
| 2496 if (deopt != NULL) __ j(OVERFLOW, deopt); | 2498 if (deopt != NULL) __ j(OVERFLOW, deopt); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 2519 } | 2521 } |
| 2520 case Token::kBIT_XOR: { | 2522 case Token::kBIT_XOR: { |
| 2521 // No overflow check. | 2523 // No overflow check. |
| 2522 __ xorq(left, right); | 2524 __ xorq(left, right); |
| 2523 break; | 2525 break; |
| 2524 } | 2526 } |
| 2525 default: | 2527 default: |
| 2526 UNREACHABLE(); | 2528 UNREACHABLE(); |
| 2527 break; | 2529 break; |
| 2528 } | 2530 } |
| 2529 EmitJavascriptOverflowCheck(compiler, deopt, result); | 2531 EmitJavascriptOverflowCheck(compiler, range(), deopt, result); |
| 2530 return; | 2532 return; |
| 2531 } // locs()->in(1).IsStackSlot(). | 2533 } // locs()->in(1).IsStackSlot(). |
| 2532 | 2534 |
| 2533 // if locs()->in(1).IsRegister. | 2535 // if locs()->in(1).IsRegister. |
| 2534 Register right = locs()->in(1).reg(); | 2536 Register right = locs()->in(1).reg(); |
| 2535 switch (op_kind()) { | 2537 switch (op_kind()) { |
| 2536 case Token::kADD: { | 2538 case Token::kADD: { |
| 2537 __ addq(left, right); | 2539 __ addq(left, right); |
| 2538 if (deopt != NULL) __ j(OVERFLOW, deopt); | 2540 if (deopt != NULL) __ j(OVERFLOW, deopt); |
| 2539 break; | 2541 break; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2649 case Token::kAND: { | 2651 case Token::kAND: { |
| 2650 // Flow graph builder has dissected this operation to guarantee correct | 2652 // Flow graph builder has dissected this operation to guarantee correct |
| 2651 // behavior (short-circuit evaluation). | 2653 // behavior (short-circuit evaluation). |
| 2652 UNREACHABLE(); | 2654 UNREACHABLE(); |
| 2653 break; | 2655 break; |
| 2654 } | 2656 } |
| 2655 default: | 2657 default: |
| 2656 UNREACHABLE(); | 2658 UNREACHABLE(); |
| 2657 break; | 2659 break; |
| 2658 } | 2660 } |
| 2659 EmitJavascriptOverflowCheck(compiler, deopt, result); | 2661 EmitJavascriptOverflowCheck(compiler, range(), deopt, result); |
| 2660 } | 2662 } |
| 2661 | 2663 |
| 2662 | 2664 |
| 2663 LocationSummary* CheckEitherNonSmiInstr::MakeLocationSummary() const { | 2665 LocationSummary* CheckEitherNonSmiInstr::MakeLocationSummary() const { |
| 2664 intptr_t left_cid = left()->Type()->ToCid(); | 2666 intptr_t left_cid = left()->Type()->ToCid(); |
| 2665 intptr_t right_cid = right()->Type()->ToCid(); | 2667 intptr_t right_cid = right()->Type()->ToCid(); |
| 2666 ASSERT((left_cid != kDoubleCid) && (right_cid != kDoubleCid)); | 2668 ASSERT((left_cid != kDoubleCid) && (right_cid != kDoubleCid)); |
| 2667 const intptr_t kNumInputs = 2; | 2669 const intptr_t kNumInputs = 2; |
| 2668 const bool need_temp = (left_cid != kSmiCid) && (right_cid != kSmiCid); | 2670 const bool need_temp = (left_cid != kSmiCid) && (right_cid != kSmiCid); |
| 2669 const intptr_t kNumTemps = need_temp ? 1 : 0; | 2671 const intptr_t kNumTemps = need_temp ? 1 : 0; |
| (...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3827 | 3829 |
| 3828 void UnarySmiOpInstr::EmitNativeCode(FlowGraphCompiler* compiler) { | 3830 void UnarySmiOpInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| 3829 Register value = locs()->in(0).reg(); | 3831 Register value = locs()->in(0).reg(); |
| 3830 ASSERT(value == locs()->out().reg()); | 3832 ASSERT(value == locs()->out().reg()); |
| 3831 switch (op_kind()) { | 3833 switch (op_kind()) { |
| 3832 case Token::kNEGATE: { | 3834 case Token::kNEGATE: { |
| 3833 Label* deopt = compiler->AddDeoptStub(deopt_id(), | 3835 Label* deopt = compiler->AddDeoptStub(deopt_id(), |
| 3834 kDeoptUnaryOp); | 3836 kDeoptUnaryOp); |
| 3835 __ negq(value); | 3837 __ negq(value); |
| 3836 __ j(OVERFLOW, deopt); | 3838 __ j(OVERFLOW, deopt); |
| 3837 EmitJavascriptOverflowCheck(compiler, deopt, value); | 3839 EmitJavascriptOverflowCheck(compiler, range(), deopt, value); |
| 3838 break; | 3840 break; |
| 3839 } | 3841 } |
| 3840 case Token::kBIT_NOT: | 3842 case Token::kBIT_NOT: |
| 3841 __ notq(value); | 3843 __ notq(value); |
| 3842 __ andq(value, Immediate(~kSmiTagMask)); // Remove inverted smi-tag. | 3844 __ andq(value, Immediate(~kSmiTagMask)); // Remove inverted smi-tag. |
| 3843 break; | 3845 break; |
| 3844 default: | 3846 default: |
| 3845 UNREACHABLE(); | 3847 UNREACHABLE(); |
| 3846 } | 3848 } |
| 3847 } | 3849 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3888 ASSERT(result != temp); | 3890 ASSERT(result != temp); |
| 3889 __ movsd(value_double, FieldAddress(value_obj, Double::value_offset())); | 3891 __ movsd(value_double, FieldAddress(value_obj, Double::value_offset())); |
| 3890 __ cvttsd2siq(result, value_double); | 3892 __ cvttsd2siq(result, value_double); |
| 3891 // Overflow is signalled with minint. | 3893 // Overflow is signalled with minint. |
| 3892 Label do_call, done; | 3894 Label do_call, done; |
| 3893 // Check for overflow and that it fits into Smi. | 3895 // Check for overflow and that it fits into Smi. |
| 3894 __ movq(temp, result); | 3896 __ movq(temp, result); |
| 3895 __ shlq(temp, Immediate(1)); | 3897 __ shlq(temp, Immediate(1)); |
| 3896 __ j(OVERFLOW, &do_call, Assembler::kNearJump); | 3898 __ j(OVERFLOW, &do_call, Assembler::kNearJump); |
| 3897 __ SmiTag(result); | 3899 __ SmiTag(result); |
| 3898 EmitJavascriptOverflowCheck(compiler, &do_call, result); | 3900 EmitJavascriptOverflowCheck(compiler, range(), &do_call, result); |
| 3899 __ jmp(&done); | 3901 __ jmp(&done); |
| 3900 __ Bind(&do_call); | 3902 __ Bind(&do_call); |
| 3901 ASSERT(instance_call()->HasICData()); | 3903 ASSERT(instance_call()->HasICData()); |
| 3902 const ICData& ic_data = *instance_call()->ic_data(); | 3904 const ICData& ic_data = *instance_call()->ic_data(); |
| 3903 ASSERT((ic_data.NumberOfChecks() == 1)); | 3905 ASSERT((ic_data.NumberOfChecks() == 1)); |
| 3904 const Function& target = Function::ZoneHandle(ic_data.GetTargetAt(0)); | 3906 const Function& target = Function::ZoneHandle(ic_data.GetTargetAt(0)); |
| 3905 | 3907 |
| 3906 const intptr_t kNumberOfArguments = 1; | 3908 const intptr_t kNumberOfArguments = 1; |
| 3907 __ pushq(value_obj); | 3909 __ pushq(value_obj); |
| 3908 compiler->GenerateStaticCall(deopt_id(), | 3910 compiler->GenerateStaticCall(deopt_id(), |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 3934 Register temp = locs()->temp(0).reg(); | 3936 Register temp = locs()->temp(0).reg(); |
| 3935 | 3937 |
| 3936 __ cvttsd2siq(result, value); | 3938 __ cvttsd2siq(result, value); |
| 3937 // Overflow is signalled with minint. | 3939 // Overflow is signalled with minint. |
| 3938 Label do_call, done; | 3940 Label do_call, done; |
| 3939 // Check for overflow and that it fits into Smi. | 3941 // Check for overflow and that it fits into Smi. |
| 3940 __ movq(temp, result); | 3942 __ movq(temp, result); |
| 3941 __ shlq(temp, Immediate(1)); | 3943 __ shlq(temp, Immediate(1)); |
| 3942 __ j(OVERFLOW, deopt); | 3944 __ j(OVERFLOW, deopt); |
| 3943 __ SmiTag(result); | 3945 __ SmiTag(result); |
| 3944 EmitJavascriptOverflowCheck(compiler, deopt, result); | 3946 EmitJavascriptOverflowCheck(compiler, range(), deopt, result); |
| 3945 } | 3947 } |
| 3946 | 3948 |
| 3947 | 3949 |
| 3948 LocationSummary* DoubleToDoubleInstr::MakeLocationSummary() const { | 3950 LocationSummary* DoubleToDoubleInstr::MakeLocationSummary() const { |
| 3949 const intptr_t kNumInputs = 1; | 3951 const intptr_t kNumInputs = 1; |
| 3950 const intptr_t kNumTemps = 0; | 3952 const intptr_t kNumTemps = 0; |
| 3951 LocationSummary* result = | 3953 LocationSummary* result = |
| 3952 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); | 3954 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); |
| 3953 result->set_in(0, Location::RequiresFpuRegister()); | 3955 result->set_in(0, Location::RequiresFpuRegister()); |
| 3954 result->set_out(Location::RequiresFpuRegister()); | 3956 result->set_out(Location::RequiresFpuRegister()); |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4544 PcDescriptors::kOther, | 4546 PcDescriptors::kOther, |
| 4545 locs()); | 4547 locs()); |
| 4546 __ Drop(2); // Discard type arguments and receiver. | 4548 __ Drop(2); // Discard type arguments and receiver. |
| 4547 } | 4549 } |
| 4548 | 4550 |
| 4549 } // namespace dart | 4551 } // namespace dart |
| 4550 | 4552 |
| 4551 #undef __ | 4553 #undef __ |
| 4552 | 4554 |
| 4553 #endif // defined TARGET_ARCH_X64 | 4555 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |