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

Unified Diff: src/ia32/lithium-codegen-ia32.cc

Issue 189963005: Revert "Handle non-power-of-2 divisors in division-like operations", "A64 tweaks for division-like … (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 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 | « src/assembler.cc ('k') | src/ia32/lithium-ia32.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ia32/lithium-codegen-ia32.cc
diff --git a/src/ia32/lithium-codegen-ia32.cc b/src/ia32/lithium-codegen-ia32.cc
index 5f5e3f3dde3862939507efcf7d1f0ec96aee182e..827add3738e591f612f3e08c8cb7a3eab2af1d40 100644
--- a/src/ia32/lithium-codegen-ia32.cc
+++ b/src/ia32/lithium-codegen-ia32.cc
@@ -1401,34 +1401,6 @@ void LCodeGen::DoModByPowerOf2I(LModByPowerOf2I* instr) {
}
-void LCodeGen::DoModByConstI(LModByConstI* instr) {
- Register dividend = ToRegister(instr->dividend());
- int32_t divisor = instr->divisor();
- ASSERT(ToRegister(instr->result()).is(eax));
-
- if (divisor == 0) {
- DeoptimizeIf(no_condition, instr->environment());
- return;
- }
-
- __ FlooringDiv(dividend, Abs(divisor));
- __ imul(edx, edx, Abs(divisor));
- __ mov(eax, dividend);
- __ sub(eax, edx);
-
- // Check for negative zero.
- HMod* hmod = instr->hydrogen();
- if (hmod->CheckFlag(HValue::kBailoutOnMinusZero) &&
- hmod->left()->CanBeNegative()) {
- Label remainder_not_zero;
- __ j(not_zero, &remainder_not_zero, Label::kNear);
- __ cmp(dividend, Immediate(0));
- DeoptimizeIf(less, instr->environment());
- __ bind(&remainder_not_zero);
- }
-}
-
-
void LCodeGen::DoModI(LModI* instr) {
HMod* hmod = instr->hydrogen();
HValue* left = hmod->left();
@@ -1528,36 +1500,6 @@ void LCodeGen::DoDivByPowerOf2I(LDivByPowerOf2I* instr) {
}
-void LCodeGen::DoDivByConstI(LDivByConstI* instr) {
- Register dividend = ToRegister(instr->dividend());
- int32_t divisor = instr->divisor();
- ASSERT(ToRegister(instr->result()).is(edx));
-
- if (divisor == 0) {
- DeoptimizeIf(no_condition, instr->environment());
- return;
- }
-
- // Check for (0 / -x) that will produce negative zero.
- HDiv* hdiv = instr->hydrogen();
- if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) &&
- hdiv->left()->RangeCanInclude(0) && divisor < 0) {
- __ test(dividend, dividend);
- DeoptimizeIf(zero, instr->environment());
- }
-
- __ FlooringDiv(dividend, Abs(divisor));
- if (divisor < 0) __ neg(edx);
-
- if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) {
- __ mov(eax, edx);
- __ imul(eax, eax, divisor);
- __ sub(eax, dividend);
- DeoptimizeIf(not_equal, instr->environment());
- }
-}
-
-
void LCodeGen::DoDivI(LDivI* instr) {
Register dividend = ToRegister(instr->left());
Register divisor = ToRegister(instr->right());
@@ -1657,6 +1599,8 @@ void LCodeGen::DoFlooringDivByPowerOf2I(LFlooringDivByPowerOf2I* instr) {
void LCodeGen::DoFlooringDivByConstI(LFlooringDivByConstI* instr) {
Register dividend = ToRegister(instr->dividend());
int32_t divisor = instr->divisor();
+ Register scratch = ToRegister(instr->temp());
+ ASSERT(ToRegister(instr->dividend()).is(eax));
ASSERT(ToRegister(instr->result()).is(edx));
if (divisor == 0) {
@@ -1664,15 +1608,52 @@ void LCodeGen::DoFlooringDivByConstI(LFlooringDivByConstI* instr) {
return;
}
- // Check for (0 / -x) that will produce negative zero.
- HMathFloorOfDiv* hdiv = instr->hydrogen();
- if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) &&
- hdiv->left()->RangeCanInclude(0) && divisor < 0) {
+ // Find b which: 2^b < divisor_abs < 2^(b+1).
+ uint32_t divisor_abs = abs(divisor);
+ unsigned b = 31 - CompilerIntrinsics::CountLeadingZeros(divisor_abs);
+ unsigned shift = 32 + b; // Precision +1bit (effectively).
+ double multiplier_f =
+ static_cast<double>(static_cast<uint64_t>(1) << shift) / divisor_abs;
+ int64_t multiplier;
+ if (multiplier_f - std::floor(multiplier_f) < 0.5) {
+ multiplier = static_cast<int64_t>(std::floor(multiplier_f));
+ } else {
+ multiplier = static_cast<int64_t>(std::floor(multiplier_f)) + 1;
+ }
+ // The multiplier is a uint32.
+ ASSERT(multiplier > 0 &&
+ multiplier < (static_cast<int64_t>(1) << 32));
+ __ mov(scratch, dividend);
+ if (divisor < 0 &&
+ instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
__ test(dividend, dividend);
DeoptimizeIf(zero, instr->environment());
}
-
- __ FlooringDiv(dividend, divisor);
+ __ mov(edx, static_cast<int32_t>(multiplier));
+ __ imul(edx);
+ if (static_cast<int32_t>(multiplier) < 0) {
+ __ add(edx, scratch);
+ }
+ Register reg_lo = eax;
+ Register reg_byte_scratch = scratch;
+ if (!reg_byte_scratch.is_byte_register()) {
+ __ xchg(reg_lo, reg_byte_scratch);
+ reg_lo = scratch;
+ reg_byte_scratch = eax;
+ }
+ if (divisor < 0) {
+ __ xor_(reg_byte_scratch, reg_byte_scratch);
+ __ cmp(reg_lo, 0x40000000);
+ __ setcc(above, reg_byte_scratch);
+ __ neg(edx);
+ __ sub(edx, reg_byte_scratch);
+ } else {
+ __ xor_(reg_byte_scratch, reg_byte_scratch);
+ __ cmp(reg_lo, 0xC0000000);
+ __ setcc(above_equal, reg_byte_scratch);
+ __ add(edx, reg_byte_scratch);
+ }
+ __ sar(edx, shift - 32);
}
« no previous file with comments | « src/assembler.cc ('k') | src/ia32/lithium-ia32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698