OLD | NEW |
---|---|
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/base/adapters.h" | 5 #include "src/base/adapters.h" |
6 #include "src/base/bits.h" | 6 #include "src/base/bits.h" |
7 #include "src/compiler/instruction-selector-impl.h" | 7 #include "src/compiler/instruction-selector-impl.h" |
8 #include "src/compiler/node-matchers.h" | 8 #include "src/compiler/node-matchers.h" |
9 #include "src/compiler/node-properties.h" | 9 #include "src/compiler/node-properties.h" |
10 | 10 |
(...skipping 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1086 if (IsSupported(ARMv7) && m.right().IsInt32Mul() && | 1086 if (IsSupported(ARMv7) && m.right().IsInt32Mul() && |
1087 CanCover(node, m.right().node())) { | 1087 CanCover(node, m.right().node())) { |
1088 Int32BinopMatcher mright(m.right().node()); | 1088 Int32BinopMatcher mright(m.right().node()); |
1089 Emit(kArmMls, g.DefineAsRegister(node), g.UseRegister(mright.left().node()), | 1089 Emit(kArmMls, g.DefineAsRegister(node), g.UseRegister(mright.left().node()), |
1090 g.UseRegister(mright.right().node()), g.UseRegister(m.left().node())); | 1090 g.UseRegister(mright.right().node()), g.UseRegister(m.left().node())); |
1091 return; | 1091 return; |
1092 } | 1092 } |
1093 VisitBinop(this, node, kArmSub, kArmRsb); | 1093 VisitBinop(this, node, kArmSub, kArmRsb); |
1094 } | 1094 } |
1095 | 1095 |
1096 void VisitInt32MulWithOverflowImpl(InstructionSelector* selector, Node* node, | |
Benedikt Meurer
2016/07/12 04:09:28
Put this into an anonymous namespace and remove th
mvstanton
2016/07/12 08:52:49
Done.
| |
1097 FlagsContinuation* cont) { | |
1098 ArmOperandGenerator g(selector); | |
1099 Int32BinopMatcher m(node); | |
1100 InstructionOperand result_operand = g.DefineAsRegister(node); | |
1101 InstructionOperand temp_operand = g.TempRegister(); | |
1102 InstructionOperand outputs[] = {result_operand, temp_operand}; | |
1103 InstructionOperand inputs[] = {g.UseRegister(m.left().node()), | |
1104 g.UseRegister(m.right().node())}; | |
1105 selector->Emit(kArmSmull, 2, outputs, 2, inputs); | |
1106 | |
1107 // result operand needs shift operator. | |
1108 InstructionOperand shift_31 = g.UseImmediate(31); | |
1109 InstructionCode opcode = cont->Encode(kArmCmp) | | |
1110 AddressingModeField::encode(kMode_Operand2_R_ASR_I); | |
1111 if (cont->IsBranch()) { | |
1112 selector->Emit(opcode, g.NoOutput(), temp_operand, result_operand, shift_31, | |
1113 g.Label(cont->true_block()), g.Label(cont->false_block())); | |
1114 } else if (cont->IsDeoptimize()) { | |
1115 InstructionOperand in[] = {temp_operand, result_operand, shift_31}; | |
1116 selector->EmitDeoptimize(opcode, 0, nullptr, 3, in, cont->frame_state()); | |
1117 } else { | |
1118 DCHECK(cont->IsSet()); | |
1119 selector->Emit(opcode, g.DefineAsRegister(cont->result()), temp_operand, | |
1120 result_operand, shift_31); | |
1121 } | |
1122 } | |
1096 | 1123 |
1097 void InstructionSelector::VisitInt32Mul(Node* node) { | 1124 void InstructionSelector::VisitInt32Mul(Node* node) { |
1098 ArmOperandGenerator g(this); | 1125 ArmOperandGenerator g(this); |
1099 Int32BinopMatcher m(node); | 1126 Int32BinopMatcher m(node); |
1100 if (m.right().HasValue() && m.right().Value() > 0) { | 1127 if (m.right().HasValue() && m.right().Value() > 0) { |
1101 int32_t value = m.right().Value(); | 1128 int32_t value = m.right().Value(); |
1102 if (base::bits::IsPowerOfTwo32(value - 1)) { | 1129 if (base::bits::IsPowerOfTwo32(value - 1)) { |
1103 Emit(kArmAdd | AddressingModeField::encode(kMode_Operand2_R_LSL_I), | 1130 Emit(kArmAdd | AddressingModeField::encode(kMode_Operand2_R_LSL_I), |
1104 g.DefineAsRegister(node), g.UseRegister(m.left().node()), | 1131 g.DefineAsRegister(node), g.UseRegister(m.left().node()), |
1105 g.UseRegister(m.left().node()), | 1132 g.UseRegister(m.left().node()), |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1674 Node* const node = value->InputAt(0); | 1701 Node* const node = value->InputAt(0); |
1675 Node* const result = NodeProperties::FindProjection(node, 0); | 1702 Node* const result = NodeProperties::FindProjection(node, 0); |
1676 if (!result || selector->IsDefined(result)) { | 1703 if (!result || selector->IsDefined(result)) { |
1677 switch (node->opcode()) { | 1704 switch (node->opcode()) { |
1678 case IrOpcode::kInt32AddWithOverflow: | 1705 case IrOpcode::kInt32AddWithOverflow: |
1679 cont->OverwriteAndNegateIfEqual(kOverflow); | 1706 cont->OverwriteAndNegateIfEqual(kOverflow); |
1680 return VisitBinop(selector, node, kArmAdd, kArmAdd, cont); | 1707 return VisitBinop(selector, node, kArmAdd, kArmAdd, cont); |
1681 case IrOpcode::kInt32SubWithOverflow: | 1708 case IrOpcode::kInt32SubWithOverflow: |
1682 cont->OverwriteAndNegateIfEqual(kOverflow); | 1709 cont->OverwriteAndNegateIfEqual(kOverflow); |
1683 return VisitBinop(selector, node, kArmSub, kArmRsb, cont); | 1710 return VisitBinop(selector, node, kArmSub, kArmRsb, cont); |
1711 case IrOpcode::kInt32MulWithOverflow: | |
1712 // ARM doesn't set the overflow flag for multiplication, so we | |
Benedikt Meurer
2016/07/12 04:09:28
Nice, thanks.
mvstanton
2016/07/12 08:52:49
Acknowledged.
| |
1713 // need to test on kNotEqual. Here is the code sequence used: | |
1714 // smull resultlow, resulthigh, left, right | |
1715 // cmp resulthigh, Operand(resultlow, ASR, 31) | |
1716 cont->OverwriteAndNegateIfEqual(kNotEqual); | |
1717 return VisitInt32MulWithOverflowImpl(selector, node, cont); | |
1684 default: | 1718 default: |
1685 break; | 1719 break; |
1686 } | 1720 } |
1687 } | 1721 } |
1688 } | 1722 } |
1689 break; | 1723 break; |
1690 case IrOpcode::kInt32Add: | 1724 case IrOpcode::kInt32Add: |
1691 return VisitWordCompare(selector, value, kArmCmn, cont); | 1725 return VisitWordCompare(selector, value, kArmCmn, cont); |
1692 case IrOpcode::kInt32Sub: | 1726 case IrOpcode::kInt32Sub: |
1693 return VisitWordCompare(selector, value, kArmCmp, cont); | 1727 return VisitWordCompare(selector, value, kArmCmp, cont); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1815 | 1849 |
1816 void InstructionSelector::VisitInt32AddWithOverflow(Node* node) { | 1850 void InstructionSelector::VisitInt32AddWithOverflow(Node* node) { |
1817 if (Node* ovf = NodeProperties::FindProjection(node, 1)) { | 1851 if (Node* ovf = NodeProperties::FindProjection(node, 1)) { |
1818 FlagsContinuation cont = FlagsContinuation::ForSet(kOverflow, ovf); | 1852 FlagsContinuation cont = FlagsContinuation::ForSet(kOverflow, ovf); |
1819 return VisitBinop(this, node, kArmAdd, kArmAdd, &cont); | 1853 return VisitBinop(this, node, kArmAdd, kArmAdd, &cont); |
1820 } | 1854 } |
1821 FlagsContinuation cont; | 1855 FlagsContinuation cont; |
1822 VisitBinop(this, node, kArmAdd, kArmAdd, &cont); | 1856 VisitBinop(this, node, kArmAdd, kArmAdd, &cont); |
1823 } | 1857 } |
1824 | 1858 |
1825 | |
1826 void InstructionSelector::VisitInt32SubWithOverflow(Node* node) { | 1859 void InstructionSelector::VisitInt32SubWithOverflow(Node* node) { |
1827 if (Node* ovf = NodeProperties::FindProjection(node, 1)) { | 1860 if (Node* ovf = NodeProperties::FindProjection(node, 1)) { |
1828 FlagsContinuation cont = FlagsContinuation::ForSet(kOverflow, ovf); | 1861 FlagsContinuation cont = FlagsContinuation::ForSet(kOverflow, ovf); |
1829 return VisitBinop(this, node, kArmSub, kArmRsb, &cont); | 1862 return VisitBinop(this, node, kArmSub, kArmRsb, &cont); |
1830 } | 1863 } |
1831 FlagsContinuation cont; | 1864 FlagsContinuation cont; |
1832 VisitBinop(this, node, kArmSub, kArmRsb, &cont); | 1865 VisitBinop(this, node, kArmSub, kArmRsb, &cont); |
1833 } | 1866 } |
1834 | 1867 |
1868 void InstructionSelector::VisitInt32MulWithOverflow(Node* node) { | |
1869 if (Node* ovf = NodeProperties::FindProjection(node, 1)) { | |
1870 // ARM doesn't set the overflow flag for multiplication, so we need to test | |
1871 // on kNotEqual. Here is the code sequence used: | |
1872 // smull resultlow, resulthigh, left, right | |
1873 // cmp resulthigh, Operand(resultlow, ASR, 31) | |
1874 FlagsContinuation cont = FlagsContinuation::ForSet(kNotEqual, ovf); | |
1875 return VisitInt32MulWithOverflowImpl(this, node, &cont); | |
1876 } | |
1877 FlagsContinuation cont; | |
1878 VisitInt32MulWithOverflowImpl(this, node, &cont); | |
1879 } | |
1835 | 1880 |
1836 void InstructionSelector::VisitFloat32Equal(Node* node) { | 1881 void InstructionSelector::VisitFloat32Equal(Node* node) { |
1837 FlagsContinuation cont = FlagsContinuation::ForSet(kEqual, node); | 1882 FlagsContinuation cont = FlagsContinuation::ForSet(kEqual, node); |
1838 VisitFloat32Compare(this, node, &cont); | 1883 VisitFloat32Compare(this, node, &cont); |
1839 } | 1884 } |
1840 | 1885 |
1841 | 1886 |
1842 void InstructionSelector::VisitFloat32LessThan(Node* node) { | 1887 void InstructionSelector::VisitFloat32LessThan(Node* node) { |
1843 FlagsContinuation cont = FlagsContinuation::ForSet(kFloatLessThan, node); | 1888 FlagsContinuation cont = FlagsContinuation::ForSet(kFloatLessThan, node); |
1844 VisitFloat32Compare(this, node, &cont); | 1889 VisitFloat32Compare(this, node, &cont); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2004 // static | 2049 // static |
2005 MachineOperatorBuilder::AlignmentRequirements | 2050 MachineOperatorBuilder::AlignmentRequirements |
2006 InstructionSelector::AlignmentRequirements() { | 2051 InstructionSelector::AlignmentRequirements() { |
2007 return MachineOperatorBuilder::AlignmentRequirements:: | 2052 return MachineOperatorBuilder::AlignmentRequirements:: |
2008 FullUnalignedAccessSupport(); | 2053 FullUnalignedAccessSupport(); |
2009 } | 2054 } |
2010 | 2055 |
2011 } // namespace compiler | 2056 } // namespace compiler |
2012 } // namespace internal | 2057 } // namespace internal |
2013 } // namespace v8 | 2058 } // namespace v8 |
OLD | NEW |