OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved.7 | 1 // Copyright 2012 the V8 project authors. All rights reserved.7 |
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 1710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1721 DeoptimizeIf(al, instr); | 1721 DeoptimizeIf(al, instr); |
1722 __ bind(&no_overflow_label); | 1722 __ bind(&no_overflow_label); |
1723 } | 1723 } |
1724 } | 1724 } |
1725 | 1725 |
1726 | 1726 |
1727 void LCodeGen::DoMathMinMax(LMathMinMax* instr) { | 1727 void LCodeGen::DoMathMinMax(LMathMinMax* instr) { |
1728 LOperand* left = instr->left(); | 1728 LOperand* left = instr->left(); |
1729 LOperand* right = instr->right(); | 1729 LOperand* right = instr->right(); |
1730 HMathMinMax::Operation operation = instr->hydrogen()->operation(); | 1730 HMathMinMax::Operation operation = instr->hydrogen()->operation(); |
1731 Condition condition = (operation == HMathMinMax::kMathMin) ? le : ge; | 1731 Register scratch = scratch1(); |
1732 if (instr->hydrogen()->representation().IsSmiOrInteger32()) { | 1732 if (instr->hydrogen()->representation().IsSmiOrInteger32()) { |
| 1733 Condition condition = (operation == HMathMinMax::kMathMin) ? le : ge; |
1733 Register left_reg = ToRegister(left); | 1734 Register left_reg = ToRegister(left); |
1734 Register right_reg = EmitLoadRegister(right, scratch0()); | 1735 Register right_reg = EmitLoadRegister(right, scratch0()); |
1735 Register result_reg = ToRegister(instr->result()); | 1736 Register result_reg = ToRegister(instr->result()); |
1736 Label return_right, done; | 1737 Label return_right, done; |
1737 Register scratch = scratch1(); | |
1738 __ Slt(scratch, left_reg, Operand(right_reg)); | 1738 __ Slt(scratch, left_reg, Operand(right_reg)); |
1739 if (condition == ge) { | 1739 if (condition == ge) { |
1740 __ Movz(result_reg, left_reg, scratch); | 1740 __ Movz(result_reg, left_reg, scratch); |
1741 __ Movn(result_reg, right_reg, scratch); | 1741 __ Movn(result_reg, right_reg, scratch); |
1742 } else { | 1742 } else { |
1743 DCHECK(condition == le); | 1743 DCHECK(condition == le); |
1744 __ Movn(result_reg, left_reg, scratch); | 1744 __ Movn(result_reg, left_reg, scratch); |
1745 __ Movz(result_reg, right_reg, scratch); | 1745 __ Movz(result_reg, right_reg, scratch); |
1746 } | 1746 } |
1747 } else { | 1747 } else { |
1748 DCHECK(instr->hydrogen()->representation().IsDouble()); | 1748 DCHECK(instr->hydrogen()->representation().IsDouble()); |
1749 FPURegister left_reg = ToDoubleRegister(left); | 1749 FPURegister left_reg = ToDoubleRegister(left); |
1750 FPURegister right_reg = ToDoubleRegister(right); | 1750 FPURegister right_reg = ToDoubleRegister(right); |
1751 FPURegister result_reg = ToDoubleRegister(instr->result()); | 1751 FPURegister result_reg = ToDoubleRegister(instr->result()); |
1752 Label check_nan_left, check_zero, return_left, return_right, done; | 1752 Label nan, done; |
1753 __ BranchF(&check_zero, &check_nan_left, eq, left_reg, right_reg); | 1753 if (operation == HMathMinMax::kMathMax) { |
1754 __ BranchF(&return_left, NULL, condition, left_reg, right_reg); | 1754 __ MaxNaNCheck_d(result_reg, left_reg, right_reg, &nan); |
1755 __ Branch(&return_right); | |
1756 | |
1757 __ bind(&check_zero); | |
1758 // left == right != 0. | |
1759 __ BranchF(&return_left, NULL, ne, left_reg, kDoubleRegZero); | |
1760 // At this point, both left and right are either 0 or -0. | |
1761 if (operation == HMathMinMax::kMathMin) { | |
1762 // The algorithm is: -((-L) + (-R)), which in case of L and R being | |
1763 // different registers is most efficiently expressed as -((-L) - R). | |
1764 __ neg_d(left_reg, left_reg); | |
1765 if (left_reg.is(right_reg)) { | |
1766 __ add_d(result_reg, left_reg, right_reg); | |
1767 } else { | |
1768 __ sub_d(result_reg, left_reg, right_reg); | |
1769 } | |
1770 __ neg_d(result_reg, result_reg); | |
1771 } else { | 1755 } else { |
1772 __ add_d(result_reg, left_reg, right_reg); | 1756 DCHECK(operation == HMathMinMax::kMathMin); |
| 1757 __ MinNaNCheck_d(result_reg, left_reg, right_reg, &nan); |
1773 } | 1758 } |
1774 __ Branch(&done); | 1759 __ Branch(&done); |
1775 | 1760 |
1776 __ bind(&check_nan_left); | 1761 __ bind(&nan); |
1777 // left == NaN. | 1762 __ LoadRoot(scratch, Heap::kNanValueRootIndex); |
1778 __ BranchF(NULL, &return_left, eq, left_reg, left_reg); | 1763 __ ldc1(result_reg, FieldMemOperand(scratch, HeapNumber::kValueOffset)); |
1779 __ bind(&return_right); | |
1780 if (!right_reg.is(result_reg)) { | |
1781 __ mov_d(result_reg, right_reg); | |
1782 } | |
1783 __ Branch(&done); | |
1784 | 1764 |
1785 __ bind(&return_left); | |
1786 if (!left_reg.is(result_reg)) { | |
1787 __ mov_d(result_reg, left_reg); | |
1788 } | |
1789 __ bind(&done); | 1765 __ bind(&done); |
1790 } | 1766 } |
1791 } | 1767 } |
1792 | 1768 |
1793 | 1769 |
1794 void LCodeGen::DoArithmeticD(LArithmeticD* instr) { | 1770 void LCodeGen::DoArithmeticD(LArithmeticD* instr) { |
1795 DoubleRegister left = ToDoubleRegister(instr->left()); | 1771 DoubleRegister left = ToDoubleRegister(instr->left()); |
1796 DoubleRegister right = ToDoubleRegister(instr->right()); | 1772 DoubleRegister right = ToDoubleRegister(instr->right()); |
1797 DoubleRegister result = ToDoubleRegister(instr->result()); | 1773 DoubleRegister result = ToDoubleRegister(instr->result()); |
1798 switch (instr->op()) { | 1774 switch (instr->op()) { |
(...skipping 3763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5562 __ lw(result, FieldMemOperand(scratch, | 5538 __ lw(result, FieldMemOperand(scratch, |
5563 FixedArray::kHeaderSize - kPointerSize)); | 5539 FixedArray::kHeaderSize - kPointerSize)); |
5564 __ bind(deferred->exit()); | 5540 __ bind(deferred->exit()); |
5565 __ bind(&done); | 5541 __ bind(&done); |
5566 } | 5542 } |
5567 | 5543 |
5568 #undef __ | 5544 #undef __ |
5569 | 5545 |
5570 } // namespace internal | 5546 } // namespace internal |
5571 } // namespace v8 | 5547 } // namespace v8 |
OLD | NEW |