Commit be1a5f75 authored by clemensh's avatar clemensh Committed by Commit bot

[asm] Fix lots of invalid asm.js tests

I identified lots of asm.js tests that are actually not valid according
to the spec, hence they execute in default-javascript-mode.
This CL fixes most of them by adding additional type annotations.

The atomic tests are totally non-spec-compliant by expecting a fourth
argument, and infinite-loops-taken expects a function-type parameter,
so I did not fix those.
I also did not fix the regression tests.

R=titzer@chromium.org, bradnelson@chromium.org
BUG=v8:4203

Review-Url: https://codereview.chromium.org/2663243002
Cr-Commit-Position: refs/heads/master@{#43179}
parent 0b287bd4
......@@ -41,11 +41,11 @@ function Module() {
function d6(a) {
a = a | 0;
do {
if (a == 0) return 120;
if (a == 1) break;
if (a == 2) return 122;
if (a == 3) continue;
if (a == 4) return 124;
if ((a | 0) == 0) return 120;
if ((a | 0) == 1) break;
if ((a | 0) == 2) return 122;
if ((a | 0) == 3) continue;
if ((a | 0) == 4) return 124;
} while(false);
return 125;
}
......
......@@ -5,17 +5,17 @@
function Module(stdlib, foreign, buffer) {
"use asm";
function f(i) {
var j;
i = i|0;
var j = 0;
do {
if (i > 0) {
j = i != 0;
if ((i | 0) > 0) {
j = (i | 0) != 0;
i = (i - 1) | 0;
} else {
j = 0;
}
} while (j);
return i;
return i | 0;
}
return {f:f};
}
......
......@@ -12,8 +12,7 @@ var m = (function Module(stdlib, foreign, heap) {
var MEM32 = new stdlib.Float32Array(heap);
function load(i) {
i = i|0;
i = +MEM32[i >> 2];
return i;
return +MEM32[i >> 2];
}
function store(i, v) {
i = i|0;
......@@ -22,8 +21,7 @@ var m = (function Module(stdlib, foreign, heap) {
}
function load8(i) {
i = i|0;
i = +MEM32[i + 8 >> 2];
return i;
return +MEM32[i + 8 >> 2];
}
function store8(i, v) {
i = i|0;
......
......@@ -7,8 +7,7 @@ function Module(stdlib, foreign, heap) {
var MEM32 = new stdlib.Float32Array(heap);
function load(i) {
i = i|0;
i = +MEM32[i >> 2];
return i;
return +MEM32[i >> 2];
}
function store(i, v) {
i = i|0;
......
......@@ -6,8 +6,9 @@ function Module(stdlib, foreign, heap) {
"use asm";
var MEM32 = new stdlib.Float32Array(heap);
function foo(i) {
MEM32[0] = (i >>> 0) / 2;
return MEM32[0];
i = i | 0;
MEM32[0] = +(i >>> 0) / 2.;
return +MEM32[0];
}
return { foo: foo };
}
......
......@@ -12,8 +12,7 @@ var m = (function Module(stdlib, foreign, heap) {
var MEM64 = new stdlib.Float64Array(heap);
function load(i) {
i = i|0;
i = +MEM64[i >> 3];
return i;
return +MEM64[i >> 3];
}
function store(i, v) {
i = i|0;
......@@ -22,8 +21,7 @@ var m = (function Module(stdlib, foreign, heap) {
}
function load8(i) {
i = i|0;
i = +MEM64[i + 8 >> 3];
return i;
return +MEM64[i + 8 >> 3];
}
function store8(i, v) {
i = i|0;
......
......@@ -7,8 +7,7 @@ function Module(stdlib, foreign, heap) {
var MEM64 = new stdlib.Float64Array(heap);
function load(i) {
i = i|0;
i = +MEM64[i >> 3];
return i;
return +MEM64[i >> 3];
}
function store(i, v) {
i = i|0;
......
......@@ -6,8 +6,9 @@ function Module(stdlib, foreign, heap) {
"use asm";
var MEM64 = new stdlib.Float64Array(heap);
function foo(i) {
MEM64[0] = (i >>> 0) / 2;
return MEM64[0];
i = i | 0;
MEM64[0] = +(i >>> 0) / 2.;
return +MEM64[0];
}
return { foo: foo };
}
......
......@@ -10,7 +10,7 @@ function Module(stdlib, foreign, heap) {
}
function f2(i) {
i = +i;
return +(-1 * i);
return +(-1. * i);
}
function f3(i) {
i = +i;
......
......@@ -7,7 +7,7 @@ var if0 = (function Module() {
function if0(i, j) {
i = i|0;
j = j|0;
if (i == 0 ? j == 0 : 0) return 1;
if ((i | 0) == 0 ? (j | 0) == 0 : 0) return 1;
return 0;
}
return {if0: if0};
......@@ -23,7 +23,7 @@ var if1 = (function Module() {
function if1(i, j) {
i = i|0;
j = j|0;
if (i == 0 ? j == 0 : 1) return 0;
if ((i | 0) == 0 ? (j | 0) == 0 : 1) return 0;
return 1;
}
return {if1: if1};
......
......@@ -18,41 +18,55 @@ function Module() {
function if2() {
if (0) return 15;
else return 16;
return 0; // needed for validation
}
function if3() {
if (1) return 17;
else return 18;
return 0; // needed for validation
}
function if4() {
return 1 ? 19 : 20;
return (1 ? 19 : 20) | 0;
}
function if5() {
return 0 ? 21 : 22;
return (0 ? 21 : 22) | 0;
}
function if6() {
var x = 0 ? 23 : 24;
return x;
var x = 0;
x = 0 ? 23 : 24;
return x | 0;
}
function if7() {
if (0) { var x = 0 ? 25 : 26; }
else { var x = 0 ? 27 : 28; }
return x;
var x = 0;
if (0) {
x = 0 ? 25 : 26;
} else {
x = 0 ? 27 : 28;
}
return x | 0;
}
function if8() {
var x = 0;
if (0) {
if (0) { var x = 0 ? 29 : 30; }
else { var x = 0 ? 31 : 32; }
if (0) {
x = 0 ? 29 : 30;
} else {
x = 0 ? 31 : 32;
}
} else {
if (0) { var x = 0 ? 33 : 34; }
else { var x = 0 ? 35 : 36; }
if (0) {
x = 0 ? 33 : 34;
} else {
x = 0 ? 35 : 36;
}
}
return x;
return x | 0;
}
return {if0: if0, if1: if1, if2: if2, if3: if3, if4: if4, if5: if5, if6: if6, if7: if7, if8: if8 };
......@@ -70,25 +84,33 @@ assertEquals(28, m.if7());
assertEquals(36, m.if8());
function Spec(a,b,c) {
function Spec0(stdlib, foreign, heap) {
"use asm";
var xx = a | 0;
var yy = b | 0;
var zz = c | 0;
var xx = foreign.a | 0;
var yy = foreign.b | 0;
var zz = foreign.c | 0;
function f() {
var x = 0;
if (xx) {
if (yy) { var x = zz ? 29 : 30; }
else { var x = zz ? 31 : 32; }
if (yy) {
x = zz ? 29 : 30;
} else {
x = zz ? 31 : 32;
}
} else {
if (yy) { var x = zz ? 33 : 34; }
else { var x = zz ? 35 : 36; }
if (yy) {
x = zz ? 33 : 34;
} else {
x = zz ? 35 : 36;
}
}
return x;
return x | 0;
}
return {f: f};
}
var Spec = (a, b, c) => Spec0(this, {a: a, b: b, c: c});
assertEquals(36, Spec(0,0,0).f());
assertEquals(35, Spec(0,0,1).f());
......
......@@ -6,65 +6,84 @@ function Module() {
"use asm";
function if0() {
var x = 0 ? 11 : 12;
return (x == 11) | 0;
var x = 0;
x = 0 ? 11 : 12;
return ((x | 0) == 11) | 0;
}
function if1() {
var x = 1 ? 13 : 14;
return (x == 13) | 0;
var x = 0;
x = 1 ? 13 : 14;
return ((x | 0) == 13) | 0;
}
function if2() {
var x = 0 ? 15 : 16;
return (x != 15) | 0;
var x = 0;
x = 0 ? 15 : 16;
return ((x | 0) != 15) | 0;
}
function if3() {
var x = 1 ? 17 : 18;
return (x != 17) | 0;
var x = 0;
x = 1 ? 17 : 18;
return ((x | 0) != 17) | 0;
}
function if4() {
var x = 0 ? 19 : 20;
var y = (x == 19) ? 21 : 22;
return y;
var x = 0;
var y = 0;
x = 0 ? 19 : 20;
y = ((x | 0) == 19) ? 21 : 22;
return y | 0;
}
function if5() {
var x = 1 ? 23 : 24;
var y = (x == 23) ? 25 : 26;
return y;
var x = 0;
var y = 0;
x = 1 ? 23 : 24;
y = ((x | 0) == 23) ? 25 : 26;
return y | 0;
}
function if6() {
var x = 0 ? 27 : 28;
var y = (x == 27) ? 29 : 30;
var z = (y == 29) ? 31 : 32;
return z;
var x = 0;
var y = 0;
var z = 0;
x = 0 ? 27 : 28;
y = ((x | 0) == 27) ? 29 : 30;
z = ((y | 0) == 29) ? 31 : 32;
return z | 0;
}
function if7() {
var x = 1 ? 33 : 34;
var y = (x == 33) ? 35 : 36;
var z = (y == 35) ? 37 : 38;
var w = (z == 37) ? 39 : 40;
return w;
var x = 0;
var y = 0;
var z = 0;
var w = 0;
x = 1 ? 33 : 34;
y = ((x | 0) == 33) ? 35 : 36;
z = ((y | 0) == 35) ? 37 : 38;
w = ((z | 0) == 37) ? 39 : 40;
return w | 0;
}
function if8() {
var w = 0;
var x = 0;
var y = 0;
var z = 0;
if (0) {
var x = 0 ? 43 : 44;
var y = (x == 43) ? 45 : 46;
var z = (y == 45) ? 47 : 48;
var w = (z == 47) ? 49 : 50;
x = 0 ? 43 : 44;
y = ((x | 0) == 43) ? 45 : 46;
z = ((y | 0) == 45) ? 47 : 48;
w = ((z | 0) == 47) ? 49 : 50;
} else {
var x = 1 ? 53 : 54;
var y = (x == 53) ? 55 : 56;
var z = (y == 55) ? 57 : 58;
var w = (z == 57) ? 59 : 60;
x = 1 ? 53 : 54;
y = ((x | 0) == 53) ? 55 : 56;
z = ((y | 0) == 55) ? 57 : 58;
w = ((z | 0) == 57) ? 59 : 60;
}
return w;
return w | 0;
}
return {if0: if0, if1: if1, if2: if2, if3: if3, if4: if4, if5: if5, if6: if6, if7: if7, if8: if8 };
......@@ -82,28 +101,33 @@ assertEquals(39, m.if7());
assertEquals(59, m.if8());
function Spec(a,b) {
function Spec0(stdlib, foreign, heap) {
"use asm";
var xx = a | 0;
var yy = b | 0;
var xx = foreign.a | 0;
var yy = foreign.b | 0;
function f() {
var x = 0;
var y = 0;
var z = 0;
var w = 0;
if (xx) {
var x = yy ? 43 : 44;
var y = (x == 43) ? 45 : 46;
var z = (y == 45) ? 47 : 48;
var w = (z == 47) ? 49 : 50;
x = yy ? 43 : 44;
y = ((x | 0) == 43) ? 45 : 46;
z = ((y | 0) == 45) ? 47 : 48;
w = ((z | 0) == 47) ? 49 : 50;
} else {
var x = yy ? 53 : 54;
var y = (x == 53) ? 55 : 56;
var z = (y == 55) ? 57 : 58;
var w = (z == 57) ? 59 : 60;
x = yy ? 53 : 54;
y = ((x | 0) == 53) ? 55 : 56;
z = ((y | 0) == 55) ? 57 : 58;
w = ((z | 0) == 57) ? 59 : 60;
}
return w;
return w | 0;
}
return {f: f};
}
var Spec = (a, b, c) => Spec0(this, {a: a, b: b, c: c});
assertEquals(60, Spec(0,0).f());
assertEquals(59, Spec(0,1).f());
......
......@@ -10,8 +10,8 @@ function Module(stdlib, foreign, heap) {
"use asm";
function foo(i) {
i = i|0;
if (i > 0) {
i = i == 1;
if ((i | 0) > 0) {
i = (i | 0) == 1;
} else {
i = 1;
}
......
......@@ -7,6 +7,7 @@ function counter(x) {
return (function() { if (x-- == 0) throw error;});
}
// TODO(asm): This module is not valid asm.js.
function Module() {
"use asm";
......
......@@ -13,7 +13,7 @@ var m = (function Module(stdlib, foreign, heap) {
function load(i) {
i = i|0;
i = MEM16[i >> 1]|0;
return i;
return i | 0;
}
function store(i, v) {
i = i|0;
......@@ -23,7 +23,7 @@ var m = (function Module(stdlib, foreign, heap) {
function load8(i) {
i = i|0;
i = MEM16[i + 8 >> 1]|0;
return i;
return i | 0;
}
function store8(i, v) {
i = i|0;
......
......@@ -8,19 +8,22 @@ function Module(stdlib, foreign, heap) {
function load(i) {
i = i|0;
i = MEM16[i >> 1] | 0;
return i;
return i | 0;
}
function loadm1() {
return MEM16[-1] | 0;
var i = -1 << 1;
return MEM16[i >> 1] | 0;
return 0;
}
function store(i, v) {
i = i|0;
v = v|0;
i = i | 0;
v = v | 0;
MEM16[i >> 1] = v;
}
function storem1(v) {
v = v|0;
MEM16[-1] = v;
v = v | 0;
var i = -1 << 1;
MEM16[i >> 1] = v;
}
return {load: load, loadm1: loadm1, store: store, storem1: storem1};
}
......
......@@ -6,19 +6,19 @@ function Module(stdlib, foreign, heap) {
"use asm";
function f1(i) {
i = i|0;
return i / 3 | 0;
return (i | 0) / 3 | 0;
}
function f2(i) {
i = i|0;
return i / 13 | 0;
return (i | 0) / 13 | 0;
}
function f3(i) {
i = i|0;
return i / 1024 | 0;
return (i | 0) / 1024 | 0;
}
function f4(i) {
i = i|0;
return i / 3733331 | 0;
return (i | 0) / 3733331 | 0;
}
return { f1: f1, f2: f2, f3: f3, f4: f4 };
}
......
......@@ -6,19 +6,19 @@ function Module(stdlib, foreign, heap) {
"use asm";
function f1(i) {
i = i|0;
return i % 3;
return ((i | 0) % 3) | 0;
}
function f2(i) {
i = i|0;
return i % 9;
return ((i | 0) % 9) | 0;
}
function f3(i) {
i = i|0;
return i % 1024;
return ((i | 0) % 1024) | 0;
}
function f4(i) {
i = i|0;
return i % 3133335;
return ((i | 0) % 3133335) | 0;
}
return { f1: f1, f2: f2, f3: f3, f4: f4 };
}
......@@ -26,8 +26,8 @@ function Module(stdlib, foreign, heap) {
var m = Module(this, {}, new ArrayBuffer(1024));
for (var i = -2147483648; i < 2147483648; i += 3999773) {
assertEquals(i % 3, m.f1(i));
assertEquals(i % 9, m.f2(i));
assertEquals(i % 1024, m.f3(i));
assertEquals(i % 3133335, m.f4(i));
assertEquals((i % 3) | 0, m.f1(i));
assertEquals((i % 9) | 0, m.f2(i));
assertEquals((i % 1024) | 0, m.f3(i));
assertEquals((i % 3133335) | 0, m.f4(i));
}
......@@ -6,19 +6,19 @@ function Module(stdlib, foreign, heap) {
"use asm";
function f1(i) {
i = i|0;
return i * 3 | 0;
return (i | 0) * 3 | 0;
}
function f2(i) {
i = i|0;
return i * 7 | 0;
return (i | 0) * 7 | 0;
}
function f3(i) {
i = i|0;
return i * 1024 | 0;
return (i | 0) * 1024 | 0;
}
function f4(i) {
i = i|0;
return i * 3333339 | 0;
return (i | 0) * 333339 | 0;
}
return { f1: f1, f2: f2, f3: f3, f4: f4 };
}
......@@ -29,5 +29,5 @@ for (var i = -2147483648; i < 2147483648; i += 3999771) {
assertEquals(i * 3 | 0, m.f1(i));
assertEquals(i * 7 | 0, m.f2(i));
assertEquals(i * 1024 | 0, m.f3(i));
assertEquals(i * 3333339 | 0, m.f4(i));
assertEquals(i * 333339 | 0, m.f4(i));
}
......@@ -6,23 +6,23 @@ function Module(stdlib, foreign, heap) {
"use asm";
function f0(i) {
i = i|0;
return i % 2 | 0;
return (i | 0) % 2 | 0;
}
function f1(i) {
i = i|0;
return i % 3 | 0;
return (i | 0) % 3 | 0;
}
function f2(i) {
i = i|0;
return i % 9 | 0;
return (i | 0) % 9 | 0;
}
function f3(i) {
i = i|0;
return i % 1024 | 0;
return (i | 0) % 1024 | 0;
}
function f4(i) {
i = i|0;
return i % 3333339 | 0;
return (i | 0) % 3333339 | 0;
}
return { f0: f0, f1: f1, f2: f2, f3: f3, f4: f4 };
}
......
......@@ -5,20 +5,20 @@
function Module(stdlib, foreign, heap) {
"use asm";
function f1(i) {
i = i>>>0;
return i / 3 | 0;
i = i | 0;
return (i >>> 0) / 3 | 0;
}
function f2(i) {
i = i>>>0;
return i / 17 | 0;
i = i | 0;
return (i >>> 0) / 17 | 0;
}
function f3(i) {
i = i>>>0;
return i / 1024 | 0;
i = i | 0;
return (i >>> 0) / 1024 | 0;
}
function f4(i) {
i = i>>>0;
return i / 3343330 | 0;
i = i | 0;
return (i >>> 0) / 3343330 | 0;
}
return { f1: f1, f2: f2, f3: f3, f4: f4 };
}
......
......@@ -5,20 +5,20 @@
function Module(stdlib, foreign, heap) {
"use asm";
function f1(i) {
i = i>>>0;
return i % 3;
i = i | 0;
return (i >>> 0) % 3 | 0;
}
function f2(i) {
i = i>>>0;
return i % 11;
i = i | 0;
return (i >>> 0) % 11 | 0;
}
function f3(i) {
i = i>>>0;
return i % 1024;
i = i | 0;
return (i >>> 0) % 1024 | 0;
}
function f4(i) {
i = i>>>0;
return i % 3333337;
i = i | 0;
return (i >>> 0) % 3333337 | 0;
}
return { f1: f1, f2: f2, f3: f3, f4: f4 };
}
......
......@@ -6,28 +6,34 @@ function Module(stdlib, foreign, heap) {
"use asm";
var MEM32 = new stdlib.Int32Array(heap);
function loadm4194304() {
return MEM32[-4194304];
var i = -4194304 << 2;
return MEM32[i >> 2] | 0;
}
function loadm0() {
return MEM32[-0];
return MEM32[-0] | 0;
}
function load0() {
return MEM32[0];
return MEM32[0] | 0;
}
function load4() {
return MEM32[4];
return MEM32[4] | 0;
}
function storem4194304(v) {
MEM32[-4194304] = v;
v = v | 0;
var i = -4194304 << 2;
MEM32[i >> 2] = v;
}
function storem0(v) {
v = v | 0;
MEM32[-0] = v;
}
function store0(v) {
MEM32[0] = v;
v = v | 0;
MEM32[0 >> 2] = v;
}
function store4(v) {
MEM32[4] = v;
v = v | 0;
MEM32[(4 << 2) >> 2] = v;
}
return { loadm4194304: loadm4194304, storem4194304: storem4194304,
loadm0: loadm0, storem0: storem0, load0: load0, store0: store0,
......@@ -36,27 +42,27 @@ function Module(stdlib, foreign, heap) {
var m = Module(this, {}, new ArrayBuffer(4));
assertEquals(undefined, m.loadm4194304());
assertEquals(0, m.loadm4194304());
assertEquals(0, m.loadm0());
assertEquals(0, m.load0());
assertEquals(undefined, m.load4());
assertEquals(0, m.load4());
m.storem4194304(123456789);
assertEquals(undefined, m.loadm4194304());
assertEquals(0, m.loadm4194304());
assertEquals(0, m.loadm0());
assertEquals(0, m.load0());
assertEquals(undefined, m.load4());
assertEquals(0, m.load4());
m.storem0(987654321);
assertEquals(undefined, m.loadm4194304());
assertEquals(0, m.loadm4194304());
assertEquals(987654321, m.loadm0());
assertEquals(987654321, m.load0());
assertEquals(undefined, m.load4());
assertEquals(0, m.load4());
m.store0(0x12345678);
assertEquals(undefined, m.loadm4194304());
assertEquals(0, m.loadm4194304());
assertEquals(0x12345678, m.loadm0());
assertEquals(0x12345678, m.load0());
assertEquals(undefined, m.load4());
assertEquals(0, m.load4());
m.store4(43);
assertEquals(undefined, m.loadm4194304());
assertEquals(0, m.loadm4194304());
assertEquals(0x12345678, m.loadm0());
assertEquals(0x12345678, m.load0());
assertEquals(undefined, m.load4());
assertEquals(0, m.load4());
......@@ -13,7 +13,7 @@ var m = (function Module(stdlib, foreign, heap) {
function load(i) {
i = i|0;
i = MEM32[i >> 2]|0;
return i;
return i | 0;
}
function store(i, v) {
i = i|0;
......@@ -23,7 +23,7 @@ var m = (function Module(stdlib, foreign, heap) {
function load8(i) {
i = i|0;
i = MEM32[i + 8 >> 2]|0;
return i;
return i | 0;
}
function store8(i, v) {
i = i|0;
......
......@@ -8,7 +8,7 @@ function Module(stdlib, foreign, heap) {
function load(i) {
i = i|0;
i = MEM32[i >> 2] | 0;
return i;
return i | 0;
}
function store(i, v) {
i = i|0;
......
......@@ -8,7 +8,7 @@ function Module(stdlib, foreign, heap) {
function load(i) {
i = i|0;
i = MEM32[i >> 2] | 0;
return i;
return i | 0;
}
function store(i, v) {
i = i|0;
......
......@@ -12,13 +12,15 @@ function Int32Div(divisor) {
name += "minus_";
}
name += Math.abs(divisor);
var m = eval("function Module(stdlib, foreign, heap) {\n"
+ " \"use asm\";\n"
+ " function " + name + "(dividend) {\n"
+ " return ((dividend | 0) / " + divisor + ") | 0;\n"
+ " }\n"
+ " return { f: " + name + "}\n"
+ "}; Module");
var m = eval(
'function Module(stdlib, foreign, heap) {\n' +
' "use asm";\n' +
' function ' + name + '(dividend) {\n' +
' dividend = dividend | 0;\n' +
' return ((dividend | 0) / ' + divisor + ') | 0;\n' +
' }\n' +
' return { f: ' + name + '}\n' +
'}; Module');
return m(stdlib, foreign, heap).f;
}
......
......@@ -12,13 +12,15 @@ function Int32Mod(divisor) {
name += "minus_";
}
name += Math.abs(divisor);
var m = eval("function Module(stdlib, foreign, heap) {\n"
+ " \"use asm\";\n"
+ " function " + name + "(dividend) {\n"
+ " return ((dividend | 0) % " + divisor + ") | 0;\n"
+ " }\n"
+ " return { f: " + name + "}\n"
+ "}; Module");
var m = eval(
'function Module(stdlib, foreign, heap) {\n' +
' "use asm";\n' +
' function ' + name + '(dividend) {\n' +
' dividend = dividend | 0;\n' +
' return ((dividend | 0) % ' + divisor + ') | 0;\n' +
' }\n' +
' return { f: ' + name + '}\n' +
'}; Module');
return m(stdlib, foreign, heap).f;
}
......
......@@ -11,7 +11,7 @@ var mod = (function Module(stdlib, foreign, heap) {
function mod(dividend, divisor) {
dividend = dividend|0;
divisor = divisor|0;
return (dividend % divisor) | 0;
return ((dividend | 0) % (divisor | 0)) | 0;
}
return { mod: mod };
})(stdlib, foreign, heap).mod;
......
......@@ -11,7 +11,7 @@ var mod = (function Module(stdlib, foreign, heap) {
function mod(dividend, divisor) {
dividend = dividend|0;
divisor = divisor|0;
return (dividend % divisor) | 0;
return ((dividend | 0) % (divisor | 0)) | 0;
}
return { mod: mod };
})(stdlib, foreign, heap).mod;
......
......@@ -13,7 +13,7 @@ var m = (function Module(stdlib, foreign, heap) {
function load(i) {
i = i|0;
i = MEM8[i >> 0]|0;
return i;
return i | 0;
}
function store(i, v) {
i = i|0;
......@@ -23,7 +23,7 @@ var m = (function Module(stdlib, foreign, heap) {
function load8(i) {
i = i|0;
i = MEM8[i + 8 >> 0]|0;
return i;
return i | 0;
}
function store8(i, v) {
i = i|0;
......
......@@ -10,12 +10,13 @@ var heap = new ArrayBuffer(64 * 1024 * 1024);
var foo = (function(stdlib, foreign, heap) {
"use asm";
var M16 = new Int16Array(heap);
var M32 = new Int32Array(heap);
var M16 = new stdlib.Int16Array(heap);
var M32 = new stdlib.Int32Array(heap);
function foo() {
var i = 0;
M32[0] = 0x12341234;
var i = M32[0];
return M16[0];
i = M32[0] | 0;
return M16[0] | 0;
}
return foo;
})(stdlib, foreign, heap);
......
......@@ -15,14 +15,14 @@ function Module(stdlib) {
// g: unsigned -> double
function g(a) {
a = a>>>0;
return +abs(a);
a = a | 0;
return +abs(+(a >>> 0));
}
// h: signed -> double
function h(a) {
a = a|0;
return +abs(a);
return +abs(+(a | 0));
}
return { f: f, g: g, h: h };
......
......@@ -10,7 +10,7 @@ function Module(stdlib) {
// f: double -> float
function f(a) {
a = +a;
return ceil(a);
return +ceil(a);
}
return { f: f };
......
......@@ -10,8 +10,8 @@ var f = (function Module(stdlib) {
var clz32 = stdlib.Math.clz32;
function f(a) {
a = a >>> 0;
return clz32(a)|0;
a = a | 0;
return clz32(a >>> 0) | 0;
}
return f;
......
......@@ -9,8 +9,8 @@ function Module(stdlib) {
// f: double -> float
function f(a) {
a = +a;
return floor(a);
a = +a
return +floor(a);
}
return { f: f };
......
......@@ -7,15 +7,15 @@
function module(stdlib, foreign, heap) {
"use asm";
function foo(i) {
var j = 0;
i = i|0;
if (i < 0) {
var j = 0;
if ((i | 0) < 0) {
j = i+1|0;
}
if (i > 0) {
if ((i | 0) > 0) {
j = i+1|0;
}
return j;
return j | 0;
}
return { foo: foo };
}
......
......@@ -7,9 +7,9 @@
function module(stdlib, foreign, heap) {
"use asm";
function foo(i) {
var j = 0;
i = i|0;
switch (i) {
var j = 0;
switch (i | 0) {
case 0:
j = i+1|0;
break;
......@@ -20,10 +20,10 @@ function module(stdlib, foreign, heap) {
j = i;
break;
}
return j;
return j | 0;
}
return { foo: foo };
}
var foo = module(this, {}, new ArrayBuffer(64*1024)).foo;
print(foo(1));
assertEquals(2, foo(2));
......@@ -11,11 +11,12 @@ var switch1 = (function(stdlib, foreign, heap) {
"use asm";
function switch1(i) {
i = i|0;
switch (i) {
switch (i | 0) {
case 0: return 1;
case 1: return 2;
default: return i|0;
}
return i | 0;
}
return { switch1: switch1 };
})(stdlib, foreign, heap).switch1;
......@@ -32,7 +33,7 @@ var switch2 = (function(stdlib, foreign, heap) {
function switch2(i) {
i = i|0;
var j = 0;
switch (i) {
switch (i | 0) {
case 0: j = 1; break;
case 1: j = 2; break;
case 2: j = 3; break;
......@@ -56,7 +57,7 @@ var switch3 = (function(stdlib, foreign, heap) {
function switch3(i) {
i = i|0;
var j = 0;
switch (i) {
switch (i | 0) {
case 0:
case 1: j = 1; break;
case 2:
......@@ -85,7 +86,7 @@ var switch4 = (function(stdlib, foreign, heap) {
"use asm";
function switch4(i) {
i = i|0;
switch (i) {
switch (i | 0) {
case -1:
case 1:
return 0;
......@@ -105,6 +106,7 @@ var switch4 = (function(stdlib, foreign, heap) {
default:
return 4;
}
return 0; // needed for validation
}
return { switch4: switch4 };
})(stdlib, foreign, heap).switch4;
......
......@@ -7,7 +7,8 @@ function Module(stdlib, foreign, heap) {
function foo1(i1) {
i1 = i1 | 0;
var i10 = i1 >> 5;
var i10 = 0;
i10 = (i1 >> 5) | 0;
if (i10 >>> 0 < 5) {
return 1;
} else {
......@@ -18,7 +19,8 @@ function Module(stdlib, foreign, heap) {
function foo2(i1) {
i1 = i1 | 0;
var i10 = i1 / 32 | 0;
var i10 = 0;
i10 = ((i1 | 0) / 32) | 0;
if (i10 >>> 0 < 5) {
return 1;
} else {
......@@ -29,7 +31,8 @@ function Module(stdlib, foreign, heap) {
function foo3(i1) {
i1 = i1 | 0;
var i10 = (i1 + 32 | 0) / 32 | 0;
var i10 = 0;
i10 = (i1 + 32 | 0) / 32 | 0;
if (i10 >>> 0 < 5) {
return 1;
} else {
......
......@@ -9,13 +9,15 @@ var heap = new ArrayBuffer(64 * 1024);
function Uint32Div(divisor) {
var name = "div_";
name += divisor;
var m = eval("function Module(stdlib, foreign, heap) {\n"
+ " \"use asm\";\n"
+ " function " + name + "(dividend) {\n"
+ " return ((dividend >>> 0) / " + divisor + ") >>> 0;\n"
+ " }\n"
+ " return { f: " + name + "}\n"
+ "}; Module");
var m = eval(
'function Module(stdlib, foreign, heap) {\n' +
' "use asm";\n' +
' function ' + name + '(dividend) {\n' +
' dividend = dividend | 0;\n' +
' return ((dividend >>> 0) / ' + divisor + ') | 0;\n' +
' }\n' +
' return { f: ' + name + '}\n' +
'}; Module');
return m(stdlib, foreign, heap).f;
}
......@@ -24,13 +26,15 @@ for (var i in divisors) {
var divisor = divisors[i];
var div = Uint32Div(divisor);
for (var dividend = 0; dividend < 4294967296; dividend += 3999773) {
assertEquals((dividend / divisor) >>> 0, div(dividend));
assertEquals((dividend / divisor) | 0, div(dividend));
}
}
var div = (function(stdlib, foreign, heap) {
"use asm";
function div(dividend, divisor) {
dividend = dividend | 0;
divisor = divisor | 0;
return (dividend >>> 0) / (divisor >>> 0) | 0;
}
return {div: div};
......
......@@ -9,13 +9,15 @@ var heap = new ArrayBuffer(64 * 1024);
function Uint32Mod(divisor) {
var name = "mod_";
name += divisor;
var m = eval("function Module(stdlib, foreign, heap) {\n"
+ " \"use asm\";\n"
+ " function " + name + "(dividend) {\n"
+ " return ((dividend >>> 0) % " + divisor + ") >>> 0;\n"
+ " }\n"
+ " return { f: " + name + "}\n"
+ "}; Module");
var m = eval(
'function Module(stdlib, foreign, heap) {\n' +
' "use asm";\n' +
' function ' + name + '(dividend) {\n' +
' dividend = dividend | 0;\n' +
' return ((dividend >>> 0) % ' + divisor + ') | 0;\n' +
' }\n' +
' return { f: ' + name + '}\n' +
'}; Module');
return m(stdlib, foreign, heap).f;
}
......@@ -24,6 +26,6 @@ for (var i in divisors) {
var divisor = divisors[i];
var mod = Uint32Mod(divisor);
for (var dividend = 0; dividend < 4294967296; dividend += 3999773) {
assertEquals((dividend % divisor) >>> 0, mod(dividend));
assertEquals((dividend % divisor) | 0, mod(dividend));
}
}
......@@ -9,9 +9,9 @@ var heap = new ArrayBuffer(64 * 1024);
var mod = (function Module(stdlib, foreign, heap) {
"use asm";
function mod(dividend, divisor) {
dividend = dividend >>> 0;
divisor = divisor >>> 0;
return (dividend % divisor) >>> 0;
dividend = dividend | 0;
divisor = divisor | 0;
return ((dividend >>> 0) % (divisor >>> 0)) | 0;
}
return { mod: mod };
})(stdlib, foreign, heap).mod;
......@@ -20,6 +20,6 @@ var divisors = [0, 1, 3, 4, 10, 42, 64, 100, 1024, 2147483647, 4294967295];
for (var i in divisors) {
var divisor = divisors[i];
for (var dividend = 0; dividend < 4294967296; dividend += 3999773) {
assertEquals((dividend % divisor) >>> 0, mod(dividend, divisor));
assertEquals((dividend % divisor) | 0, mod(dividend, divisor));
}
}
......@@ -8,7 +8,7 @@ function Module(stdlib, foreign, heap) {
function load(i) {
i = i|0;
i = MEM8[i] | 0;
return i;
return i | 0;
}
function store(i, v) {
i = i|0;
......
......@@ -8,13 +8,15 @@ var heap = new ArrayBuffer(64 * 1024);
function Word32And(rhs) {
var name = "and_0x" + Number(rhs).toString(16);
var m = eval("function Module(stdlib, foreign, heap) {\n"
+ " \"use asm\";\n"
+ " function " + name + "(lhs) {\n"
+ " return (lhs | 0) & 0x" + Number(rhs).toString(16) + ";\n"
+ " }\n"
+ " return { f: " + name + "}\n"
+ "}; Module");
var m = eval(
'function Module(stdlib, foreign, heap) {\n' +
' "use asm";\n' +
' function ' + name + '(lhs) {\n' +
' lhs = lhs | 0;\n' +
' return (lhs & 0x' + Number(rhs).toString(16) + ') | 0;\n' +
' }\n' +
' return { f: ' + name + '}\n' +
'}; Module');
return m(stdlib, foreign, heap).f;
}
......
......@@ -11,7 +11,7 @@ var rol = (function Module(stdlib, foreign, heap) {
function rol(x, y) {
x = x | 0;
y = y | 0;
return (x << y) | (x >>> (32 - y));
return (x << y) | (x >>> (32 - y)) | 0;
}
return { rol: rol };
})(stdlib, foreign, heap).rol;
......@@ -26,7 +26,7 @@ var ror = (function Module(stdlib, foreign, heap) {
function ror(x, y) {
x = x | 0;
y = y | 0;
return (x << (32 - y)) | (x >>> y);
return (x << (32 - y)) | (x >>> y) | 0;
}
return { ror: ror };
})(stdlib, foreign, heap).ror;
......
......@@ -10,8 +10,8 @@ var foreign = {}
var zext8 = (function Module(stdlib, foreign, heap) {
"use asm";
function zext8(i) {
i = i|0;
return i & 0xff;
i = i | 0;
return (i & 0xff) | 0;
}
return { zext8: zext8 };
})(stdlib, foreign, buffer).zext8;
......@@ -25,8 +25,8 @@ assertEquals(0xff, zext8(0xff));
var zext16 = (function Module(stdlib, foreign, heap) {
"use asm";
function zext16(i) {
i = i|0;
return i & 0xffff;
i = i | 0;
return (i & 0xffff) | 0;
}
return { zext16: zext16 };
})(stdlib, foreign, buffer).zext16;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment