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_IA32. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. |
| 6 #if defined(TARGET_ARCH_IA32) | 6 #if defined(TARGET_ARCH_IA32) |
| 7 | 7 |
| 8 #include "vm/intermediate_language.h" | 8 #include "vm/intermediate_language.h" |
| 9 | 9 |
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
| (...skipping 2402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2413 break; | 2413 break; |
| 2414 } | 2414 } |
| 2415 default: | 2415 default: |
| 2416 UNREACHABLE(); | 2416 UNREACHABLE(); |
| 2417 } | 2417 } |
| 2418 return; | 2418 return; |
| 2419 } // if locs()->in(1).IsStackSlot. | 2419 } // if locs()->in(1).IsStackSlot. |
| 2420 | 2420 |
| 2421 // if locs()->in(1).IsRegister. | 2421 // if locs()->in(1).IsRegister. |
| 2422 Register right = locs()->in(1).reg(); | 2422 Register right = locs()->in(1).reg(); |
| 2423 Range* right_range = this->right()->definition()->range(); | |
| 2423 switch (op_kind()) { | 2424 switch (op_kind()) { |
| 2424 case Token::kADD: { | 2425 case Token::kADD: { |
| 2425 __ addl(left, right); | 2426 __ addl(left, right); |
| 2426 if (deopt != NULL) __ j(OVERFLOW, deopt); | 2427 if (deopt != NULL) __ j(OVERFLOW, deopt); |
| 2427 break; | 2428 break; |
| 2428 } | 2429 } |
| 2429 case Token::kSUB: { | 2430 case Token::kSUB: { |
| 2430 __ subl(left, right); | 2431 __ subl(left, right); |
| 2431 if (deopt != NULL) __ j(OVERFLOW, deopt); | 2432 if (deopt != NULL) __ j(OVERFLOW, deopt); |
| 2432 break; | 2433 break; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 2446 // No overflow check. | 2447 // No overflow check. |
| 2447 __ orl(left, right); | 2448 __ orl(left, right); |
| 2448 break; | 2449 break; |
| 2449 } | 2450 } |
| 2450 case Token::kBIT_XOR: { | 2451 case Token::kBIT_XOR: { |
| 2451 // No overflow check. | 2452 // No overflow check. |
| 2452 __ xorl(left, right); | 2453 __ xorl(left, right); |
| 2453 break; | 2454 break; |
| 2454 } | 2455 } |
| 2455 case Token::kTRUNCDIV: { | 2456 case Token::kTRUNCDIV: { |
| 2456 // Handle divide by zero in runtime. | 2457 if ((right_range == NULL) || right_range->IsWithin(0, 0)) { |
|
Florian Schneider
2013/11/22 15:17:11
Please also make sure that there is test coverage
srdjan
2013/11/22 22:08:17
Added test coverage, added Range::Overlaps functio
| |
| 2457 __ testl(right, right); | 2458 // Handle divide by zero in runtime. |
| 2458 __ j(ZERO, deopt); | 2459 __ testl(right, right); |
| 2460 __ j(ZERO, deopt); | |
| 2461 } | |
| 2459 ASSERT(left == EAX); | 2462 ASSERT(left == EAX); |
| 2460 ASSERT((right != EDX) && (right != EAX)); | 2463 ASSERT((right != EDX) && (right != EAX)); |
| 2461 ASSERT(locs()->temp(0).reg() == EDX); | 2464 ASSERT(locs()->temp(0).reg() == EDX); |
| 2462 ASSERT(result == EAX); | 2465 ASSERT(result == EAX); |
| 2463 __ SmiUntag(left); | 2466 __ SmiUntag(left); |
| 2464 __ SmiUntag(right); | 2467 __ SmiUntag(right); |
| 2465 __ cdq(); // Sign extend EAX -> EDX:EAX. | 2468 __ cdq(); // Sign extend EAX -> EDX:EAX. |
| 2466 __ idivl(right); // EAX: quotient, EDX: remainder. | 2469 __ idivl(right); // EAX: quotient, EDX: remainder. |
| 2467 // Check the corner case of dividing the 'MIN_SMI' with -1, in which | 2470 // Check the corner case of dividing the 'MIN_SMI' with -1, in which |
| 2468 // case we cannot tag the result. | 2471 // case we cannot tag the result. |
| 2469 __ cmpl(result, Immediate(0x40000000)); | 2472 __ cmpl(result, Immediate(0x40000000)); |
| 2470 __ j(EQUAL, deopt); | 2473 __ j(EQUAL, deopt); |
| 2471 __ SmiTag(result); | 2474 __ SmiTag(result); |
| 2472 break; | 2475 break; |
| 2473 } | 2476 } |
| 2474 case Token::kMOD: { | 2477 case Token::kMOD: { |
| 2475 // Handle divide by zero in runtime. | 2478 if ((right_range == NULL) || right_range->IsWithin(0, 0)) { |
| 2476 __ testl(right, right); | 2479 // Handle divide by zero in runtime. |
| 2477 __ j(ZERO, deopt); | 2480 __ testl(right, right); |
| 2481 __ j(ZERO, deopt); | |
| 2482 } | |
|
Florian Schneider
2013/11/22 15:17:11
In the case that the instruction can't deoptimize
srdjan
2013/11/22 22:08:17
Changed BinarySmiOperation::CanDeoptimize.
| |
| 2478 ASSERT(left == EDX); | 2483 ASSERT(left == EDX); |
| 2479 ASSERT((right != EDX) && (right != EAX)); | 2484 ASSERT((right != EDX) && (right != EAX)); |
| 2480 ASSERT(locs()->temp(0).reg() == EAX); | 2485 ASSERT(locs()->temp(0).reg() == EAX); |
| 2481 ASSERT(result == EDX); | 2486 ASSERT(result == EDX); |
| 2482 __ SmiUntag(left); | 2487 __ SmiUntag(left); |
| 2483 __ SmiUntag(right); | 2488 __ SmiUntag(right); |
| 2484 __ movl(EAX, EDX); | 2489 __ movl(EAX, EDX); |
| 2485 __ cdq(); // Sign extend EAX -> EDX:EAX. | 2490 __ cdq(); // Sign extend EAX -> EDX:EAX. |
| 2486 __ idivl(right); // EAX: quotient, EDX: remainder. | 2491 __ idivl(right); // EAX: quotient, EDX: remainder. |
| 2487 // res = left % right; | 2492 // res = left % right; |
| 2488 // if (res < 0) { | 2493 // if (res < 0) { |
| 2489 // if (right < 0) { | 2494 // if (right < 0) { |
| 2490 // res = res - right; | 2495 // res = res - right; |
| 2491 // } else { | 2496 // } else { |
| 2492 // res = res + right; | 2497 // res = res + right; |
| 2493 // } | 2498 // } |
| 2494 // } | 2499 // } |
| 2495 Label subtract, done; | 2500 Label done; |
| 2496 __ cmpl(result, Immediate(0)); | 2501 __ cmpl(result, Immediate(0)); |
| 2497 __ j(GREATER_EQUAL, &done, Assembler::kNearJump); | 2502 __ j(GREATER_EQUAL, &done, Assembler::kNearJump); |
| 2498 // Result is negative, adjust it. | 2503 // Result is negative, adjust it. |
| 2499 __ cmpl(right, Immediate(0)); | 2504 if ((right_range == NULL) || right_range->IsWithin(-1, 1)) { |
| 2500 __ j(LESS, &subtract, Assembler::kNearJump); | 2505 Label subtract; |
| 2501 __ addl(result, right); | 2506 __ cmpl(right, Immediate(0)); |
| 2502 __ jmp(&done, Assembler::kNearJump); | 2507 __ j(LESS, &subtract, Assembler::kNearJump); |
| 2503 __ Bind(&subtract); | 2508 __ addl(result, right); |
| 2504 __ subl(result, right); | 2509 __ jmp(&done, Assembler::kNearJump); |
| 2510 __ Bind(&subtract); | |
| 2511 __ subl(result, right); | |
| 2512 } else if (right_range->IsWithin(0, RangeBoundary::kPlusInfinity)) { | |
| 2513 // Right is positive. | |
| 2514 __ addl(result, right); | |
| 2515 } else { | |
| 2516 // Right is negative. | |
| 2517 __ subl(result, right); | |
| 2518 } | |
| 2505 __ Bind(&done); | 2519 __ Bind(&done); |
| 2506 __ SmiTag(result); | 2520 __ SmiTag(result); |
| 2507 break; | 2521 break; |
| 2508 } | 2522 } |
| 2509 case Token::kSHR: { | 2523 case Token::kSHR: { |
| 2510 if (CanDeoptimize()) { | 2524 if (CanDeoptimize()) { |
| 2511 __ cmpl(right, Immediate(0)); | 2525 __ cmpl(right, Immediate(0)); |
| 2512 __ j(LESS, deopt); | 2526 __ j(LESS, deopt); |
| 2513 } | 2527 } |
| 2514 __ SmiUntag(right); | 2528 __ SmiUntag(right); |
| 2515 // sarl operation masks the count to 5 bits. | 2529 // sarl operation masks the count to 5 bits. |
| 2516 const intptr_t kCountLimit = 0x1F; | 2530 const intptr_t kCountLimit = 0x1F; |
| 2517 Range* right_range = this->right()->definition()->range(); | |
| 2518 if ((right_range == NULL) || | 2531 if ((right_range == NULL) || |
| 2519 !right_range->IsWithin(RangeBoundary::kMinusInfinity, kCountLimit)) { | 2532 !right_range->IsWithin(RangeBoundary::kMinusInfinity, kCountLimit)) { |
| 2520 __ cmpl(right, Immediate(kCountLimit)); | 2533 __ cmpl(right, Immediate(kCountLimit)); |
| 2521 Label count_ok; | 2534 Label count_ok; |
| 2522 __ j(LESS, &count_ok, Assembler::kNearJump); | 2535 __ j(LESS, &count_ok, Assembler::kNearJump); |
| 2523 __ movl(right, Immediate(kCountLimit)); | 2536 __ movl(right, Immediate(kCountLimit)); |
| 2524 __ Bind(&count_ok); | 2537 __ Bind(&count_ok); |
| 2525 } | 2538 } |
| 2526 ASSERT(right == ECX); // Count must be in ECX | 2539 ASSERT(right == ECX); // Count must be in ECX |
| 2527 __ SmiUntag(left); | 2540 __ SmiUntag(left); |
| (...skipping 1472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4000 void MergedMathInstr::EmitNativeCode(FlowGraphCompiler* compiler) { | 4013 void MergedMathInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| 4001 Label* deopt = NULL; | 4014 Label* deopt = NULL; |
| 4002 if (CanDeoptimize()) { | 4015 if (CanDeoptimize()) { |
| 4003 deopt = compiler->AddDeoptStub(deopt_id(), kDeoptBinarySmiOp); | 4016 deopt = compiler->AddDeoptStub(deopt_id(), kDeoptBinarySmiOp); |
| 4004 } | 4017 } |
| 4005 | 4018 |
| 4006 if (kind() == MergedMathInstr::kTruncDivMod) { | 4019 if (kind() == MergedMathInstr::kTruncDivMod) { |
| 4007 Register left = locs()->in(0).reg(); | 4020 Register left = locs()->in(0).reg(); |
| 4008 Register right = locs()->in(1).reg(); | 4021 Register right = locs()->in(1).reg(); |
| 4009 Register result = locs()->out().reg(); | 4022 Register result = locs()->out().reg(); |
| 4010 // Handle divide by zero in runtime. | 4023 Range* right_range = InputAt(1)->definition()->range(); |
| 4011 __ testl(right, right); | 4024 if ((right_range == NULL) || right_range->IsWithin(0, 0)) { |
| 4012 __ j(ZERO, deopt); | 4025 // Handle divide by zero in runtime. |
| 4026 __ testl(right, right); | |
| 4027 __ j(ZERO, deopt); | |
| 4028 } | |
| 4013 ASSERT(left == EAX); | 4029 ASSERT(left == EAX); |
| 4014 ASSERT((right != EDX) && (right != EAX)); | 4030 ASSERT((right != EDX) && (right != EAX)); |
| 4015 ASSERT(locs()->temp(0).reg() == EDX); | 4031 ASSERT(locs()->temp(0).reg() == EDX); |
| 4016 ASSERT((result != EDX) && (result != EAX)); | 4032 ASSERT((result != EDX) && (result != EAX)); |
| 4017 __ SmiUntag(left); | 4033 __ SmiUntag(left); |
| 4018 __ SmiUntag(right); | 4034 __ SmiUntag(right); |
| 4019 __ cdq(); // Sign extend EAX -> EDX:EAX. | 4035 __ cdq(); // Sign extend EAX -> EDX:EAX. |
| 4020 __ idivl(right); // EAX: quotient, EDX: remainder. | 4036 __ idivl(right); // EAX: quotient, EDX: remainder. |
| 4021 // Check the corner case of dividing the 'MIN_SMI' with -1, in which | 4037 // Check the corner case of dividing the 'MIN_SMI' with -1, in which |
| 4022 // case we cannot tag the result. | 4038 // case we cannot tag the result. |
| 4023 // TODO(srdjan): We could store instead untagged intermediate results in a | 4039 // TODO(srdjan): We could store instead untagged intermediate results in a |
| 4024 // typed array, but then the load indexed instructions would need to be | 4040 // typed array, but then the load indexed instructions would need to be |
| 4025 // able to deoptimize. | 4041 // able to deoptimize. |
| 4026 __ cmpl(EAX, Immediate(0x40000000)); | 4042 __ cmpl(EAX, Immediate(0x40000000)); |
| 4027 __ j(EQUAL, deopt); | 4043 __ j(EQUAL, deopt); |
| 4028 // Modulo result (EDX) correction: | 4044 // Modulo result (EDX) correction: |
| 4029 // res = left % right; | 4045 // res = left % right; |
| 4030 // if (res < 0) { | 4046 // if (res < 0) { |
| 4031 // if (right < 0) { | 4047 // if (right < 0) { |
| 4032 // res = res - right; | 4048 // res = res - right; |
| 4033 // } else { | 4049 // } else { |
| 4034 // res = res + right; | 4050 // res = res + right; |
| 4035 // } | 4051 // } |
| 4036 // } | 4052 // } |
| 4037 Label subtract, done; | 4053 Label done; |
| 4038 __ cmpl(EDX, Immediate(0)); | 4054 __ cmpl(EDX, Immediate(0)); |
| 4039 __ j(GREATER_EQUAL, &done, Assembler::kNearJump); | 4055 __ j(GREATER_EQUAL, &done, Assembler::kNearJump); |
| 4040 // Result is negative, adjust it. | 4056 // Result is negative, adjust it. |
| 4041 __ cmpl(right, Immediate(0)); | 4057 if ((right_range == NULL) || right_range->IsWithin(-1, 1)) { |
| 4042 __ j(LESS, &subtract, Assembler::kNearJump); | 4058 Label subtract; |
| 4043 __ addl(EDX, right); | 4059 __ cmpl(right, Immediate(0)); |
| 4044 __ jmp(&done, Assembler::kNearJump); | 4060 __ j(LESS, &subtract, Assembler::kNearJump); |
| 4045 __ Bind(&subtract); | 4061 __ addl(EDX, right); |
| 4046 __ subl(EDX, right); | 4062 __ jmp(&done, Assembler::kNearJump); |
| 4063 __ Bind(&subtract); | |
| 4064 __ subl(EDX, right); | |
| 4065 } else if (right_range->IsWithin(0, RangeBoundary::kPlusInfinity)) { | |
| 4066 // Right is positive. | |
| 4067 __ addl(EDX, right); | |
| 4068 } else { | |
| 4069 // Right is negative. | |
| 4070 __ subl(EDX, right); | |
| 4071 } | |
| 4047 __ Bind(&done); | 4072 __ Bind(&done); |
| 4048 | 4073 |
| 4049 __ LoadObject(result, Array::ZoneHandle(Array::New(2, Heap::kOld))); | 4074 __ LoadObject(result, Array::ZoneHandle(Array::New(2, Heap::kOld))); |
| 4050 const intptr_t index_scale = FlowGraphCompiler::ElementSizeFor(kArrayCid); | 4075 const intptr_t index_scale = FlowGraphCompiler::ElementSizeFor(kArrayCid); |
| 4051 Address trunc_div_address( | 4076 Address trunc_div_address( |
| 4052 FlowGraphCompiler::ElementAddressForIntIndex(kArrayCid, | 4077 FlowGraphCompiler::ElementAddressForIntIndex(kArrayCid, |
| 4053 index_scale, | 4078 index_scale, |
| 4054 result, | 4079 result, |
| 4055 0)); | 4080 0)); |
| 4056 Address mod_address( | 4081 Address mod_address( |
| (...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4967 PcDescriptors::kOther, | 4992 PcDescriptors::kOther, |
| 4968 locs()); | 4993 locs()); |
| 4969 __ Drop(2); // Discard type arguments and receiver. | 4994 __ Drop(2); // Discard type arguments and receiver. |
| 4970 } | 4995 } |
| 4971 | 4996 |
| 4972 } // namespace dart | 4997 } // namespace dart |
| 4973 | 4998 |
| 4974 #undef __ | 4999 #undef __ |
| 4975 | 5000 |
| 4976 #endif // defined TARGET_ARCH_IA32 | 5001 #endif // defined TARGET_ARCH_IA32 |
| OLD | NEW |