OLD | NEW |
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 1538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1549 | 1549 |
1550 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) { | 1550 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) { |
1551 __ mov(eax, edx); | 1551 __ mov(eax, edx); |
1552 __ imul(eax, eax, divisor); | 1552 __ imul(eax, eax, divisor); |
1553 __ sub(eax, dividend); | 1553 __ sub(eax, dividend); |
1554 DeoptimizeIf(not_equal, instr->environment()); | 1554 DeoptimizeIf(not_equal, instr->environment()); |
1555 } | 1555 } |
1556 } | 1556 } |
1557 | 1557 |
1558 | 1558 |
| 1559 // TODO(svenpanne) Refactor this to avoid code duplication with DoFlooringDivI. |
1559 void LCodeGen::DoDivI(LDivI* instr) { | 1560 void LCodeGen::DoDivI(LDivI* instr) { |
1560 HBinaryOperation* hdiv = instr->hydrogen(); | 1561 HBinaryOperation* hdiv = instr->hydrogen(); |
1561 Register dividend = ToRegister(instr->left()); | 1562 Register dividend = ToRegister(instr->dividend()); |
1562 Register divisor = ToRegister(instr->right()); | 1563 Register divisor = ToRegister(instr->divisor()); |
1563 Register remainder = ToRegister(instr->temp()); | 1564 Register remainder = ToRegister(instr->temp()); |
1564 Register result = ToRegister(instr->result()); | 1565 Register result = ToRegister(instr->result()); |
1565 ASSERT(dividend.is(eax)); | 1566 ASSERT(dividend.is(eax)); |
1566 ASSERT(remainder.is(edx)); | 1567 ASSERT(remainder.is(edx)); |
1567 ASSERT(result.is(eax)); | 1568 ASSERT(result.is(eax)); |
1568 ASSERT(!divisor.is(eax)); | 1569 ASSERT(!divisor.is(eax)); |
1569 ASSERT(!divisor.is(edx)); | 1570 ASSERT(!divisor.is(edx)); |
1570 | 1571 |
1571 // Check for x / 0. | 1572 // Check for x / 0. |
1572 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { | 1573 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { |
(...skipping 18 matching lines...) Expand all Loading... |
1591 __ j(not_zero, ÷nd_not_min_int, Label::kNear); | 1592 __ j(not_zero, ÷nd_not_min_int, Label::kNear); |
1592 __ cmp(divisor, -1); | 1593 __ cmp(divisor, -1); |
1593 DeoptimizeIf(zero, instr->environment()); | 1594 DeoptimizeIf(zero, instr->environment()); |
1594 __ bind(÷nd_not_min_int); | 1595 __ bind(÷nd_not_min_int); |
1595 } | 1596 } |
1596 | 1597 |
1597 // Sign extend to edx (= remainder). | 1598 // Sign extend to edx (= remainder). |
1598 __ cdq(); | 1599 __ cdq(); |
1599 __ idiv(divisor); | 1600 __ idiv(divisor); |
1600 | 1601 |
1601 if (hdiv->IsMathFloorOfDiv()) { | 1602 if (!hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) { |
1602 Label done; | |
1603 __ test(remainder, remainder); | |
1604 __ j(zero, &done, Label::kNear); | |
1605 __ xor_(remainder, divisor); | |
1606 __ sar(remainder, 31); | |
1607 __ add(result, remainder); | |
1608 __ bind(&done); | |
1609 } else if (!hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) { | |
1610 // Deoptimize if remainder is not 0. | 1603 // Deoptimize if remainder is not 0. |
1611 __ test(remainder, remainder); | 1604 __ test(remainder, remainder); |
1612 DeoptimizeIf(not_zero, instr->environment()); | 1605 DeoptimizeIf(not_zero, instr->environment()); |
1613 } | 1606 } |
1614 } | 1607 } |
1615 | 1608 |
1616 | 1609 |
1617 void LCodeGen::DoFlooringDivByPowerOf2I(LFlooringDivByPowerOf2I* instr) { | 1610 void LCodeGen::DoFlooringDivByPowerOf2I(LFlooringDivByPowerOf2I* instr) { |
1618 Register dividend = ToRegister(instr->dividend()); | 1611 Register dividend = ToRegister(instr->dividend()); |
1619 int32_t divisor = instr->divisor(); | 1612 int32_t divisor = instr->divisor(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1689 __ jmp(&done, Label::kNear); | 1682 __ jmp(&done, Label::kNear); |
1690 __ bind(&needs_adjustment); | 1683 __ bind(&needs_adjustment); |
1691 __ lea(temp, Operand(dividend, divisor > 0 ? 1 : -1)); | 1684 __ lea(temp, Operand(dividend, divisor > 0 ? 1 : -1)); |
1692 __ TruncatingDiv(temp, Abs(divisor)); | 1685 __ TruncatingDiv(temp, Abs(divisor)); |
1693 if (divisor < 0) __ neg(edx); | 1686 if (divisor < 0) __ neg(edx); |
1694 __ dec(edx); | 1687 __ dec(edx); |
1695 __ bind(&done); | 1688 __ bind(&done); |
1696 } | 1689 } |
1697 | 1690 |
1698 | 1691 |
| 1692 // TODO(svenpanne) Refactor this to avoid code duplication with DoDivI. |
| 1693 void LCodeGen::DoFlooringDivI(LFlooringDivI* instr) { |
| 1694 HBinaryOperation* hdiv = instr->hydrogen(); |
| 1695 Register dividend = ToRegister(instr->dividend()); |
| 1696 Register divisor = ToRegister(instr->divisor()); |
| 1697 Register remainder = ToRegister(instr->temp()); |
| 1698 Register result = ToRegister(instr->result()); |
| 1699 ASSERT(dividend.is(eax)); |
| 1700 ASSERT(remainder.is(edx)); |
| 1701 ASSERT(result.is(eax)); |
| 1702 ASSERT(!divisor.is(eax)); |
| 1703 ASSERT(!divisor.is(edx)); |
| 1704 |
| 1705 // Check for x / 0. |
| 1706 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { |
| 1707 __ test(divisor, divisor); |
| 1708 DeoptimizeIf(zero, instr->environment()); |
| 1709 } |
| 1710 |
| 1711 // Check for (0 / -x) that will produce negative zero. |
| 1712 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1713 Label dividend_not_zero; |
| 1714 __ test(dividend, dividend); |
| 1715 __ j(not_zero, ÷nd_not_zero, Label::kNear); |
| 1716 __ test(divisor, divisor); |
| 1717 DeoptimizeIf(sign, instr->environment()); |
| 1718 __ bind(÷nd_not_zero); |
| 1719 } |
| 1720 |
| 1721 // Check for (kMinInt / -1). |
| 1722 if (hdiv->CheckFlag(HValue::kCanOverflow)) { |
| 1723 Label dividend_not_min_int; |
| 1724 __ cmp(dividend, kMinInt); |
| 1725 __ j(not_zero, ÷nd_not_min_int, Label::kNear); |
| 1726 __ cmp(divisor, -1); |
| 1727 DeoptimizeIf(zero, instr->environment()); |
| 1728 __ bind(÷nd_not_min_int); |
| 1729 } |
| 1730 |
| 1731 // Sign extend to edx (= remainder). |
| 1732 __ cdq(); |
| 1733 __ idiv(divisor); |
| 1734 |
| 1735 Label done; |
| 1736 __ test(remainder, remainder); |
| 1737 __ j(zero, &done, Label::kNear); |
| 1738 __ xor_(remainder, divisor); |
| 1739 __ sar(remainder, 31); |
| 1740 __ add(result, remainder); |
| 1741 __ bind(&done); |
| 1742 } |
| 1743 |
| 1744 |
1699 void LCodeGen::DoMulI(LMulI* instr) { | 1745 void LCodeGen::DoMulI(LMulI* instr) { |
1700 Register left = ToRegister(instr->left()); | 1746 Register left = ToRegister(instr->left()); |
1701 LOperand* right = instr->right(); | 1747 LOperand* right = instr->right(); |
1702 | 1748 |
1703 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1749 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
1704 __ mov(ToRegister(instr->temp()), left); | 1750 __ mov(ToRegister(instr->temp()), left); |
1705 } | 1751 } |
1706 | 1752 |
1707 if (right->IsConstantOperand()) { | 1753 if (right->IsConstantOperand()) { |
1708 // Try strength reductions on the multiplication. | 1754 // Try strength reductions on the multiplication. |
(...skipping 4683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6392 __ bind(deferred->exit()); | 6438 __ bind(deferred->exit()); |
6393 __ bind(&done); | 6439 __ bind(&done); |
6394 } | 6440 } |
6395 | 6441 |
6396 | 6442 |
6397 #undef __ | 6443 #undef __ |
6398 | 6444 |
6399 } } // namespace v8::internal | 6445 } } // namespace v8::internal |
6400 | 6446 |
6401 #endif // V8_TARGET_ARCH_IA32 | 6447 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |