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

Unified Diff: runtime/vm/intermediate_language_x64.cc

Issue 81623003: Use range information to omit checks in TRUNCDIV/MOD operations. (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_x64.cc
===================================================================
--- runtime/vm/intermediate_language_x64.cc (revision 30543)
+++ runtime/vm/intermediate_language_x64.cc (working copy)
@@ -2391,6 +2391,7 @@
// if locs()->in(1).IsRegister.
Register right = locs()->in(1).reg();
+ Range* right_range = this->right()->definition()->range();
switch (op_kind()) {
case Token::kADD: {
__ addq(left, right);
@@ -2431,11 +2432,11 @@
ASSERT((right != RDX) && (right != RAX));
ASSERT(temp == RDX);
ASSERT(result == RAX);
-
- // Handle divide by zero in runtime.
- __ testq(right, right);
- __ j(ZERO, deopt);
-
+ if ((right_range == NULL) || right_range->IsWithin(0, 0)) {
+ // Handle divide by zero in runtime.
+ __ testq(right, right);
+ __ j(ZERO, deopt);
+ }
// Check if both operands fit into 32bits as idiv with 64bit operands
// requires twice as many cycles and has much higher latency.
// We are checking this before untagging them to avoid corner case
@@ -2478,9 +2479,11 @@
ASSERT((right != RDX) && (right != RAX));
ASSERT(temp == RAX);
ASSERT(result == RDX);
- // Handle divide by zero in runtime.
- __ testq(right, right);
- __ j(ZERO, deopt);
+ if ((right_range == NULL) || right_range->IsWithin(0, 0)) {
+ // Handle divide by zero in runtime.
+ __ testq(right, right);
+ __ j(ZERO, deopt);
+ }
// Check if both operands fit into 32bits as idiv with 64bit operands
// requires twice as many cycles and has much higher latency.
// We are checking this before untagging them to avoid corner case
@@ -2517,16 +2520,25 @@
// res = res + right;
// }
// }
- Label subtract, all_done;
+ Label all_done;
__ cmpq(result, Immediate(0));
__ j(GREATER_EQUAL, &all_done, Assembler::kNearJump);
// Result is negative, adjust it.
- __ cmpq(right, Immediate(0));
- __ j(LESS, &subtract, Assembler::kNearJump);
- __ addq(result, right);
- __ jmp(&all_done, Assembler::kNearJump);
- __ Bind(&subtract);
- __ subq(result, right);
+ if ((right_range == NULL) || right_range->IsWithin(-1, 1)) {
+ Label subtract;
+ __ cmpq(right, Immediate(0));
+ __ j(LESS, &subtract, Assembler::kNearJump);
+ __ addq(result, right);
+ __ jmp(&all_done, Assembler::kNearJump);
+ __ Bind(&subtract);
+ __ subq(result, right);
+ } else if (right_range->IsWithin(0, RangeBoundary::kPlusInfinity)) {
+ // Right is positive.
+ __ addq(result, right);
+ } else {
+ // Right is negative.
+ __ subq(result, right);
+ }
__ Bind(&all_done);
__ SmiTag(result);
break;
@@ -2539,7 +2551,6 @@
__ SmiUntag(right);
// sarq operation masks the count to 6 bits.
const intptr_t kCountLimit = 0x3F;
- Range* right_range = this->right()->definition()->range();
if ((right_range == NULL) ||
!right_range->IsWithin(RangeBoundary::kMinusInfinity, kCountLimit)) {
__ CompareImmediate(right, Immediate(kCountLimit), PP);
@@ -4076,9 +4087,13 @@
ASSERT((right != RDX) && (right != RAX));
ASSERT(temp == RDX);
ASSERT((result != RDX) && (result != RAX));
- // Handle divide by zero in runtime.
- __ testq(right, right);
- __ j(ZERO, deopt);
+
+ Range* right_range = InputAt(1)->definition()->range();
+ if ((right_range == NULL) || right_range->IsWithin(0, 0)) {
+ // Handle divide by zero in runtime.
+ __ testq(right, right);
+ __ j(ZERO, deopt);
+ }
// Check if both operands fit into 32bits as idiv with 64bit operands
// requires twice as many cycles and has much higher latency.
// We are checking this before untagging them to avoid corner case
@@ -4121,16 +4136,25 @@
// res = res + right;
// }
// }
- Label subtract, all_done;
+ Label all_done;
__ cmpq(RDX, Immediate(0));
__ j(GREATER_EQUAL, &all_done, Assembler::kNearJump);
// Result is negative, adjust it.
- __ cmpq(right, Immediate(0));
- __ j(LESS, &subtract, Assembler::kNearJump);
- __ addq(RDX, right);
- __ jmp(&all_done, Assembler::kNearJump);
- __ Bind(&subtract);
- __ subq(RDX, right);
+ if ((right_range == NULL) || right_range->IsWithin(-1, 1)) {
+ Label subtract;
+ __ cmpq(right, Immediate(0));
+ __ j(LESS, &subtract, Assembler::kNearJump);
+ __ addq(RDX, right);
+ __ jmp(&all_done, Assembler::kNearJump);
+ __ Bind(&subtract);
+ __ subq(RDX, right);
+ } else if (right_range->IsWithin(0, RangeBoundary::kPlusInfinity)) {
+ // Right is positive.
+ __ addq(RDX, right);
+ } else {
+ // Right is negative.
+ __ subq(RDX, right);
+ }
__ Bind(&all_done);
__ SmiTag(result);
« runtime/vm/intermediate_language_ia32.cc ('K') | « runtime/vm/intermediate_language_mips.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698