michael@0: // Fuzz tests michael@0: (function(){ michael@0: // michael@0: (function(){ michael@0: var g = {}; michael@0: x = new Float32Array() michael@0: Function('g', "g.o = x[1]")(g); michael@0: })(); michael@0: // michael@0: (function() { michael@0: var g = new Float32Array(16); michael@0: var h = new Float64Array(16); michael@0: var farrays = [ g, h ]; michael@0: for (aridx = 0; aridx < farrays.length; ++aridx) { michael@0: ar = farrays[aridx]; michael@0: !(ar[ar.length-2] == (NaN / Infinity)[ar.length-2]) michael@0: } michael@0: })(); michael@0: // michael@0: (function () { michael@0: var v = new Float32Array(32); michael@0: for (var i = 0; i < v.length; ++i) michael@0: v[i] = i; michael@0: var t = (false ); michael@0: for (var i = 0; i < i .length; ++i) michael@0: t += v[i]; michael@0: })(); michael@0: // michael@0: (function() { michael@0: if (typeof ParallelArray !== "undefined") michael@0: ParallelArray([1606], Math.fround) michael@0: })(); michael@0: // michael@0: (function() { michael@0: x = y = {}; michael@0: z = new Float32Array(6) michael@0: for (c in this) { michael@0: Array.prototype.unshift.call(x, new ArrayBuffer()) michael@0: } michael@0: Array.prototype.sort.call(x, (function (j) { michael@0: y.s = z[2] michael@0: })) michael@0: })(); michael@0: // michael@0: })(); michael@0: // michael@0: // ION TESTS michael@0: // michael@0: // The assertFloat32 function is deactivated in --ion-eager mode, as the first time, the function Math.fround michael@0: // would be guarded against modifications (typeguard on Math and then on fround). In this case, Math.fround is michael@0: // not inlined and the compiler will consider the return value to be a double, not a float32, making the michael@0: // assertions fail. Note that as assertFloat32 is declared unsafe for fuzzing, this can't happen in fuzzed code. michael@0: // michael@0: // To be able to test it, we still need ion compilation though. A nice solution is to manually lower the ion usecount. michael@0: setJitCompilerOption("ion.usecount.trigger", 50); michael@0: michael@0: function test(f) { michael@0: f32[0] = .5; michael@0: for(var n = 110; n; n--) michael@0: f(); michael@0: } michael@0: michael@0: var f32 = new Float32Array(2); michael@0: var f64 = new Float64Array(2); michael@0: michael@0: function acceptAdd() { michael@0: var use = f32[0] + 1; michael@0: assertFloat32(use, true); michael@0: f32[0] = use; michael@0: } michael@0: test(acceptAdd); michael@0: michael@0: function acceptAddSeveral() { michael@0: var sum1 = f32[0] + 0.5; michael@0: var sum2 = f32[0] + 0.5; michael@0: f32[0] = sum1; michael@0: f32[0] = sum2; michael@0: assertFloat32(sum1, true); michael@0: assertFloat32(sum2, true); michael@0: } michael@0: test(acceptAddSeveral); michael@0: michael@0: function acceptAddVar() { michael@0: var x = f32[0] + 1; michael@0: f32[0] = x; michael@0: f32[1] = x; michael@0: assertFloat32(x, true); michael@0: } michael@0: test(acceptAddVar); michael@0: michael@0: function refuseAddCst() { michael@0: var x = f32[0] + 1234567890; // this constant can't be precisely represented as a float32 michael@0: f32[0] = x; michael@0: assertFloat32(x, false); michael@0: } michael@0: test(refuseAddCst); michael@0: michael@0: function refuseAddVar() { michael@0: var x = f32[0] + 1; michael@0: f32[0] = x; michael@0: f32[1] = x; michael@0: f64[1] = x; // non consumer michael@0: assertFloat32(x, false); michael@0: } michael@0: test(refuseAddVar); michael@0: michael@0: function refuseAddStore64() { michael@0: var x = f32[0] + 1; michael@0: f64[0] = x; // non consumer michael@0: f32[0] = f64[0]; michael@0: assertFloat32(x, false); michael@0: } michael@0: test(refuseAddStore64); michael@0: michael@0: function refuseAddStoreObj() { michael@0: var o = {} michael@0: var x = f32[0] + 1; michael@0: o.x = x; // non consumer michael@0: f32[0] = o['x']; michael@0: assertFloat32(x, false); michael@0: } michael@0: test(refuseAddStoreObj); michael@0: michael@0: function refuseAddSeveral() { michael@0: var sum = (f32[0] + 2) - 1; // second addition is not a consumer michael@0: f32[0] = sum; michael@0: assertFloat32(sum, false); michael@0: } michael@0: test(refuseAddSeveral); michael@0: michael@0: function refuseAddFunctionCall() { michael@0: function plusOne(x) { return Math.cos(x+1)*13.37; } michael@0: var res = plusOne(f32[0]); // func call is not a consumer michael@0: f32[0] = res; michael@0: assertFloat32(res, false); michael@0: } michael@0: test(refuseAddFunctionCall); michael@0: michael@0: function acceptSqrt() { michael@0: var res = Math.sqrt(f32[0]); michael@0: assertFloat32(res, true); michael@0: f32[0] = res; michael@0: } michael@0: test(acceptSqrt); michael@0: michael@0: function refuseSqrt() { michael@0: var res = Math.sqrt(f32[0]); michael@0: assertFloat32(res, false); michael@0: f32[0] = res + 1; michael@0: } michael@0: test(refuseSqrt); michael@0: michael@0: function acceptAbs() { michael@0: var res = Math.abs(f32[0]); michael@0: assertFloat32(res, true); michael@0: f32[0] = res; michael@0: } michael@0: test(acceptAbs); michael@0: michael@0: function refuseAbs() { michael@0: var res = Math.abs(f32[0]); michael@0: assertFloat32(res, false); michael@0: f64[0] = res + 1; michael@0: } michael@0: test(refuseAbs); michael@0: michael@0: function refuseTrigo() { michael@0: var res = Math.cos(f32[0]); michael@0: f32[0] = res; michael@0: assertFloat32(res, false); michael@0: michael@0: var res = Math.sin(f32[0]); michael@0: f32[0] = res; michael@0: assertFloat32(res, false); michael@0: michael@0: var res = Math.tan(f32[0]); michael@0: f32[0] = res; michael@0: assertFloat32(res, false); michael@0: michael@0: var res = Math.acos(f32[0]); michael@0: f32[0] = res; michael@0: assertFloat32(res, false); michael@0: michael@0: var res = Math.asin(f32[0]); michael@0: f32[0] = res; michael@0: assertFloat32(res, false); michael@0: michael@0: res = Math.atan(f32[0]); michael@0: f32[0] = res; michael@0: assertFloat32(res, false); michael@0: } michael@0: test(refuseTrigo); michael@0: michael@0: function refuseMath() { michael@0: var res = Math.log10(f32[0]); michael@0: f32[0] = res; michael@0: assertFloat32(res, false); michael@0: michael@0: res = Math.log2(f32[0]); michael@0: f32[0] = res; michael@0: assertFloat32(res, false); michael@0: michael@0: res = Math.log1p(f32[0]); michael@0: f32[0] = res; michael@0: assertFloat32(res, false); michael@0: michael@0: res = Math.expm1(f32[0]); michael@0: f32[0] = res; michael@0: assertFloat32(res, false); michael@0: michael@0: res = Math.cosh(f32[0]); michael@0: f32[0] = res; michael@0: assertFloat32(res, false); michael@0: michael@0: res = Math.sinh(f32[0]); michael@0: f32[0] = res; michael@0: assertFloat32(res, false); michael@0: michael@0: res = Math.tanh(f32[0]); michael@0: f32[0] = res; michael@0: assertFloat32(res, false); michael@0: michael@0: res = Math.acosh(f32[0]); michael@0: f32[0] = res; michael@0: assertFloat32(res, false); michael@0: michael@0: res = Math.asinh(f32[0]); michael@0: f32[0] = res; michael@0: assertFloat32(res, false); michael@0: michael@0: res = Math.atanh(f32[0]); michael@0: f32[0] = res; michael@0: assertFloat32(res, false); michael@0: michael@0: res = Math.cbrt(f32[0]); michael@0: f32[0] = res; michael@0: assertFloat32(res, false); michael@0: michael@0: res = Math.sign(f32[0]); michael@0: f32[0] = res; michael@0: assertFloat32(res, false); michael@0: michael@0: res = Math.trunc(f32[0]); michael@0: f32[0] = res; michael@0: assertFloat32(res, false); michael@0: } michael@0: test(refuseMath); michael@0: michael@0: function refuseLoop() { michael@0: var res = f32[0], michael@0: n = 10; michael@0: while (n--) { michael@0: res = res + 1; // this loop is equivalent to several additions => second addition is not a consumer michael@0: assertFloat32(res, false); michael@0: } michael@0: assertFloat32(res, false); michael@0: f32[0] = res; michael@0: } michael@0: test(refuseLoop); michael@0: michael@0: function acceptLoop() { michael@0: var res = f32[0], michael@0: n = 10; michael@0: while (n--) { michael@0: var sum = res + 1; michael@0: res = Math.fround(sum); michael@0: assertFloat32(sum, true); michael@0: } michael@0: assertFloat32(res, true); michael@0: f32[0] = res; michael@0: } michael@0: test(acceptLoop); michael@0: michael@0: function alternateCond(n) { michael@0: var x = f32[0]; michael@0: if (n > 0) { michael@0: var s1 = x + 1; michael@0: f32[0] = s1; michael@0: assertFloat32(s1, true); michael@0: } else { michael@0: var s2 = x + 1; michael@0: f64[0] = s2; // non consumer michael@0: assertFloat32(s2, false); michael@0: } michael@0: } michael@0: (function() { michael@0: f32[0] = 0; michael@0: for (var n = 110; n; n--) { michael@0: alternateCond(n % 2); michael@0: } michael@0: })(); michael@0: michael@0: function phiTest(n) { michael@0: var x = (f32[0]); michael@0: var y = n; michael@0: if (n > 0) { michael@0: x = x + 2; michael@0: assertFloat32(x, true); michael@0: } else { michael@0: if (n < -10) { michael@0: x = Math.fround(Math.sqrt(y)); michael@0: assertFloat32(x, true); michael@0: } else { michael@0: x = x - 1; michael@0: assertFloat32(x, true); michael@0: } michael@0: } michael@0: assertFloat32(x, true); michael@0: f32[0] = x; michael@0: } michael@0: (function() { michael@0: f32[0] = 0; michael@0: for (var n = 100; n; n--) { michael@0: phiTest( ((n % 3) - 1) * 15 ); michael@0: } michael@0: })(); michael@0: michael@0: function mixedPhiTest(n) { michael@0: var x = (f32[0]); michael@0: var y = n; michael@0: if (n > 0) { michael@0: x = x + 2; // non consumer because of (1) michael@0: assertFloat32(x, false); michael@0: } else { michael@0: if (n < -10) { michael@0: x = Math.fround(Math.sqrt(y)); // new producer michael@0: assertFloat32(x, true); michael@0: } else { michael@0: x = x - 1; // non consumer because of (1) michael@0: assertFloat32(x, false); michael@0: } michael@0: } michael@0: assertFloat32(x, false); michael@0: x = x + 1; // (1) non consumer michael@0: f32[0] = x; michael@0: } michael@0: (function() { michael@0: f32[0] = 0; michael@0: for (var n = 100; n; n--) { michael@0: mixedPhiTest( ((n % 3) - 1) * 15 ); michael@0: } michael@0: })(); michael@0: michael@0: function phiTest2(n) { michael@0: var x = f32[0]; michael@0: while (n >= 0) { michael@0: x = Math.fround(Math.fround(x) + 1); michael@0: assertFloat32(x, true); michael@0: if (n < 10) { michael@0: x = f32[0] + 1; michael@0: assertFloat32(x, true); michael@0: } michael@0: n = n - 1; michael@0: } michael@0: } michael@0: (function(){ michael@0: f32[0] = 0; michael@0: for (var n = 100; n > 10; n--) { michael@0: phiTest2(n); michael@0: } michael@0: })();