Commit d7aa94b9 authored by dusan.m.milosavljevic's avatar dusan.m.milosavljevic Committed by Commit bot

MIPS: [turbofan] Make Int32Div and Uint32Div safe.

TEST=
BUG=

Review URL: https://codereview.chromium.org/1503053002

Cr-Commit-Position: refs/heads/master@{#32685}
parent 8c376b46
......@@ -633,9 +633,19 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) {
break;
case kMipsDiv:
__ Div(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
if (IsMipsArchVariant(kMips32r6)) {
__ seleqz(i.OutputRegister(), i.InputRegister(0), i.InputRegister(0));
} else {
__ Movz(i.OutputRegister(), i.InputRegister(1), i.InputRegister(1));
}
break;
case kMipsDivU:
__ Divu(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
if (IsMipsArchVariant(kMips32r6)) {
__ seleqz(i.OutputRegister(), i.InputRegister(0), i.InputRegister(0));
} else {
__ Movz(i.OutputRegister(), i.InputRegister(1), i.InputRegister(1));
}
break;
case kMipsMod:
__ Mod(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
......
......@@ -468,7 +468,7 @@ void InstructionSelector::VisitUint32MulHigh(Node* node) {
void InstructionSelector::VisitInt32Div(Node* node) {
MipsOperandGenerator g(this);
Int32BinopMatcher m(node);
Emit(kMipsDiv, g.DefineAsRegister(node), g.UseRegister(m.left().node()),
Emit(kMipsDiv, g.DefineSameAsFirst(node), g.UseRegister(m.left().node()),
g.UseRegister(m.right().node()));
}
......@@ -476,7 +476,7 @@ void InstructionSelector::VisitInt32Div(Node* node) {
void InstructionSelector::VisitUint32Div(Node* node) {
MipsOperandGenerator g(this);
Int32BinopMatcher m(node);
Emit(kMipsDivU, g.DefineAsRegister(node), g.UseRegister(m.left().node()),
Emit(kMipsDivU, g.DefineSameAsFirst(node), g.UseRegister(m.left().node()),
g.UseRegister(m.right().node()));
}
......@@ -1272,7 +1272,9 @@ InstructionSelector::SupportedMachineOperatorFlags() {
MachineOperatorBuilder::kFloat64RoundTruncate |
MachineOperatorBuilder::kFloat64RoundTiesEven;
}
return flags | MachineOperatorBuilder::kWord32ShiftIsSafe |
return flags | MachineOperatorBuilder::kInt32DivIsSafe |
MachineOperatorBuilder::kUint32DivIsSafe |
MachineOperatorBuilder::kWord32ShiftIsSafe |
MachineOperatorBuilder::kFloat64Min |
MachineOperatorBuilder::kFloat64Max |
MachineOperatorBuilder::kFloat32Min |
......
......@@ -646,9 +646,19 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) {
break;
case kMips64Div:
__ Div(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
if (kArchVariant == kMips64r6) {
__ seleqz(i.OutputRegister(), i.InputRegister(0), i.InputRegister(0));
} else {
__ Movz(i.OutputRegister(), i.InputRegister(1), i.InputRegister(1));
}
break;
case kMips64DivU:
__ Divu(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
if (kArchVariant == kMips64r6) {
__ seleqz(i.OutputRegister(), i.InputRegister(0), i.InputRegister(0));
} else {
__ Movz(i.OutputRegister(), i.InputRegister(1), i.InputRegister(1));
}
break;
case kMips64Mod:
__ Mod(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
......@@ -661,9 +671,19 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) {
break;
case kMips64Ddiv:
__ Ddiv(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
if (kArchVariant == kMips64r6) {
__ seleqz(i.OutputRegister(), i.InputRegister(0), i.InputRegister(0));
} else {
__ Movz(i.OutputRegister(), i.InputRegister(1), i.InputRegister(1));
}
break;
case kMips64DdivU:
__ Ddivu(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
if (kArchVariant == kMips64r6) {
__ seleqz(i.OutputRegister(), i.InputRegister(0), i.InputRegister(0));
} else {
__ Movz(i.OutputRegister(), i.InputRegister(1), i.InputRegister(1));
}
break;
case kMips64Dmod:
__ Dmod(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
......
......@@ -722,7 +722,7 @@ void InstructionSelector::VisitInt32Div(Node* node) {
}
}
}
Emit(kMips64Div, g.DefineAsRegister(node), g.UseRegister(m.left().node()),
Emit(kMips64Div, g.DefineSameAsFirst(node), g.UseRegister(m.left().node()),
g.UseRegister(m.right().node()));
}
......@@ -730,7 +730,7 @@ void InstructionSelector::VisitInt32Div(Node* node) {
void InstructionSelector::VisitUint32Div(Node* node) {
Mips64OperandGenerator g(this);
Int32BinopMatcher m(node);
Emit(kMips64DivU, g.DefineAsRegister(node), g.UseRegister(m.left().node()),
Emit(kMips64DivU, g.DefineSameAsFirst(node), g.UseRegister(m.left().node()),
g.UseRegister(m.right().node()));
}
......@@ -769,7 +769,7 @@ void InstructionSelector::VisitUint32Mod(Node* node) {
void InstructionSelector::VisitInt64Div(Node* node) {
Mips64OperandGenerator g(this);
Int64BinopMatcher m(node);
Emit(kMips64Ddiv, g.DefineAsRegister(node), g.UseRegister(m.left().node()),
Emit(kMips64Ddiv, g.DefineSameAsFirst(node), g.UseRegister(m.left().node()),
g.UseRegister(m.right().node()));
}
......@@ -777,7 +777,7 @@ void InstructionSelector::VisitInt64Div(Node* node) {
void InstructionSelector::VisitUint64Div(Node* node) {
Mips64OperandGenerator g(this);
Int64BinopMatcher m(node);
Emit(kMips64DdivU, g.DefineAsRegister(node), g.UseRegister(m.left().node()),
Emit(kMips64DdivU, g.DefineSameAsFirst(node), g.UseRegister(m.left().node()),
g.UseRegister(m.right().node()));
}
......@@ -1742,6 +1742,8 @@ void InstructionSelector::VisitFloat64InsertHighWord32(Node* node) {
MachineOperatorBuilder::Flags
InstructionSelector::SupportedMachineOperatorFlags() {
return MachineOperatorBuilder::kWord32ShiftIsSafe |
MachineOperatorBuilder::kInt32DivIsSafe |
MachineOperatorBuilder::kUint32DivIsSafe |
MachineOperatorBuilder::kFloat64Min |
MachineOperatorBuilder::kFloat64Max |
MachineOperatorBuilder::kFloat32Min |
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment