Bug 865931 - Fix varous minor problems with the comparison routines, add test r=shu
authorNicholas D. Matsakis <nmatsakis@mozilla.com>
Wed, 08 May 2013 21:36:20 -0400
changeset 142378 262cf57a8aa746530e58ab049ccf69d28893eadd
parent 142377 f7c710fa3295634ccfe4f7c81733d9876504609b
child 142379 db1de122b2620f1f19bb97962290310b80419e19
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshu
bugs865931
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 865931 - Fix varous minor problems with the comparison routines, add test r=shu
js/src/ion/ParallelArrayAnalysis.cpp
js/src/ion/ParallelFunctions.cpp
js/src/jit-test/lib/parallelarray-helpers.js
js/src/jit-test/tests/parallelarray/compare-values.js
--- a/js/src/ion/ParallelArrayAnalysis.cpp
+++ b/js/src/ion/ParallelArrayAnalysis.cpp
@@ -112,17 +112,17 @@ class ParallelArrayVisitor : public MIns
     // obviously safe for now.  We can loosen as we need.
 
     SAFE_OP(Constant)
     SAFE_OP(Parameter)
     SAFE_OP(Callee)
     SAFE_OP(TableSwitch)
     SAFE_OP(Goto)
     CUSTOM_OP(Test)
-    CUSTOM_OP(Compare)
+    SAFE_OP(Compare)
     SAFE_OP(Phi)
     SAFE_OP(Beta)
     UNSAFE_OP(OsrValue)
     UNSAFE_OP(OsrScopeChain)
     UNSAFE_OP(ReturnFromCtor)
     CUSTOM_OP(CheckOverRecursed)
     UNSAFE_OP(DefVar)
     UNSAFE_OP(DefFun)
@@ -488,40 +488,16 @@ ParallelCompileContext::replaceOperandsO
 
 bool
 ParallelArrayVisitor::visitTest(MTest *)
 {
     return true;
 }
 
 bool
-ParallelArrayVisitor::visitCompare(MCompare *compare)
-{
-    MCompare::CompareType type = compare->compareType();
-
-    switch (type) {
-      case MCompare::Compare_Int32:
-      case MCompare::Compare_Double:
-      case MCompare::Compare_Null:
-      case MCompare::Compare_Undefined:
-      case MCompare::Compare_Boolean:
-      case MCompare::Compare_Object:
-      case MCompare::Compare_Value:
-      case MCompare::Compare_Unknown:
-      case MCompare::Compare_String:
-        // These paths through compare are ok in any mode.
-        return true;
-
-      default:
-        SpewMIR(compare, "unsafe compareType=%d\n", type);
-        return markUnsafe();
-    }
-}
-
-bool
 ParallelArrayVisitor::convertToBailout(MBasicBlock *block, MInstruction *ins)
 {
     JS_ASSERT(unsafe()); // `block` must have contained unsafe items
     JS_ASSERT(block->isMarked()); // `block` must have been reachable to get here
 
     // Clear the unsafe flag for subsequent blocks.
     clearUnsafe();
 
--- a/js/src/ion/ParallelFunctions.cpp
+++ b/js/src/ion/ParallelFunctions.cpp
@@ -305,17 +305,18 @@ ParStrictlyEqualImpl(ForkJoinSlice *slic
             *res = (lhs.toObjectOrNull() == rhs.toObjectOrNull()) == Equal;
             return TP_SUCCESS;
         }
     } else if (lhs.isString()) {
         if (rhs.isString())
             return ParLooselyEqualImpl<Equal>(slice, lhs, rhs, res);
     }
 
-    return TP_RETRY_SEQUENTIALLY;
+    *res = false;
+    return TP_SUCCESS;
 }
 
 ParallelResult
 js::ion::ParStrictlyEqual(ForkJoinSlice *slice, MutableHandleValue lhs, MutableHandleValue rhs, JSBool *res)
 {
     return ParStrictlyEqualImpl<true>(slice, lhs, rhs, res);
 }
 
--- a/js/src/jit-test/lib/parallelarray-helpers.js
+++ b/js/src/jit-test/lib/parallelarray-helpers.js
@@ -141,20 +141,21 @@ function assertEqParallelArray(a, b) {
       assertStructuralEq(e1, e2);
     } catch (e) {
       print("...in indices ", iv, " of ", shape);
       throw e;
     }
   } while (bump(iv));
 }
 
-function assertParallelArrayModesEq(modes, acc, opFunction, cmpFunction) {
+function assertParallelArrayModesEq(modes, acc, opFunction, cmpFunction, expect) {
   if (!cmpFunction) { cmpFunction = assertStructuralEq; }
+  if (!expect) { expect = "success"; }
   modes.forEach(function (mode) {
-    var result = opFunction({ mode: mode, expect: "success" });
+    var result = opFunction({ mode: mode, expect: expect });
     cmpFunction(acc, result);
   });
 }
 
 function assertParallelArrayModesCommute(modes, opFunction) {
     var acc = opFunction({ mode: modes[0], expect: "success" });
     assertParallelArrayModesEq(modes.slice(1), acc, opFunction);
 }
@@ -172,29 +173,29 @@ function comparePerformance(opts) {
 
     for (var i = 1; i < opts.length; i++) {
         var rel = (measurements[i] - measurements[0]) * 100 / measurements[0];
         print("Option " + opts[i].name + " relative to option " +
               opts[0].name + ": " + (rel|0) + "%");
     }
 }
 
-function compareAgainstArray(jsarray, opname, func, cmpFunction) {
+function compareAgainstArray(jsarray, opname, func, cmpFunction, expect) {
   var expected = jsarray[opname].apply(jsarray, [func]);
   var parray = new ParallelArray(jsarray);
 
   // Unfortunately, it sometimes happens that running 'par' twice in a
   // row causes bailouts and other unfortunate things!
 
   assertParallelArrayModesEq(["seq", "par", "par"], expected, function(m) {
     print(m.mode + " " + m.expect);
     var result = parray[opname].apply(parray, [func, m]);
     // print(result.toString());
     return result;
-  }, cmpFunction);
+  }, cmpFunction, expect);
 }
 
 function testFilter(jsarray, func, cmpFunction) {
   compareAgainstArray(jsarray, "filter", func, cmpFunction);
 
   // var expected = jsarray.filter(func);
   // var filters = jsarray.map(func);
   // var parray = new ParallelArray(jsarray);
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/parallelarray/compare-values.js
@@ -0,0 +1,47 @@
+load(libdir + "parallelarray-helpers.js");
+
+// Test that we are able to compare numbers even if the typesets are
+// not "clean" because we have previously added strings and numbers.
+// Also test that we distinguish between bools/numbers etc for strict
+// equality but not loose equality.
+
+function theTest() {
+  var ints = range(0, 1024);
+  var doubles = ints.map(v => v + 0.1);
+  var bools = ints.map(v => (v % 2) == 0);
+  var strings = ints.map(v => String(v));
+
+  function looselyCompareToDoubles(e, i) {
+    return doubles[i] == e;
+  }
+  print("doubles");
+  compareAgainstArray(doubles, "map", looselyCompareToDoubles)
+  print("bools");
+  compareAgainstArray(bools, "map", looselyCompareToDoubles,
+                      assertStructuralEq, "mixed")
+  // ion bails out when converting a string to a double right now,
+  // so par exec cannot proceed
+  print("strings");
+  compareAgainstArray(strings, "map", looselyCompareToDoubles,
+                      assertStructuralEq, "disqualified")
+  print("ints");
+  compareAgainstArray(ints, "map", looselyCompareToDoubles)
+
+  function strictlyCompareToDoubles(e, i) {
+    return doubles[i] === e;
+  }
+  print("doubles, strict");
+  compareAgainstArray(doubles, "map", strictlyCompareToDoubles,
+                     assertStructuralEq, "mixed")
+  print("bools, strict");
+  compareAgainstArray(bools, "map", strictlyCompareToDoubles,
+                      assertStructuralEq, "mixed")
+  print("strings, strict");
+  compareAgainstArray(strings, "map", strictlyCompareToDoubles,
+                      assertStructuralEq, "mixed")
+  print("ints, strict");
+  compareAgainstArray(ints, "map", strictlyCompareToDoubles)
+}
+
+if (getBuildConfiguration().parallelJS)
+  theTest();