Index: src/mips64/macro-assembler-mips64.cc |
diff --git a/src/mips64/macro-assembler-mips64.cc b/src/mips64/macro-assembler-mips64.cc |
index a1d9c41a561f9156cfc484c4278b0ebe8d7fd64c..2ca2e6a7baf851f70f70ce3d4394915f70c7f7a6 100644 |
--- a/src/mips64/macro-assembler-mips64.cc |
+++ b/src/mips64/macro-assembler-mips64.cc |
@@ -4730,6 +4730,89 @@ void MacroAssembler::DadduAndCheckForOverflow(Register dst, Register left, |
} |
+static inline void BranchOvfHelper(MacroAssembler* masm, Register overflow_dst, |
+ Label* overflow_label, |
+ Label* no_overflow_label) { |
+ DCHECK(overflow_label || no_overflow_label); |
+ if (!overflow_label) { |
+ DCHECK(no_overflow_label); |
+ masm->Branch(no_overflow_label, ge, overflow_dst, Operand(zero_reg)); |
+ } else { |
+ masm->Branch(overflow_label, lt, overflow_dst, Operand(zero_reg)); |
+ if (no_overflow_label) masm->Branch(no_overflow_label); |
+ } |
+} |
+ |
+ |
+void MacroAssembler::DaddBranchOvf(Register dst, Register left, |
+ const Operand& right, Label* overflow_label, |
+ Label* no_overflow_label, Register scratch) { |
+ if (right.is_reg()) { |
+ DaddBranchOvf(dst, left, right.rm(), overflow_label, no_overflow_label, |
+ scratch); |
+ } else { |
+ Register overflow_dst = t9; |
+ DCHECK(!dst.is(scratch)); |
+ DCHECK(!dst.is(overflow_dst)); |
+ DCHECK(!scratch.is(overflow_dst)); |
+ DCHECK(!left.is(overflow_dst)); |
+ li(overflow_dst, right); // Load right. |
+ if (dst.is(left)) { |
+ mov(scratch, left); // Preserve left. |
+ Daddu(dst, left, overflow_dst); // Left is overwritten. |
+ xor_(scratch, dst, scratch); // Original left. |
+ xor_(overflow_dst, dst, overflow_dst); |
+ and_(overflow_dst, overflow_dst, scratch); |
+ } else { |
+ Daddu(dst, left, overflow_dst); |
+ xor_(scratch, dst, overflow_dst); |
+ xor_(overflow_dst, dst, left); |
+ and_(overflow_dst, scratch, overflow_dst); |
+ } |
+ BranchOvfHelper(this, overflow_dst, overflow_label, no_overflow_label); |
+ } |
+} |
+ |
+ |
+void MacroAssembler::DaddBranchOvf(Register dst, Register left, Register right, |
+ Label* overflow_label, |
+ Label* no_overflow_label, Register scratch) { |
+ Register overflow_dst = t9; |
+ DCHECK(!dst.is(scratch)); |
+ DCHECK(!dst.is(overflow_dst)); |
+ DCHECK(!scratch.is(overflow_dst)); |
+ DCHECK(!left.is(overflow_dst)); |
+ DCHECK(!right.is(overflow_dst)); |
+ DCHECK(!left.is(scratch)); |
+ DCHECK(!right.is(scratch)); |
+ |
+ if (left.is(right) && dst.is(left)) { |
+ mov(overflow_dst, right); |
+ right = overflow_dst; |
+ } |
+ |
+ if (dst.is(left)) { |
+ mov(scratch, left); // Preserve left. |
+ daddu(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. |
+ daddu(dst, left, right); // Right is overwritten. |
+ xor_(scratch, dst, scratch); // Original right. |
+ xor_(overflow_dst, dst, left); |
+ and_(overflow_dst, overflow_dst, scratch); |
+ } else { |
+ daddu(dst, left, right); |
+ xor_(overflow_dst, dst, left); |
+ xor_(scratch, dst, right); |
+ and_(overflow_dst, scratch, overflow_dst); |
+ } |
+ BranchOvfHelper(this, overflow_dst, overflow_label, no_overflow_label); |
+} |
+ |
+ |
void MacroAssembler::SubuAndCheckForOverflow(Register dst, Register left, |
const Operand& right, |
Register overflow_dst, |
@@ -4861,6 +4944,83 @@ void MacroAssembler::DsubuAndCheckForOverflow(Register dst, Register left, |
} |
} |
+ |
+void MacroAssembler::DsubBranchOvf(Register dst, Register left, |
+ const Operand& right, Label* overflow_label, |
+ Label* no_overflow_label, Register scratch) { |
+ DCHECK(overflow_label || no_overflow_label); |
+ if (right.is_reg()) { |
+ DsubBranchOvf(dst, left, right.rm(), overflow_label, no_overflow_label, |
+ scratch); |
+ } else { |
+ Register overflow_dst = t9; |
+ DCHECK(!dst.is(scratch)); |
+ DCHECK(!dst.is(overflow_dst)); |
+ DCHECK(!scratch.is(overflow_dst)); |
+ DCHECK(!left.is(overflow_dst)); |
+ DCHECK(!left.is(scratch)); |
+ li(overflow_dst, right); // Load right. |
+ if (dst.is(left)) { |
+ mov(scratch, left); // Preserve left. |
+ Dsubu(dst, left, overflow_dst); // Left is overwritten. |
+ xor_(overflow_dst, scratch, overflow_dst); // scratch is original left. |
+ xor_(scratch, dst, scratch); // scratch is original left. |
+ and_(overflow_dst, scratch, overflow_dst); |
+ } else { |
+ Dsubu(dst, left, overflow_dst); |
+ xor_(scratch, left, overflow_dst); |
+ xor_(overflow_dst, dst, left); |
+ and_(overflow_dst, scratch, overflow_dst); |
+ } |
+ BranchOvfHelper(this, overflow_dst, overflow_label, no_overflow_label); |
+ } |
+} |
+ |
+ |
+void MacroAssembler::DsubBranchOvf(Register dst, Register left, Register right, |
+ Label* overflow_label, |
+ Label* no_overflow_label, Register scratch) { |
+ DCHECK(overflow_label || no_overflow_label); |
+ Register overflow_dst = t9; |
+ DCHECK(!dst.is(scratch)); |
+ DCHECK(!dst.is(overflow_dst)); |
+ DCHECK(!scratch.is(overflow_dst)); |
+ 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); |
+ if (no_overflow_label) { |
+ Branch(no_overflow_label); |
+ } |
+ } |
+ |
+ if (dst.is(left)) { |
+ mov(scratch, left); // Preserve left. |
+ dsubu(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. |
+ dsubu(dst, left, right); // Right is overwritten. |
+ xor_(overflow_dst, dst, left); |
+ xor_(scratch, left, scratch); // Original right. |
+ and_(overflow_dst, scratch, overflow_dst); |
+ } else { |
+ dsubu(dst, left, right); |
+ xor_(overflow_dst, dst, left); |
+ xor_(scratch, left, right); |
+ and_(overflow_dst, scratch, overflow_dst); |
+ } |
+ BranchOvfHelper(this, overflow_dst, overflow_label, no_overflow_label); |
+} |
+ |
+ |
void MacroAssembler::CallRuntime(const Runtime::Function* f, int num_arguments, |
SaveFPRegsMode save_doubles, |
BranchDelaySlot bd) { |