Commit 14151c81 authored by dusan.milosavljevic's avatar dusan.milosavljevic Committed by Commit bot

Reland "MIPS64: Fix lithium arithmetic operations for integers to sign-extend result."

TEST==mjsunit/asm/double-lo
BUG=

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

Cr-Commit-Position: refs/heads/master@{#29078}
parent 80a6e539
...@@ -2487,11 +2487,11 @@ void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr, ...@@ -2487,11 +2487,11 @@ void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr,
break; break;
} }
case Token::ADD: case Token::ADD:
__ AdduAndCheckForOverflow(v0, left, right, scratch1); __ DadduAndCheckForOverflow(v0, left, right, scratch1);
__ BranchOnOverflow(&stub_call, scratch1); __ BranchOnOverflow(&stub_call, scratch1);
break; break;
case Token::SUB: case Token::SUB:
__ SubuAndCheckForOverflow(v0, left, right, scratch1); __ DsubuAndCheckForOverflow(v0, left, right, scratch1);
__ BranchOnOverflow(&stub_call, scratch1); __ BranchOnOverflow(&stub_call, scratch1);
break; break;
case Token::MUL: { case Token::MUL: {
...@@ -4506,7 +4506,7 @@ void FullCodeGenerator::EmitFastOneByteArrayJoin(CallRuntime* expr) { ...@@ -4506,7 +4506,7 @@ void FullCodeGenerator::EmitFastOneByteArrayJoin(CallRuntime* expr) {
__ lbu(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset)); __ lbu(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
__ JumpIfInstanceTypeIsNotSequentialOneByte(scratch1, scratch2, &bailout); __ JumpIfInstanceTypeIsNotSequentialOneByte(scratch1, scratch2, &bailout);
__ ld(scratch1, FieldMemOperand(string, SeqOneByteString::kLengthOffset)); __ ld(scratch1, FieldMemOperand(string, SeqOneByteString::kLengthOffset));
__ AdduAndCheckForOverflow(string_length, string_length, scratch1, scratch3); __ DadduAndCheckForOverflow(string_length, string_length, scratch1, scratch3);
__ BranchOnOverflow(&bailout, scratch3); __ BranchOnOverflow(&bailout, scratch3);
__ Branch(&loop, lt, element, Operand(elements_end)); __ Branch(&loop, lt, element, Operand(elements_end));
...@@ -5022,7 +5022,7 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { ...@@ -5022,7 +5022,7 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
Register scratch1 = a1; Register scratch1 = a1;
Register scratch2 = a4; Register scratch2 = a4;
__ li(scratch1, Operand(Smi::FromInt(count_value))); __ li(scratch1, Operand(Smi::FromInt(count_value)));
__ AdduAndCheckForOverflow(v0, v0, scratch1, scratch2); __ DadduAndCheckForOverflow(v0, v0, scratch1, scratch2);
__ BranchOnNoOverflow(&done, scratch2); __ BranchOnNoOverflow(&done, scratch2);
// Call stub. Undo operation first. // Call stub. Undo operation first.
__ Move(v0, a0); __ Move(v0, a0);
......
This diff is collapsed.
...@@ -1527,14 +1527,17 @@ LInstruction* LChunkBuilder::DoMul(HMul* instr) { ...@@ -1527,14 +1527,17 @@ LInstruction* LChunkBuilder::DoMul(HMul* instr) {
} }
right_op = UseRegister(right); right_op = UseRegister(right);
} }
LMulI* mul = new(zone()) LMulI(left_op, right_op); LInstruction* result =
instr->representation().IsSmi()
? DefineAsRegister(new (zone()) LMulS(left_op, right_op))
: DefineAsRegister(new (zone()) LMulI(left_op, right_op));
if (right_op->IsConstantOperand() if (right_op->IsConstantOperand()
? ((can_overflow && constant_value == -1) || ? ((can_overflow && constant_value == -1) ||
(bailout_on_minus_zero && constant_value <= 0)) (bailout_on_minus_zero && constant_value <= 0))
: (can_overflow || bailout_on_minus_zero)) { : (can_overflow || bailout_on_minus_zero)) {
AssignEnvironment(mul); AssignEnvironment(result);
} }
return DefineAsRegister(mul); return result;
} else if (instr->representation().IsDouble()) { } else if (instr->representation().IsDouble()) {
if (kArchVariant == kMips64r2) { if (kArchVariant == kMips64r2) {
...@@ -1564,9 +1567,11 @@ LInstruction* LChunkBuilder::DoSub(HSub* instr) { ...@@ -1564,9 +1567,11 @@ LInstruction* LChunkBuilder::DoSub(HSub* instr) {
DCHECK(instr->left()->representation().Equals(instr->representation())); DCHECK(instr->left()->representation().Equals(instr->representation()));
DCHECK(instr->right()->representation().Equals(instr->representation())); DCHECK(instr->right()->representation().Equals(instr->representation()));
LOperand* left = UseRegisterAtStart(instr->left()); LOperand* left = UseRegisterAtStart(instr->left());
LOperand* right = UseOrConstantAtStart(instr->right()); LOperand* right = UseRegisterOrConstantAtStart(instr->right());
LSubI* sub = new(zone()) LSubI(left, right); LInstruction* result =
LInstruction* result = DefineAsRegister(sub); instr->representation().IsSmi()
? DefineAsRegister(new (zone()) LSubS(left, right))
: DefineAsRegister(new (zone()) LSubI(left, right));
if (instr->CheckFlag(HValue::kCanOverflow)) { if (instr->CheckFlag(HValue::kCanOverflow)) {
result = AssignEnvironment(result); result = AssignEnvironment(result);
} }
...@@ -1594,8 +1599,10 @@ LInstruction* LChunkBuilder::DoAdd(HAdd* instr) { ...@@ -1594,8 +1599,10 @@ LInstruction* LChunkBuilder::DoAdd(HAdd* instr) {
DCHECK(instr->right()->representation().Equals(instr->representation())); DCHECK(instr->right()->representation().Equals(instr->representation()));
LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
LOperand* right = UseRegisterOrConstantAtStart(instr->BetterRightOperand()); LOperand* right = UseRegisterOrConstantAtStart(instr->BetterRightOperand());
LAddI* add = new(zone()) LAddI(left, right); LInstruction* result =
LInstruction* result = DefineAsRegister(add); instr->representation().IsSmi()
? DefineAsRegister(new (zone()) LAddS(left, right))
: DefineAsRegister(new (zone()) LAddI(left, right));
if (instr->CheckFlag(HValue::kCanOverflow)) { if (instr->CheckFlag(HValue::kCanOverflow)) {
result = AssignEnvironment(result); result = AssignEnvironment(result);
} }
......
...@@ -19,8 +19,9 @@ class LCodeGen; ...@@ -19,8 +19,9 @@ class LCodeGen;
#define LITHIUM_CONCRETE_INSTRUCTION_LIST(V) \ #define LITHIUM_CONCRETE_INSTRUCTION_LIST(V) \
V(AccessArgumentsAt) \ V(AccessArgumentsAt) \
V(AddI) \
V(AddE) \ V(AddE) \
V(AddI) \
V(AddS) \
V(Allocate) \ V(Allocate) \
V(AllocateBlockContext) \ V(AllocateBlockContext) \
V(ApplyArguments) \ V(ApplyArguments) \
...@@ -123,6 +124,7 @@ class LCodeGen; ...@@ -123,6 +124,7 @@ class LCodeGen;
V(ModByPowerOf2I) \ V(ModByPowerOf2I) \
V(ModI) \ V(ModI) \
V(MulI) \ V(MulI) \
V(MulS) \
V(MultiplyAddD) \ V(MultiplyAddD) \
V(NumberTagD) \ V(NumberTagD) \
V(NumberTagU) \ V(NumberTagU) \
...@@ -151,6 +153,7 @@ class LCodeGen; ...@@ -151,6 +153,7 @@ class LCodeGen;
V(StringCharFromCode) \ V(StringCharFromCode) \
V(StringCompareAndBranch) \ V(StringCompareAndBranch) \
V(SubI) \ V(SubI) \
V(SubS) \
V(TaggedToI) \ V(TaggedToI) \
V(ThisFunction) \ V(ThisFunction) \
V(ToFastProperties) \ V(ToFastProperties) \
...@@ -754,6 +757,21 @@ class LFlooringDivI final : public LTemplateInstruction<1, 2, 0> { ...@@ -754,6 +757,21 @@ class LFlooringDivI final : public LTemplateInstruction<1, 2, 0> {
}; };
class LMulS final : public LTemplateInstruction<1, 2, 0> {
public:
LMulS(LOperand* left, LOperand* right) {
inputs_[0] = left;
inputs_[1] = right;
}
LOperand* left() { return inputs_[0]; }
LOperand* right() { return inputs_[1]; }
DECLARE_CONCRETE_INSTRUCTION(MulS, "mul-s")
DECLARE_HYDROGEN_ACCESSOR(Mul)
};
class LMulI final : public LTemplateInstruction<1, 2, 0> { class LMulI final : public LTemplateInstruction<1, 2, 0> {
public: public:
LMulI(LOperand* left, LOperand* right) { LMulI(LOperand* left, LOperand* right) {
...@@ -1274,6 +1292,21 @@ class LSubI final : public LTemplateInstruction<1, 2, 0> { ...@@ -1274,6 +1292,21 @@ class LSubI final : public LTemplateInstruction<1, 2, 0> {
}; };
class LSubS final : public LTemplateInstruction<1, 2, 0> {
public:
LSubS(LOperand* left, LOperand* right) {
inputs_[0] = left;
inputs_[1] = right;
}
LOperand* left() { return inputs_[0]; }
LOperand* right() { return inputs_[1]; }
DECLARE_CONCRETE_INSTRUCTION(SubS, "sub-s")
DECLARE_HYDROGEN_ACCESSOR(Sub)
};
class LConstantI final : public LTemplateInstruction<1, 0, 0> { class LConstantI final : public LTemplateInstruction<1, 0, 0> {
public: public:
DECLARE_CONCRETE_INSTRUCTION(ConstantI, "constant-i") DECLARE_CONCRETE_INSTRUCTION(ConstantI, "constant-i")
...@@ -1452,6 +1485,21 @@ class LAddI final : public LTemplateInstruction<1, 2, 0> { ...@@ -1452,6 +1485,21 @@ class LAddI final : public LTemplateInstruction<1, 2, 0> {
}; };
class LAddS final : public LTemplateInstruction<1, 2, 0> {
public:
LAddS(LOperand* left, LOperand* right) {
inputs_[0] = left;
inputs_[1] = right;
}
LOperand* left() { return inputs_[0]; }
LOperand* right() { return inputs_[1]; }
DECLARE_CONCRETE_INSTRUCTION(AddS, "add-s")
DECLARE_HYDROGEN_ACCESSOR(Add)
};
class LMathMinMax final : public LTemplateInstruction<1, 2, 0> { class LMathMinMax final : public LTemplateInstruction<1, 2, 0> {
public: public:
LMathMinMax(LOperand* left, LOperand* right) { LMathMinMax(LOperand* left, LOperand* right) {
......
...@@ -4447,7 +4447,6 @@ void MacroAssembler::ObjectToDoubleFPURegister(Register object, ...@@ -4447,7 +4447,6 @@ void MacroAssembler::ObjectToDoubleFPURegister(Register object,
void MacroAssembler::SmiToDoubleFPURegister(Register smi, void MacroAssembler::SmiToDoubleFPURegister(Register smi,
FPURegister value, FPURegister value,
Register scratch1) { Register scratch1) {
// dsra(scratch1, smi, kSmiTagSize);
dsra32(scratch1, smi, 0); dsra32(scratch1, smi, 0);
mtc1(scratch1, value); mtc1(scratch1, value);
cvt_d_w(value, value); cvt_d_w(value, value);
...@@ -4462,19 +4461,16 @@ void MacroAssembler::AdduAndCheckForOverflow(Register dst, Register left, ...@@ -4462,19 +4461,16 @@ void MacroAssembler::AdduAndCheckForOverflow(Register dst, Register left,
AdduAndCheckForOverflow(dst, left, right.rm(), overflow_dst, scratch); AdduAndCheckForOverflow(dst, left, right.rm(), overflow_dst, scratch);
} else { } else {
if (dst.is(left)) { if (dst.is(left)) {
li(t9, right); // Load right.
mov(scratch, left); // Preserve left. mov(scratch, left); // Preserve left.
daddiu(dst, left, addu(dst, left, t9); // Left is overwritten.
static_cast<int32_t>(right.immediate())); // Left is overwritten.
xor_(scratch, dst, scratch); // Original left. xor_(scratch, dst, scratch); // Original left.
// Load right since xori takes uint16 as immediate.
daddiu(t9, zero_reg, static_cast<int32_t>(right.immediate()));
xor_(overflow_dst, dst, t9); xor_(overflow_dst, dst, t9);
and_(overflow_dst, overflow_dst, scratch); and_(overflow_dst, overflow_dst, scratch);
} else { } else {
daddiu(dst, left, static_cast<int32_t>(right.immediate())); li(t9, right);
addu(dst, left, t9);
xor_(overflow_dst, dst, left); xor_(overflow_dst, dst, left);
// Load right since xori takes uint16 as immediate.
daddiu(t9, zero_reg, static_cast<int32_t>(right.immediate()));
xor_(scratch, dst, t9); xor_(scratch, dst, t9);
and_(overflow_dst, scratch, overflow_dst); and_(overflow_dst, scratch, overflow_dst);
} }
...@@ -4482,8 +4478,7 @@ void MacroAssembler::AdduAndCheckForOverflow(Register dst, Register left, ...@@ -4482,8 +4478,7 @@ void MacroAssembler::AdduAndCheckForOverflow(Register dst, Register left,
} }
void MacroAssembler::AdduAndCheckForOverflow(Register dst, void MacroAssembler::AdduAndCheckForOverflow(Register dst, Register left,
Register left,
Register right, Register right,
Register overflow_dst, Register overflow_dst,
Register scratch) { Register scratch) {
...@@ -4503,6 +4498,72 @@ void MacroAssembler::AdduAndCheckForOverflow(Register dst, ...@@ -4503,6 +4498,72 @@ void MacroAssembler::AdduAndCheckForOverflow(Register dst,
right = t9; right = t9;
} }
if (dst.is(left)) {
mov(scratch, left); // Preserve left.
addu(dst, left, right); // Left is overwritten.
xor_(scratch, dst, scratch); // Original left.
xor_(overflow_dst, dst, right);
and_(overflow_dst, overflow_dst, scratch);
} else if (dst.is(right)) {
mov(scratch, right); // Preserve right.
addu(dst, left, right); // Right is overwritten.
xor_(scratch, dst, scratch); // Original right.
xor_(overflow_dst, dst, left);
and_(overflow_dst, overflow_dst, scratch);
} else {
addu(dst, left, right);
xor_(overflow_dst, dst, left);
xor_(scratch, dst, right);
and_(overflow_dst, scratch, overflow_dst);
}
}
void MacroAssembler::DadduAndCheckForOverflow(Register dst, Register left,
const Operand& right,
Register overflow_dst,
Register scratch) {
if (right.is_reg()) {
DadduAndCheckForOverflow(dst, left, right.rm(), overflow_dst, scratch);
} else {
if (dst.is(left)) {
li(t9, right); // Load right.
mov(scratch, left); // Preserve left.
daddu(dst, left, t9); // Left is overwritten.
xor_(scratch, dst, scratch); // Original left.
xor_(overflow_dst, dst, t9);
and_(overflow_dst, overflow_dst, scratch);
} else {
li(t9, right); // Load right.
Daddu(dst, left, t9);
xor_(overflow_dst, dst, left);
xor_(scratch, dst, t9);
and_(overflow_dst, scratch, overflow_dst);
}
}
}
void MacroAssembler::DadduAndCheckForOverflow(Register dst, Register left,
Register right,
Register overflow_dst,
Register scratch) {
DCHECK(!dst.is(overflow_dst));
DCHECK(!dst.is(scratch));
DCHECK(!overflow_dst.is(scratch));
DCHECK(!overflow_dst.is(left));
DCHECK(!overflow_dst.is(right));
if (left.is(right) && dst.is(left)) {
DCHECK(!dst.is(t9));
DCHECK(!scratch.is(t9));
DCHECK(!left.is(t9));
DCHECK(!right.is(t9));
DCHECK(!overflow_dst.is(t9));
mov(t9, right);
right = t9;
}
if (dst.is(left)) { if (dst.is(left)) {
mov(scratch, left); // Preserve left. mov(scratch, left); // Preserve left.
daddu(dst, left, right); // Left is overwritten. daddu(dst, left, right); // Left is overwritten.
...@@ -4532,19 +4593,16 @@ void MacroAssembler::SubuAndCheckForOverflow(Register dst, Register left, ...@@ -4532,19 +4593,16 @@ void MacroAssembler::SubuAndCheckForOverflow(Register dst, Register left,
SubuAndCheckForOverflow(dst, left, right.rm(), overflow_dst, scratch); SubuAndCheckForOverflow(dst, left, right.rm(), overflow_dst, scratch);
} else { } else {
if (dst.is(left)) { if (dst.is(left)) {
li(t9, right); // Load right.
mov(scratch, left); // Preserve left. mov(scratch, left); // Preserve left.
daddiu(dst, left, Subu(dst, left, t9); // Left is overwritten.
static_cast<int32_t>(-right.immediate())); // Left is overwritten.
xor_(overflow_dst, dst, scratch); // scratch is original left. xor_(overflow_dst, dst, scratch); // scratch is original left.
// Load right since xori takes uint16 as immediate.
daddiu(t9, zero_reg, static_cast<int32_t>(right.immediate()));
xor_(scratch, scratch, t9); // scratch is original left. xor_(scratch, scratch, t9); // scratch is original left.
and_(overflow_dst, scratch, overflow_dst); and_(overflow_dst, scratch, overflow_dst);
} else { } else {
daddiu(dst, left, static_cast<int32_t>(-right.immediate())); li(t9, right);
subu(dst, left, t9);
xor_(overflow_dst, dst, left); xor_(overflow_dst, dst, left);
// Load right since xori takes uint16 as immediate.
daddiu(t9, zero_reg, static_cast<int32_t>(right.immediate()));
xor_(scratch, left, t9); xor_(scratch, left, t9);
and_(overflow_dst, scratch, overflow_dst); and_(overflow_dst, scratch, overflow_dst);
} }
...@@ -4552,8 +4610,7 @@ void MacroAssembler::SubuAndCheckForOverflow(Register dst, Register left, ...@@ -4552,8 +4610,7 @@ void MacroAssembler::SubuAndCheckForOverflow(Register dst, Register left,
} }
void MacroAssembler::SubuAndCheckForOverflow(Register dst, void MacroAssembler::SubuAndCheckForOverflow(Register dst, Register left,
Register left,
Register right, Register right,
Register overflow_dst, Register overflow_dst,
Register scratch) { Register scratch) {
...@@ -4573,6 +4630,72 @@ void MacroAssembler::SubuAndCheckForOverflow(Register dst, ...@@ -4573,6 +4630,72 @@ void MacroAssembler::SubuAndCheckForOverflow(Register dst,
return; return;
} }
if (dst.is(left)) {
mov(scratch, left); // Preserve left.
subu(dst, left, right); // Left is overwritten.
xor_(overflow_dst, dst, scratch); // scratch is original left.
xor_(scratch, scratch, right); // scratch is original left.
and_(overflow_dst, scratch, overflow_dst);
} else if (dst.is(right)) {
mov(scratch, right); // Preserve right.
subu(dst, left, right); // Right is overwritten.
xor_(overflow_dst, dst, left);
xor_(scratch, left, scratch); // Original right.
and_(overflow_dst, scratch, overflow_dst);
} else {
subu(dst, left, right);
xor_(overflow_dst, dst, left);
xor_(scratch, left, right);
and_(overflow_dst, scratch, overflow_dst);
}
}
void MacroAssembler::DsubuAndCheckForOverflow(Register dst, Register left,
const Operand& right,
Register overflow_dst,
Register scratch) {
if (right.is_reg()) {
DsubuAndCheckForOverflow(dst, left, right.rm(), overflow_dst, scratch);
} else {
if (dst.is(left)) {
li(t9, right); // Load right.
mov(scratch, left); // Preserve left.
dsubu(dst, left, t9); // Left is overwritten.
xor_(overflow_dst, dst, scratch); // scratch is original left.
xor_(scratch, scratch, t9); // scratch is original left.
and_(overflow_dst, scratch, overflow_dst);
} else {
li(t9, right);
dsubu(dst, left, t9);
xor_(overflow_dst, dst, left);
xor_(scratch, left, t9);
and_(overflow_dst, scratch, overflow_dst);
}
}
}
void MacroAssembler::DsubuAndCheckForOverflow(Register dst, Register left,
Register right,
Register overflow_dst,
Register scratch) {
DCHECK(!dst.is(overflow_dst));
DCHECK(!dst.is(scratch));
DCHECK(!overflow_dst.is(scratch));
DCHECK(!overflow_dst.is(left));
DCHECK(!overflow_dst.is(right));
DCHECK(!scratch.is(left));
DCHECK(!scratch.is(right));
// This happens with some crankshaft code. Since Subu works fine if
// left == right, let's not make that restriction here.
if (left.is(right)) {
mov(dst, zero_reg);
mov(overflow_dst, zero_reg);
return;
}
if (dst.is(left)) { if (dst.is(left)) {
mov(scratch, left); // Preserve left. mov(scratch, left); // Preserve left.
dsubu(dst, left, right); // Left is overwritten. dsubu(dst, left, right); // Left is overwritten.
...@@ -4593,7 +4716,6 @@ void MacroAssembler::SubuAndCheckForOverflow(Register dst, ...@@ -4593,7 +4716,6 @@ void MacroAssembler::SubuAndCheckForOverflow(Register dst,
} }
} }
void MacroAssembler::CallRuntime(const Runtime::Function* f, void MacroAssembler::CallRuntime(const Runtime::Function* f,
int num_arguments, int num_arguments,
SaveFPRegsMode save_doubles) { SaveFPRegsMode save_doubles) {
......
...@@ -1203,7 +1203,7 @@ class MacroAssembler: public Assembler { ...@@ -1203,7 +1203,7 @@ class MacroAssembler: public Assembler {
void AdduAndCheckForOverflow(Register dst, Register left, void AdduAndCheckForOverflow(Register dst, Register left,
const Operand& right, Register overflow_dst, const Operand& right, Register overflow_dst,
Register scratch = at); Register scratch);
void SubuAndCheckForOverflow(Register dst, void SubuAndCheckForOverflow(Register dst,
Register left, Register left,
...@@ -1213,7 +1213,21 @@ class MacroAssembler: public Assembler { ...@@ -1213,7 +1213,21 @@ class MacroAssembler: public Assembler {
void SubuAndCheckForOverflow(Register dst, Register left, void SubuAndCheckForOverflow(Register dst, Register left,
const Operand& right, Register overflow_dst, const Operand& right, Register overflow_dst,
Register scratch = at); Register scratch);
void DadduAndCheckForOverflow(Register dst, Register left, Register right,
Register overflow_dst, Register scratch = at);
void DadduAndCheckForOverflow(Register dst, Register left,
const Operand& right, Register overflow_dst,
Register scratch);
void DsubuAndCheckForOverflow(Register dst, Register left, Register right,
Register overflow_dst, Register scratch = at);
void DsubuAndCheckForOverflow(Register dst, Register left,
const Operand& right, Register overflow_dst,
Register scratch);
void BranchOnOverflow(Label* label, void BranchOnOverflow(Label* label,
Register overflow_check, Register overflow_check,
......
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