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

Unified Diff: runtime/vm/intermediate_language_mips.cc

Issue 68663003: Merge TRUNCDIV and MOD into TRUNCDIV_MOD single 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 30236)
+++ runtime/vm/intermediate_language_mips.cc (working copy)
@@ -2393,6 +2393,15 @@
summary->set_out(Location::RequiresRegister());
return summary;
}
+ if (op_kind() == Token::kTRUNCDIVMOD) {
+ summary->set_in(0, Location::RequiresRegister());
+ summary->set_in(1, Location::RequiresRegister());
+ summary->AddTemp(Location::RequiresRegister());
+ summary->AddTemp(Location::RequiresRegister()); // result_div.
+ summary->AddTemp(Location::RequiresRegister()); // result_mod.
+ 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()) ||
@@ -2660,6 +2669,51 @@
__ SmiTag(result);
break;
}
+ case Token::kTRUNCDIVMOD: {
+ Register temp = locs()->temp(0).reg();
+ Register result_div = locs()->temp(1).reg();
+ Register result_mod = locs()->temp(2).reg();
+ // Handle divide by zero in runtime.
+ __ beq(right, ZR, deopt);
+ __ sra(temp, left, kSmiTagSize); // SmiUntag left into temp.
+ __ sra(TMP, right, kSmiTagSize); // SmiUntag right into TMP.
+ __ div(temp, TMP);
+ __ mflo(result_div);
+ __ mfhi(result_mod);
+ // Check the corner case of dividing the 'MIN_SMI' with -1, in which
+ // case we cannot tag the result.
+ __ BranchEqual(result_div, 0x40000000, deopt);
+ // res = left % right;
+ // if (res < 0) {
+ // if (right < 0) {
+ // res = res - right;
+ // } else {
+ // res = res + right;
+ // }
+ // }
+ Label done, subtract;
+ __ bgez(result_mod, &done);
+ __ bltz(right, &subtract);
+ __ addu(result_mod, result_mod, TMP);
+ __ b(&done);
+ __ Bind(&subtract);
+ __ subu(result_mod, result_mod, TMP);
+ __ Bind(&done);
+
+ __ SmiTag(result_div);
+ __ SmiTag(result_mod);
+ __ LoadObject(result, Array::ZoneHandle(Array::New(2, Heap::kOld)));
+ // Note that index is expected smi-tagged, (i.e, times 2) for all arrays.
+ // [0]: divide resut, [1]: mod result.
+ __ LoadImmediate(temp,
+ FlowGraphCompiler::DataOffsetFor(kArrayCid) - kHeapObjectTag);
+ __ addu(temp, result, temp);
+ Address div_result_address(temp, 0);
+ Address mod_result_address(temp, kWordSize);
+ __ StoreIntoObjectNoBarrier(result, div_result_address, result_div);
+ __ StoreIntoObjectNoBarrier(result, mod_result_address, result_mod);
+ break;
+ }
case Token::kSHR: {
Register temp = locs()->temp(0).reg();
if (CanDeoptimize()) {

Powered by Google App Engine
This is Rietveld 408576698