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

Side by Side Diff: src/ia32/lithium-codegen-ia32.cc

Issue 204583002: Implement flooring division by a constant via truncating division by a constant. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/hydrogen-instructions.cc ('k') | src/ia32/lithium-ia32.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1647 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 return; 1658 return;
1659 } 1659 }
1660 1660
1661 // Check for (0 / -x) that will produce negative zero. 1661 // Check for (0 / -x) that will produce negative zero.
1662 HMathFloorOfDiv* hdiv = instr->hydrogen(); 1662 HMathFloorOfDiv* hdiv = instr->hydrogen();
1663 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { 1663 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) {
1664 __ test(dividend, dividend); 1664 __ test(dividend, dividend);
1665 DeoptimizeIf(zero, instr->environment()); 1665 DeoptimizeIf(zero, instr->environment());
1666 } 1666 }
1667 1667
1668 // TODO(svenpanne) Add correction terms. 1668 // Easy case: We need no dynamic check for the dividend and the flooring
1669 __ TruncatingDiv(dividend, divisor); 1669 // division is the same as the truncating division.
1670 if ((divisor > 0 && !hdiv->CheckFlag(HValue::kLeftCanBeNegative)) ||
1671 (divisor < 0 && !hdiv->CheckFlag(HValue::kLeftCanBePositive))) {
1672 __ TruncatingDiv(dividend, Abs(divisor));
1673 if (divisor < 0) __ neg(edx);
1674 return;
1675 }
1676
1677 // In the general case we may need to adjust before and after the truncating
1678 // division to get a flooring division.
1679 Register temp = ToRegister(instr->temp3());
1680 ASSERT(!temp.is(dividend) && !temp.is(eax) && !temp.is(edx));
1681 Label needs_adjustment, done;
1682 __ cmp(dividend, Immediate(0));
1683 __ j(divisor > 0 ? less : greater, &needs_adjustment, Label::kNear);
1684 __ TruncatingDiv(dividend, Abs(divisor));
1685 if (divisor < 0) __ neg(edx);
1686 __ jmp(&done, Label::kNear);
1687 __ bind(&needs_adjustment);
1688 __ lea(temp, Operand(dividend, divisor > 0 ? 1 : -1));
1689 __ TruncatingDiv(temp, Abs(divisor));
1690 if (divisor < 0) __ neg(edx);
1691 __ dec(edx);
1692 __ bind(&done);
1670 } 1693 }
1671 1694
1672 1695
1673 void LCodeGen::DoMulI(LMulI* instr) { 1696 void LCodeGen::DoMulI(LMulI* instr) {
1674 Register left = ToRegister(instr->left()); 1697 Register left = ToRegister(instr->left());
1675 LOperand* right = instr->right(); 1698 LOperand* right = instr->right();
1676 1699
1677 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { 1700 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
1678 __ mov(ToRegister(instr->temp()), left); 1701 __ mov(ToRegister(instr->temp()), left);
1679 } 1702 }
(...skipping 4649 matching lines...) Expand 10 before | Expand all | Expand 10 after
6329 FixedArray::kHeaderSize - kPointerSize)); 6352 FixedArray::kHeaderSize - kPointerSize));
6330 __ bind(&done); 6353 __ bind(&done);
6331 } 6354 }
6332 6355
6333 6356
6334 #undef __ 6357 #undef __
6335 6358
6336 } } // namespace v8::internal 6359 } } // namespace v8::internal
6337 6360
6338 #endif // V8_TARGET_ARCH_IA32 6361 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/hydrogen-instructions.cc ('k') | src/ia32/lithium-ia32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698