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

Unified Diff: runtime/vm/intrinsifier_x64.cc

Issue 10663006: Expand ia32 intrinsic for integer modulo, implement it for x64. Next step will be to emit it direct… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 months 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/intrinsifier_ia32.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/intrinsifier_x64.cc
===================================================================
--- runtime/vm/intrinsifier_x64.cc (revision 9046)
+++ runtime/vm/intrinsifier_x64.cc (working copy)
@@ -310,6 +310,17 @@
}
+// Tests if two top most arguments are smis, jumps to label not_smi if not.
+// Topmost argument is in RAX.
+static void TestBothArgumentsSmis(Assembler* assembler, Label* not_smi) {
+ __ movq(RAX, Address(RSP, + 1 * kWordSize));
+ __ movq(RCX, Address(RSP, + 2 * kWordSize));
+ __ orq(RCX, RAX);
+ __ testq(RCX, Immediate(kSmiTagMask));
+ __ j(NOT_ZERO, not_smi, Assembler::kNearJump);
+}
+
+
bool Intrinsifier::Integer_addFromInteger(Assembler* assembler) {
return false;
}
@@ -342,6 +353,35 @@
bool Intrinsifier::Integer_modulo(Assembler* assembler) {
+ Label fall_through, return_zero, try_modulo;
+ TestBothArgumentsSmis(assembler, &fall_through);
+ // RAX: right argument (divisor)
+ // Check if modulo by zero -> exception thrown in main function.
+ __ cmpq(RAX, Immediate(0));
+ __ j(EQUAL, &fall_through, Assembler::kNearJump);
+ __ movq(RCX, Address(RSP, + 2 * kWordSize)); // Left argument (dividend).
+ __ cmpq(RCX, Immediate(0));
+ __ j(LESS, &fall_through, Assembler::kNearJump);
+ __ cmpq(RCX, RAX);
+ __ j(EQUAL, &return_zero, Assembler::kNearJump);
+ __ j(GREATER, &try_modulo, Assembler::kNearJump);
+ __ movq(RAX, RCX); // Return dividend as it is smaller than divisor.
+ __ ret();
+ __ Bind(&return_zero);
+ __ xorq(RAX, RAX); // Return zero.
+ __ ret();
+ __ Bind(&try_modulo);
+ // RAX: right (non-null divisor).
+ __ movq(RCX, RAX);
+ __ SmiUntag(RCX);
+ __ movq(RAX, Address(RSP, + 2 * kWordSize)); // Left argument (dividend).
+ __ SmiUntag(RAX);
+ __ cqo();
+ __ idivq(RCX);
+ __ movq(RAX, RDX);
+ __ SmiTag(RAX);
+ __ ret();
+ __ Bind(&fall_through);
return false;
}
« no previous file with comments | « runtime/vm/intrinsifier_ia32.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698