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