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

Side by Side Diff: src/compiler/arm/instruction-selector-arm.cc

Issue 2101123005: [turbofan] Introduce integer multiplication with overflow. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: REBASE. Created 4 years, 5 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
OLDNEW
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
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 namespace {
1097
1098 void EmitInt32MulWithOverflow(InstructionSelector* selector, Node* node,
1099 FlagsContinuation* cont) {
1100 ArmOperandGenerator g(selector);
1101 Int32BinopMatcher m(node);
1102 InstructionOperand result_operand = g.DefineAsRegister(node);
1103 InstructionOperand temp_operand = g.TempRegister();
1104 InstructionOperand outputs[] = {result_operand, temp_operand};
1105 InstructionOperand inputs[] = {g.UseRegister(m.left().node()),
1106 g.UseRegister(m.right().node())};
1107 selector->Emit(kArmSmull, 2, outputs, 2, inputs);
1108
1109 // result operand needs shift operator.
1110 InstructionOperand shift_31 = g.UseImmediate(31);
1111 InstructionCode opcode = cont->Encode(kArmCmp) |
1112 AddressingModeField::encode(kMode_Operand2_R_ASR_I);
1113 if (cont->IsBranch()) {
1114 selector->Emit(opcode, g.NoOutput(), temp_operand, result_operand, shift_31,
1115 g.Label(cont->true_block()), g.Label(cont->false_block()));
1116 } else if (cont->IsDeoptimize()) {
1117 InstructionOperand in[] = {temp_operand, result_operand, shift_31};
1118 selector->EmitDeoptimize(opcode, 0, nullptr, 3, in, cont->frame_state());
1119 } else {
1120 DCHECK(cont->IsSet());
1121 selector->Emit(opcode, g.DefineAsRegister(cont->result()), temp_operand,
1122 result_operand, shift_31);
1123 }
1124 }
1125
1126 } // namespace
1096 1127
1097 void InstructionSelector::VisitInt32Mul(Node* node) { 1128 void InstructionSelector::VisitInt32Mul(Node* node) {
1098 ArmOperandGenerator g(this); 1129 ArmOperandGenerator g(this);
1099 Int32BinopMatcher m(node); 1130 Int32BinopMatcher m(node);
1100 if (m.right().HasValue() && m.right().Value() > 0) { 1131 if (m.right().HasValue() && m.right().Value() > 0) {
1101 int32_t value = m.right().Value(); 1132 int32_t value = m.right().Value();
1102 if (base::bits::IsPowerOfTwo32(value - 1)) { 1133 if (base::bits::IsPowerOfTwo32(value - 1)) {
1103 Emit(kArmAdd | AddressingModeField::encode(kMode_Operand2_R_LSL_I), 1134 Emit(kArmAdd | AddressingModeField::encode(kMode_Operand2_R_LSL_I),
1104 g.DefineAsRegister(node), g.UseRegister(m.left().node()), 1135 g.DefineAsRegister(node), g.UseRegister(m.left().node()),
1105 g.UseRegister(m.left().node()), 1136 g.UseRegister(m.left().node()),
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
1674 Node* const node = value->InputAt(0); 1705 Node* const node = value->InputAt(0);
1675 Node* const result = NodeProperties::FindProjection(node, 0); 1706 Node* const result = NodeProperties::FindProjection(node, 0);
1676 if (!result || selector->IsDefined(result)) { 1707 if (!result || selector->IsDefined(result)) {
1677 switch (node->opcode()) { 1708 switch (node->opcode()) {
1678 case IrOpcode::kInt32AddWithOverflow: 1709 case IrOpcode::kInt32AddWithOverflow:
1679 cont->OverwriteAndNegateIfEqual(kOverflow); 1710 cont->OverwriteAndNegateIfEqual(kOverflow);
1680 return VisitBinop(selector, node, kArmAdd, kArmAdd, cont); 1711 return VisitBinop(selector, node, kArmAdd, kArmAdd, cont);
1681 case IrOpcode::kInt32SubWithOverflow: 1712 case IrOpcode::kInt32SubWithOverflow:
1682 cont->OverwriteAndNegateIfEqual(kOverflow); 1713 cont->OverwriteAndNegateIfEqual(kOverflow);
1683 return VisitBinop(selector, node, kArmSub, kArmRsb, cont); 1714 return VisitBinop(selector, node, kArmSub, kArmRsb, cont);
1715 case IrOpcode::kInt32MulWithOverflow:
1716 // ARM doesn't set the overflow flag for multiplication, so we
1717 // need to test on kNotEqual. Here is the code sequence used:
1718 // smull resultlow, resulthigh, left, right
1719 // cmp resulthigh, Operand(resultlow, ASR, 31)
1720 cont->OverwriteAndNegateIfEqual(kNotEqual);
1721 return EmitInt32MulWithOverflow(selector, node, cont);
1684 default: 1722 default:
1685 break; 1723 break;
1686 } 1724 }
1687 } 1725 }
1688 } 1726 }
1689 break; 1727 break;
1690 case IrOpcode::kInt32Add: 1728 case IrOpcode::kInt32Add:
1691 return VisitWordCompare(selector, value, kArmCmn, cont); 1729 return VisitWordCompare(selector, value, kArmCmn, cont);
1692 case IrOpcode::kInt32Sub: 1730 case IrOpcode::kInt32Sub:
1693 return VisitWordCompare(selector, value, kArmCmp, cont); 1731 return VisitWordCompare(selector, value, kArmCmp, cont);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1815 1853
1816 void InstructionSelector::VisitInt32AddWithOverflow(Node* node) { 1854 void InstructionSelector::VisitInt32AddWithOverflow(Node* node) {
1817 if (Node* ovf = NodeProperties::FindProjection(node, 1)) { 1855 if (Node* ovf = NodeProperties::FindProjection(node, 1)) {
1818 FlagsContinuation cont = FlagsContinuation::ForSet(kOverflow, ovf); 1856 FlagsContinuation cont = FlagsContinuation::ForSet(kOverflow, ovf);
1819 return VisitBinop(this, node, kArmAdd, kArmAdd, &cont); 1857 return VisitBinop(this, node, kArmAdd, kArmAdd, &cont);
1820 } 1858 }
1821 FlagsContinuation cont; 1859 FlagsContinuation cont;
1822 VisitBinop(this, node, kArmAdd, kArmAdd, &cont); 1860 VisitBinop(this, node, kArmAdd, kArmAdd, &cont);
1823 } 1861 }
1824 1862
1825
1826 void InstructionSelector::VisitInt32SubWithOverflow(Node* node) { 1863 void InstructionSelector::VisitInt32SubWithOverflow(Node* node) {
1827 if (Node* ovf = NodeProperties::FindProjection(node, 1)) { 1864 if (Node* ovf = NodeProperties::FindProjection(node, 1)) {
1828 FlagsContinuation cont = FlagsContinuation::ForSet(kOverflow, ovf); 1865 FlagsContinuation cont = FlagsContinuation::ForSet(kOverflow, ovf);
1829 return VisitBinop(this, node, kArmSub, kArmRsb, &cont); 1866 return VisitBinop(this, node, kArmSub, kArmRsb, &cont);
1830 } 1867 }
1831 FlagsContinuation cont; 1868 FlagsContinuation cont;
1832 VisitBinop(this, node, kArmSub, kArmRsb, &cont); 1869 VisitBinop(this, node, kArmSub, kArmRsb, &cont);
1833 } 1870 }
1834 1871
1872 void InstructionSelector::VisitInt32MulWithOverflow(Node* node) {
1873 if (Node* ovf = NodeProperties::FindProjection(node, 1)) {
1874 // ARM doesn't set the overflow flag for multiplication, so we need to test
1875 // on kNotEqual. Here is the code sequence used:
1876 // smull resultlow, resulthigh, left, right
1877 // cmp resulthigh, Operand(resultlow, ASR, 31)
1878 FlagsContinuation cont = FlagsContinuation::ForSet(kNotEqual, ovf);
1879 return EmitInt32MulWithOverflow(this, node, &cont);
1880 }
1881 FlagsContinuation cont;
1882 EmitInt32MulWithOverflow(this, node, &cont);
1883 }
1835 1884
1836 void InstructionSelector::VisitFloat32Equal(Node* node) { 1885 void InstructionSelector::VisitFloat32Equal(Node* node) {
1837 FlagsContinuation cont = FlagsContinuation::ForSet(kEqual, node); 1886 FlagsContinuation cont = FlagsContinuation::ForSet(kEqual, node);
1838 VisitFloat32Compare(this, node, &cont); 1887 VisitFloat32Compare(this, node, &cont);
1839 } 1888 }
1840 1889
1841 1890
1842 void InstructionSelector::VisitFloat32LessThan(Node* node) { 1891 void InstructionSelector::VisitFloat32LessThan(Node* node) {
1843 FlagsContinuation cont = FlagsContinuation::ForSet(kFloatLessThan, node); 1892 FlagsContinuation cont = FlagsContinuation::ForSet(kFloatLessThan, node);
1844 VisitFloat32Compare(this, node, &cont); 1893 VisitFloat32Compare(this, node, &cont);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
2004 // static 2053 // static
2005 MachineOperatorBuilder::AlignmentRequirements 2054 MachineOperatorBuilder::AlignmentRequirements
2006 InstructionSelector::AlignmentRequirements() { 2055 InstructionSelector::AlignmentRequirements() {
2007 return MachineOperatorBuilder::AlignmentRequirements:: 2056 return MachineOperatorBuilder::AlignmentRequirements::
2008 FullUnalignedAccessSupport(); 2057 FullUnalignedAccessSupport();
2009 } 2058 }
2010 2059
2011 } // namespace compiler 2060 } // namespace compiler
2012 } // namespace internal 2061 } // namespace internal
2013 } // namespace v8 2062 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/arm/instruction-scheduler-arm.cc ('k') | src/compiler/arm64/code-generator-arm64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698