Bug 913282: Tests
authorBenjamin Bouvier <benj@benj.me>
Tue, 22 Oct 2013 14:58:21 +0200
changeset 166451 b3056780fa816cdb8649e1ca95607cead17da525
parent 166450 0267af0f436625d3d847b569ace2effa83865ce2
child 166452 6bedc085975507a4f3aa025f45ea2a4116186e8b
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs913282
milestone27.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 913282: Tests
js/src/jit-test/tests/ion/testFloat32-correctness.js
js/src/jit-test/tests/ion/testFloat32.js
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/ion/testFloat32-correctness.js
@@ -0,0 +1,171 @@
+setJitCompilerOption("ion.usecount.trigger", 50);
+
+var f32 = new Float32Array(10);
+
+function test(setup, f) {
+    if (f === undefined) {
+        f = setup;
+        setup = function(){};
+    }
+    setup();
+    for(var n = 200; n; --n) {
+        f();
+    }
+}
+
+// Basic arithmetic
+function setupBasicArith() {
+    f32[0] = -Infinity;
+    f32[1] = -1;
+    f32[2] = -0;
+    f32[3] = 0;
+    f32[4] = 1.337;
+    f32[5] = 42;
+    f32[6] = Infinity;
+    f32[7] = NaN;
+}
+function basicArith() {
+    for (var i = 0; i < 7; ++i) {
+        var opf = Math.fround(f32[i] + f32[i+1]);
+        var opd = (1 / (1 / f32[i])) + f32[i+1];
+        assertFloat32(opf, true);
+        assertFloat32(opd, false);
+        assertEq(opf, Math.fround(opd));
+
+        opf = Math.fround(f32[i] - f32[i+1]);
+        opd = (1 / (1 / f32[i])) - f32[i+1];
+        assertFloat32(opf, true);
+        assertFloat32(opd, false);
+        assertEq(opf, Math.fround(opd));
+
+        opf = Math.fround(f32[i] * f32[i+1]);
+        opd = (1 / (1 / f32[i])) * f32[i+1];
+        assertFloat32(opf, true);
+        assertFloat32(opd, false);
+        assertEq(opf, Math.fround(opd));
+
+        opf = Math.fround(f32[i] / f32[i+1]);
+        opd = (1 / (1 / f32[i])) / f32[i+1];
+        assertFloat32(opf, true);
+        assertFloat32(opd, false);
+        assertEq(opf, Math.fround(opd));
+    }
+}
+test(setupBasicArith, basicArith);
+
+// MAbs
+function setupAbs() {
+    f32[0] = -0;
+    f32[1] = 0;
+    f32[2] = -3.14159;
+    f32[3] = 3.14159;
+    f32[4] = -Infinity;
+    f32[5] = Infinity;
+    f32[6] = NaN;
+}
+function abs() {
+    for(var i = 0; i < 7; ++i) {
+        assertEq( Math.fround(Math.abs(f32[i])), Math.abs(f32[i]) );
+    }
+}
+test(setupAbs, abs);
+
+// MSqrt
+function setupSqrt() {
+    f32[0] = 0;
+    f32[1] = 1;
+    f32[2] = 4;
+    f32[3] = -1;
+    f32[4] = Infinity;
+    f32[5] = NaN;
+    f32[6] = 13.37;
+}
+function sqrt() {
+    for(var i = 0; i < 7; ++i) {
+        var sqrtf = Math.fround(Math.sqrt(f32[i]));
+        var sqrtd = 1 + Math.sqrt(f32[i]) - 1; // force no float32 by chaining arith ops
+        assertEq( sqrtf, Math.fround(sqrtd) );
+    }
+}
+test(setupSqrt, sqrt);
+
+// MTruncateToInt32
+// The only way to get a MTruncateToInt32 with a Float32 input is to use Math.imul
+function setupTruncateToInt32() {
+    f32[0] = -1;
+    f32[1] = 4;
+    f32[2] = 5.13;
+}
+function truncateToInt32() {
+    assertEq( Math.imul(f32[0], f32[1]), Math.imul(-1, 4) );
+    assertEq( Math.imul(f32[1], f32[2]), Math.imul(4, 5) );
+}
+test(setupTruncateToInt32, truncateToInt32);
+
+// MCompare
+function comp() {
+    for(var i = 0; i < 9; ++i) {
+        assertEq( f32[i] < f32[i+1], true );
+    }
+}
+function setupComp() {
+    f32[0] = -Infinity;
+    f32[1] = -1;
+    f32[2] = -0.01;
+    f32[3] = 0;
+    f32[4] = 0.01;
+    f32[5] = 1;
+    f32[6] = 10;
+    f32[7] = 13.37;
+    f32[8] = 42;
+    f32[9] = Infinity;
+}
+test(setupComp, comp);
+
+// MNot
+function setupNot() {
+    f32[0] = -0;
+    f32[1] = 0;
+    f32[2] = 1;
+    f32[3] = NaN;
+    f32[4] = Infinity;
+    f32[5] = 42;
+    f32[5] = -23;
+}
+function not() {
+    assertEq( !f32[0], true );
+    assertEq( !f32[1], true );
+    assertEq( !f32[2], false );
+    assertEq( !f32[3], true );
+    assertEq( !f32[4], false );
+    assertEq( !f32[5], false );
+    assertEq( !f32[6], false );
+}
+test(setupNot, not);
+
+// MToInt32
+var str = "can haz cheezburger? okthxbye;";
+function setupToInt32() {
+    f32[0] = 0;
+    f32[1] = 1;
+    f32[2] = 2;
+    f32[3] = 4;
+    f32[4] = 5;
+}
+function testToInt32() {
+    assertEq(str[f32[0]], 'c');
+    assertEq(str[f32[1]], 'a');
+    assertEq(str[f32[2]], 'n');
+    assertEq(str[f32[3]], 'h');
+    assertEq(str[f32[4]], 'a');
+}
+test(setupToInt32, testToInt32);
+
+function setupBailoutToInt32() {
+    f32[0] = .5;
+}
+function testBailoutToInt32() {
+    assertEq(typeof str[f32[0]], 'undefined');
+}
+test(setupBailoutToInt32, testBailoutToInt32);
+
--- a/js/src/jit-test/tests/ion/testFloat32.js
+++ b/js/src/jit-test/tests/ion/testFloat32.js
@@ -50,17 +50,17 @@
 // would be guarded against modifications (typeguard on Math and then on fround). In this case, Math.fround is
 // not inlined and the compiler will consider the return value to be a double, not a float32, making the
 // assertions fail. Note that as assertFloat32 is declared unsafe for fuzzing, this can't happen in fuzzed code.
 //
 // To be able to test it, we still need ion compilation though. A nice solution is to manually lower the ion usecount.
 setJitCompilerOption("ion.usecount.trigger", 50);
 
 function test(f) {
-    f32[0] = 1;
+    f32[0] = .5;
     for(var n = 110; n; n--)
         f();
 }
 
 var f32 = new Float32Array(2);
 var f64 = new Float64Array(2);
 
 function acceptAdd() {
@@ -131,16 +131,44 @@ test(refuseAddSeveral);
 function refuseAddFunctionCall() {
     function plusOne(x) { return Math.cos(x+1)*13.37; }
     var res = plusOne(f32[0]); // func call is not a consumer
     f32[0] = res;
     assertFloat32(res, false);
 }
 test(refuseAddFunctionCall);
 
+function acceptSqrt() {
+    var res = Math.sqrt(f32[0]);
+    assertFloat32(res, true);
+    f32[0] = res;
+}
+test(acceptSqrt);
+
+function refuseSqrt() {
+    var res = Math.sqrt(f32[0]);
+    assertFloat32(res, false);
+    f32[0] = res + 1;
+}
+test(refuseSqrt);
+
+function acceptAbs() {
+    var res = Math.abs(f32[0]);
+    assertFloat32(res, true);
+    f32[0] = res;
+}
+test(acceptAbs);
+
+function refuseAbs() {
+    var res = Math.abs(f32[0]);
+    assertFloat32(res, false);
+    f64[0] = res + 1;
+}
+test(refuseAbs);
+
 function acceptTrigo() {
     var res = Math.cos(f32[0]);
     f32[0] = res;
     assertFloat32(res, true);
 
     var res = Math.sin(f32[0]);
     f32[0] = res;
     assertFloat32(res, true);