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

Unified Diff: runtime/vm/intermediate_language_arm.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_arm.cc
===================================================================
--- runtime/vm/intermediate_language_arm.cc (revision 30005)
+++ runtime/vm/intermediate_language_arm.cc (working copy)
@@ -2239,6 +2239,14 @@
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->AddTemp(Location::RequiresFpuRegister());
+ 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()) ||
@@ -2467,6 +2475,38 @@
__ SmiTag(result);
break;
}
+ case Token::kMOD: {
+ // Handle divide by zero in runtime.
+ __ cmp(right, ShifterOperand(0));
+ __ b(deopt, EQ);
+ Register temp = locs()->temp(0).reg();
+ DRegister dtemp = EvenDRegisterOf(locs()->temp(1).fpu_reg());
+ __ Asr(temp, left, kSmiTagSize); // SmiUntag left into temp.
+ __ Asr(IP, right, kSmiTagSize); // SmiUntag right into IP.
+
+ __ IntegerDivide(result, temp, IP, dtemp, DTMP);
+
+ __ Asr(IP, right, kSmiTagSize); // SmiUntag right into IP.
zra 2013/11/07 16:40:06 IntegerDivide doesn't clobber temp and IP here, so
srdjan 2013/11/07 21:26:10 I think it is safe to assume that IP is not guaran
+ __ mls(result, IP, result, temp); // result <- left - right * result
+ __ SmiTag(result);
+ // res = left % right;
+ // if (res < 0) {
+ // if (right < 0) {
+ // res = res - right;
+ // } else {
+ // res = res + right;
+ // }
+ // }
+ Label done;
+ __ cmp(result, ShifterOperand(0));
+ __ b(&done, GE);
+ // Result is negative, adjust it.
+ __ cmp(right, ShifterOperand(0));
+ __ sub(result, result, ShifterOperand(right), LT);
+ __ add(result, result, ShifterOperand(right), GE);
+ __ Bind(&done);
+ break;
+ }
case Token::kSHR: {
if (CanDeoptimize()) {
__ CompareImmediate(right, 0);
@@ -2493,11 +2533,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