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

Unified Diff: runtime/vm/intermediate_language_ia32.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/intermediate_language_arm.cc ('k') | runtime/vm/intermediate_language_mips.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/intermediate_language_ia32.cc
===================================================================
--- runtime/vm/intermediate_language_ia32.cc (revision 30070)
+++ runtime/vm/intermediate_language_ia32.cc (working copy)
@@ -2306,6 +2306,17 @@
summary->set_temp(0, Location::RegisterLocation(EDX));
}
return summary;
+ } else if (op_kind() == Token::kMOD) {
+ const intptr_t kNumTemps = 1;
+ LocationSummary* summary =
+ new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
+ // Both inputs must be writable because they will be untagged.
+ summary->set_in(0, Location::RegisterLocation(EDX));
+ summary->set_in(1, Location::WritableRegister());
+ summary->set_out(Location::SameAsFirstInput());
+ // Will be used for sign extension and division.
+ summary->set_temp(0, Location::RegisterLocation(EAX));
+ return summary;
} else if (op_kind() == Token::kSHR) {
const intptr_t kNumTemps = 0;
LocationSummary* summary =
@@ -2551,6 +2562,41 @@
__ SmiTag(result);
break;
}
+ case Token::kMOD: {
+ // Handle divide by zero in runtime.
+ __ testl(right, right);
+ __ j(ZERO, deopt);
+ ASSERT(left == EDX);
+ ASSERT((right != EDX) && (right != EAX));
+ ASSERT(locs()->temp(0).reg() == EAX);
+ ASSERT(result == EDX);
+ __ SmiUntag(left);
+ __ SmiUntag(right);
+ __ movl(EAX, EDX);
+ __ cdq(); // Sign extend EAX -> EDX:EAX.
+ __ idivl(right); // EAX: quotient, EDX: remainder.
+ // res = left % right;
+ // if (res < 0) {
+ // if (right < 0) {
+ // res = res - right;
+ // } else {
+ // res = res + right;
+ // }
+ // }
+ Label subtract, done;
+ __ cmpl(result, Immediate(0));
+ __ j(GREATER_EQUAL, &done, Assembler::kNearJump);
+ // Result is negative, adjust it.
+ __ cmpl(right, Immediate(0));
+ __ j(LESS, &subtract, Assembler::kNearJump);
+ __ addl(result, right);
+ __ jmp(&done, Assembler::kNearJump);
+ __ Bind(&subtract);
+ __ subl(result, right);
+ __ Bind(&done);
+ __ SmiTag(result);
+ break;
+ }
case Token::kSHR: {
if (CanDeoptimize()) {
__ cmpl(right, Immediate(0));
@@ -2580,11 +2626,6 @@
UNREACHABLE();
break;
}
- case Token::kMOD: {
- // TODO(srdjan): Implement.
- UNREACHABLE();
- break;
- }
case Token::kOR:
case Token::kAND: {
// Flow graph builder has dissected this operation to guarantee correct
« no previous file with comments | « runtime/vm/intermediate_language_arm.cc ('k') | runtime/vm/intermediate_language_mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698