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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/intermediate_language_mips.cc
===================================================================
--- runtime/vm/intermediate_language_mips.cc (revision 30005)
+++ runtime/vm/intermediate_language_mips.cc (working copy)
@@ -2314,6 +2314,13 @@
summary->set_out(Location::RequiresRegister());
return summary;
}
+ if (op_kind() == Token::kMOD) {
+ summary->set_in(0, Location::RequiresRegister());
+ summary->set_in(1, Location::RequiresRegister());
+ summary->AddTemp(Location::RequiresRegister());
+ summary->set_out(Location::RequiresRegister());
+ return summary;
+ }
summary->set_in(0, Location::RequiresRegister());
summary->set_in(1, Location::RegisterOrSmiConstant(right()));
if (((op_kind() == Token::kSHL) && !is_truncating()) ||
@@ -2554,6 +2561,33 @@
__ SmiTag(result);
break;
}
+ case Token::kMOD: {
+ // Handle divide by zero in runtime.
+ __ beq(right, ZR, deopt);
+ Register temp = locs()->temp(0).reg();
+ __ sra(temp, left, kSmiTagSize); // SmiUntag left into temp.
+ __ sra(TMP, right, kSmiTagSize); // SmiUntag right into TMP.
+ __ div(temp, TMP);
+ __ mfhi(result);
+ // res = left % right;
+ // if (res < 0) {
+ // if (right < 0) {
+ // res = res - right;
+ // } else {
+ // res = res + right;
+ // }
+ // }
+ Label done, subtract;
+ __ bgez(result, &done);
+ __ bltz(right, &subtract);
+ __ addu(result, result, TMP);
+ __ b(&done);
+ __ Bind(&subtract);
+ __ subu(result, result, TMP);
+ __ Bind(&done);
+ __ SmiTag(result);
+ break;
+ }
case Token::kSHR: {
Register temp = locs()->temp(0).reg();
if (CanDeoptimize()) {
@@ -2582,11 +2616,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

Powered by Google App Engine
This is Rietveld 408576698