Reviewers: Jakob Kummerow, Benedikt Meurer, paul.l..., akos.palfi.imgtec, balazs.kilvady,

Message:
PTAL.

Description:
MIPS64: Fix random failures of fannkuch.js.

TEST=mjsunit/asm/embenchen/fannkuch,
     mjsunit/math-abs
BUG=

Please review this at https://codereview.chromium.org/1192413002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+36, -3 lines):
  M src/mips64/lithium-codegen-mips64.h
  M src/mips64/lithium-codegen-mips64.cc
  M test/mjsunit/math-abs.js


Index: src/mips64/lithium-codegen-mips64.cc
diff --git a/src/mips64/lithium-codegen-mips64.cc b/src/mips64/lithium-codegen-mips64.cc index 0082a3f50b389b906d7b1f6bd4d37148c5cd132e..c4988f4ec7688c577914bef73b4b5d619e21e486 100644
--- a/src/mips64/lithium-codegen-mips64.cc
+++ b/src/mips64/lithium-codegen-mips64.cc
@@ -3773,13 +3773,27 @@ void LCodeGen::EmitIntegerMathAbs(LMathAbs* instr) {
   Label done;
   __ Branch(USE_DELAY_SLOT, &done, ge, input, Operand(zero_reg));
   __ mov(result, input);
-  __ dsubu(result, zero_reg, input);
+  __ subu(result, zero_reg, input);
   // Overflow if result is still negative, i.e. 0x80000000.
DeoptimizeIf(lt, instr, Deoptimizer::kOverflow, result, Operand(zero_reg));
   __ bind(&done);
 }


+void LCodeGen::EmitSmiMathAbs(LMathAbs* instr) {
+  Register input = ToRegister(instr->value());
+  Register result = ToRegister(instr->result());
+  Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_);
+  Label done;
+  __ Branch(USE_DELAY_SLOT, &done, ge, input, Operand(zero_reg));
+  __ mov(result, input);
+  __ dsubu(result, zero_reg, input);
+  // Overflow if result is still negative, i.e. 0x80000000 00000000.
+ DeoptimizeIf(lt, instr, Deoptimizer::kOverflow, result, Operand(zero_reg));
+  __ bind(&done);
+}
+
+
 void LCodeGen::DoMathAbs(LMathAbs* instr) {
   // Class for deferred case.
   class DeferredMathAbsTaggedHeapNumber final : public LDeferredCode {
@@ -3800,8 +3814,10 @@ void LCodeGen::DoMathAbs(LMathAbs* instr) {
     FPURegister input = ToDoubleRegister(instr->value());
     FPURegister result = ToDoubleRegister(instr->result());
     __ abs_d(result, input);
-  } else if (r.IsSmiOrInteger32()) {
+  } else if (r.IsInteger32()) {
     EmitIntegerMathAbs(instr);
+  } else if (r.IsSmi()) {
+    EmitSmiMathAbs(instr);
   } else {
     // Representation is tagged.
     DeferredMathAbsTaggedHeapNumber* deferred =
@@ -3810,7 +3826,7 @@ void LCodeGen::DoMathAbs(LMathAbs* instr) {
     // Smi check.
     __ JumpIfNotSmi(input, deferred->entry());
     // If smi, handle it directly.
-    EmitIntegerMathAbs(instr);
+    EmitSmiMathAbs(instr);
     __ bind(deferred->exit());
   }
 }
Index: src/mips64/lithium-codegen-mips64.h
diff --git a/src/mips64/lithium-codegen-mips64.h b/src/mips64/lithium-codegen-mips64.h index 904a62cea80e11efa4b255dd50945638b63ee3ad..0afae2dd4652e5a0d2d149ca52dbbb4f9adb922b 100644
--- a/src/mips64/lithium-codegen-mips64.h
+++ b/src/mips64/lithium-codegen-mips64.h
@@ -251,6 +251,7 @@ class LCodeGen: public LCodeGenBase {
                                    String::Encoding encoding);

   void EmitIntegerMathAbs(LMathAbs* instr);
+  void EmitSmiMathAbs(LMathAbs* instr);

   // Support for recording safepoint and position information.
   void RecordSafepoint(LPointerMap* pointers,
Index: test/mjsunit/math-abs.js
diff --git a/test/mjsunit/math-abs.js b/test/mjsunit/math-abs.js
index b90ae0917c4d513c4d880f8a79e71a895dc7986c..09e6416c8b5794ba2ad19ce229523e3ec8e64e70 100644
--- a/test/mjsunit/math-abs.js
+++ b/test/mjsunit/math-abs.js
@@ -120,3 +120,19 @@ assertEquals(1, foo2());
 assertEquals(1, foo2());
 %OptimizeFunctionOnNextCall(foo2);
 assertEquals(1, foo2());
+
+
+// Regression test for Integer input of Math.abs on mips64.
+function absHalf(bits) {
+  var x = 1 << (bits - 1);
+  var half = Math.abs(x);
+  return half;
+
+}
+
+// Create minimum integer input for abs() using bitwise operations
+// that sould overflow.
+bits = 32;
+for (i = 0; i < 1000; i++) {
+  assertEquals(2147483648, absHalf(bits));
+}


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to