Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: runtime/vm/intermediate_language_mips.cc

Issue 61123003: Inline integer modulo operation. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_MIPS. 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_MIPS.
6 #if defined(TARGET_ARCH_MIPS) 6 #if defined(TARGET_ARCH_MIPS)
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 2296 matching lines...) Expand 10 before | Expand all | Expand 10 after
2307 if (RightIsPowerOfTwoConstant()) { 2307 if (RightIsPowerOfTwoConstant()) {
2308 ConstantInstr* right_constant = right()->definition()->AsConstant(); 2308 ConstantInstr* right_constant = right()->definition()->AsConstant();
2309 summary->set_in(1, Location::Constant(right_constant->value())); 2309 summary->set_in(1, Location::Constant(right_constant->value()));
2310 } else { 2310 } else {
2311 summary->set_in(1, Location::RequiresRegister()); 2311 summary->set_in(1, Location::RequiresRegister());
2312 } 2312 }
2313 summary->AddTemp(Location::RequiresRegister()); 2313 summary->AddTemp(Location::RequiresRegister());
2314 summary->set_out(Location::RequiresRegister()); 2314 summary->set_out(Location::RequiresRegister());
2315 return summary; 2315 return summary;
2316 } 2316 }
2317 if (op_kind() == Token::kMOD) {
2318 summary->set_in(0, Location::RequiresRegister());
2319 summary->set_in(1, Location::RequiresRegister());
2320 summary->AddTemp(Location::RequiresRegister());
2321 summary->set_out(Location::RequiresRegister());
2322 return summary;
2323 }
2317 summary->set_in(0, Location::RequiresRegister()); 2324 summary->set_in(0, Location::RequiresRegister());
2318 summary->set_in(1, Location::RegisterOrSmiConstant(right())); 2325 summary->set_in(1, Location::RegisterOrSmiConstant(right()));
2319 if (((op_kind() == Token::kSHL) && !is_truncating()) || 2326 if (((op_kind() == Token::kSHL) && !is_truncating()) ||
2320 (op_kind() == Token::kSHR)) { 2327 (op_kind() == Token::kSHR)) {
2321 summary->AddTemp(Location::RequiresRegister()); 2328 summary->AddTemp(Location::RequiresRegister());
2322 } else if (op_kind() == Token::kADD) { 2329 } else if (op_kind() == Token::kADD) {
2323 // Need an extra temp for the overflow detection code. 2330 // Need an extra temp for the overflow detection code.
2324 summary->set_temp(0, Location::RequiresRegister()); 2331 summary->set_temp(0, Location::RequiresRegister());
2325 } 2332 }
2326 // We make use of 3-operand instructions by not requiring result register 2333 // We make use of 3-operand instructions by not requiring result register
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
2547 __ sra(temp, left, kSmiTagSize); // SmiUntag left into temp. 2554 __ sra(temp, left, kSmiTagSize); // SmiUntag left into temp.
2548 __ sra(TMP, right, kSmiTagSize); // SmiUntag right into TMP. 2555 __ sra(TMP, right, kSmiTagSize); // SmiUntag right into TMP.
2549 __ div(temp, TMP); 2556 __ div(temp, TMP);
2550 __ mflo(result); 2557 __ mflo(result);
2551 // Check the corner case of dividing the 'MIN_SMI' with -1, in which 2558 // Check the corner case of dividing the 'MIN_SMI' with -1, in which
2552 // case we cannot tag the result. 2559 // case we cannot tag the result.
2553 __ BranchEqual(result, 0x40000000, deopt); 2560 __ BranchEqual(result, 0x40000000, deopt);
2554 __ SmiTag(result); 2561 __ SmiTag(result);
2555 break; 2562 break;
2556 } 2563 }
2564 case Token::kMOD: {
2565 // Handle divide by zero in runtime.
2566 __ beq(right, ZR, deopt);
2567 Register temp = locs()->temp(0).reg();
2568 __ sra(temp, left, kSmiTagSize); // SmiUntag left into temp.
2569 __ sra(TMP, right, kSmiTagSize); // SmiUntag right into TMP.
2570 __ div(temp, TMP);
2571 __ mfhi(result);
2572 // res = left % right;
2573 // if (res < 0) {
2574 // if (right < 0) {
2575 // res = res - right;
2576 // } else {
2577 // res = res + right;
2578 // }
2579 // }
2580 Label done, subtract;
2581 __ bgez(result, &done);
2582 __ bltz(right, &subtract);
2583 __ addu(result, result, TMP);
2584 __ b(&done);
2585 __ Bind(&subtract);
2586 __ subu(result, result, TMP);
2587 __ Bind(&done);
2588 __ SmiTag(result);
2589 break;
2590 }
2557 case Token::kSHR: { 2591 case Token::kSHR: {
2558 Register temp = locs()->temp(0).reg(); 2592 Register temp = locs()->temp(0).reg();
2559 if (CanDeoptimize()) { 2593 if (CanDeoptimize()) {
2560 __ bltz(right, deopt); 2594 __ bltz(right, deopt);
2561 } 2595 }
2562 __ sra(temp, right, kSmiTagSize); // SmiUntag right into temp. 2596 __ sra(temp, right, kSmiTagSize); // SmiUntag right into temp.
2563 // sra operation masks the count to 5 bits. 2597 // sra operation masks the count to 5 bits.
2564 const intptr_t kCountLimit = 0x1F; 2598 const intptr_t kCountLimit = 0x1F;
2565 Range* right_range = this->right()->definition()->range(); 2599 Range* right_range = this->right()->definition()->range();
2566 if ((right_range == NULL) || 2600 if ((right_range == NULL) ||
2567 !right_range->IsWithin(RangeBoundary::kMinusInfinity, kCountLimit)) { 2601 !right_range->IsWithin(RangeBoundary::kMinusInfinity, kCountLimit)) {
2568 Label ok; 2602 Label ok;
2569 __ BranchSignedLessEqual(temp, kCountLimit, &ok); 2603 __ BranchSignedLessEqual(temp, kCountLimit, &ok);
2570 __ LoadImmediate(temp, kCountLimit); 2604 __ LoadImmediate(temp, kCountLimit);
2571 __ Bind(&ok); 2605 __ Bind(&ok);
2572 } 2606 }
2573 2607
2574 __ sra(CMPRES1, left, kSmiTagSize); // SmiUntag left into CMPRES1. 2608 __ sra(CMPRES1, left, kSmiTagSize); // SmiUntag left into CMPRES1.
2575 __ srav(result, CMPRES1, temp); 2609 __ srav(result, CMPRES1, temp);
2576 __ SmiTag(result); 2610 __ SmiTag(result);
2577 break; 2611 break;
2578 } 2612 }
2579 case Token::kDIV: { 2613 case Token::kDIV: {
2580 // Dispatches to 'Double./'. 2614 // Dispatches to 'Double./'.
2581 // TODO(srdjan): Implement as conversion to double and double division. 2615 // TODO(srdjan): Implement as conversion to double and double division.
2582 UNREACHABLE(); 2616 UNREACHABLE();
2583 break; 2617 break;
2584 } 2618 }
2585 case Token::kMOD: {
2586 // TODO(srdjan): Implement.
2587 UNREACHABLE();
2588 break;
2589 }
2590 case Token::kOR: 2619 case Token::kOR:
2591 case Token::kAND: { 2620 case Token::kAND: {
2592 // Flow graph builder has dissected this operation to guarantee correct 2621 // Flow graph builder has dissected this operation to guarantee correct
2593 // behavior (short-circuit evaluation). 2622 // behavior (short-circuit evaluation).
2594 UNREACHABLE(); 2623 UNREACHABLE();
2595 break; 2624 break;
2596 } 2625 }
2597 default: 2626 default:
2598 UNREACHABLE(); 2627 UNREACHABLE();
2599 break; 2628 break;
(...skipping 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after
3927 compiler->GenerateCall(token_pos(), 3956 compiler->GenerateCall(token_pos(),
3928 &label, 3957 &label,
3929 PcDescriptors::kOther, 3958 PcDescriptors::kOther,
3930 locs()); 3959 locs());
3931 __ Drop(2); // Discard type arguments and receiver. 3960 __ Drop(2); // Discard type arguments and receiver.
3932 } 3961 }
3933 3962
3934 } // namespace dart 3963 } // namespace dart
3935 3964
3936 #endif // defined TARGET_ARCH_MIPS 3965 #endif // defined TARGET_ARCH_MIPS
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698