1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
load(libdir + "asm.js");
var code = asmCompile('glob', 'imp', 'b', USE_ASM + HEAP_IMPORTS + 'function f(i,j) {i=i|0;j=j|0; u32[((i<<2)+32 & 0xffff)>>2] = j } return f');
var f = asmLink(code, this, null, BUF_64KB);
for (var i = 0; i < 100; i++)
f(i, i);
var u32 = new Uint32Array(BUF_64KB);
for (var i = 0; i < 100; i++)
assertEq(u32[8+i], i);
var code = asmCompile('glob', 'imp', 'b', USE_ASM + HEAP_IMPORTS + 'function f(i) {i=i|0; return u32[((i<<2)+32 & 0xffff)>>2]|0 } return f');
var f = asmLink(code, this, null, BUF_64KB);
for (var i = 0; i < 100; i++)
assertEq(f(i), i);
var code = asmCompile('glob', 'imp', 'b', USE_ASM + HEAP_IMPORTS + 'function f(i,j) {i=i|0;j=j|0; u32[(i<<2 & 0xffff)>>2] = j } return f');
var f = asmLink(code, this, null, BUF_64KB);
for (var i = 0; i < 100; i++)
f(i, i);
var u32 = new Uint32Array(BUF_64KB);
for (var i = 0; i < 100; i++)
assertEq(u32[i], i);
var code = asmCompile('glob', 'imp', 'b', USE_ASM + HEAP_IMPORTS + 'function f(i) {i=i|0; return u32[(i<<2 & 0xffff)>>2]|0 } return f');
var f = asmLink(code, this, null, BUF_64KB);
for (var i = 0; i < 100; i++)
assertEq(f(i), i);
// For legacy compatibility, test Int8/Uint8 accesses with no shift.
var code = asmCompile('glob', 'imp', 'b', USE_ASM + HEAP_IMPORTS + 'function f(i,j) {i=i|0;j=j|0; u8[i+20 & 0xffff] = j } return f');
var f = asmLink(code, this, null, BUF_64KB);
for (var i = 0; i < 100; i++)
f(i, i);
var u8 = new Uint8Array(BUF_64KB);
for (var i = 0; i < 100; i++)
assertEq(u8[i+20], i);
var code = asmCompile('glob', 'imp', 'b', USE_ASM + HEAP_IMPORTS + 'function f(i) {i=i|0; return u8[i+20 & 0xffff]|0 } return f');
var f = asmLink(code, this, null, BUF_64KB);
for (var i = 0; i < 100; i++)
assertEq(f(i), i);
var code = asmCompile('glob', 'imp', 'b', USE_ASM + HEAP_IMPORTS + 'function f(i,j) {i=i|0;j=j|0; u8[(i+20 & 0xffff)>>0] = j } return f');
var f = asmLink(code, this, null, BUF_64KB);
for (var i = 0; i < 100; i++)
f(i, i);
var u8 = new Uint8Array(BUF_64KB);
for (var i = 0; i < 100; i++)
assertEq(u8[i+20], i);
var code = asmCompile('glob', 'imp', 'b', USE_ASM + HEAP_IMPORTS + 'function f(i) {i=i|0; return u8[(i+20 & 0xffff)>>0]|0 } return f');
var f = asmLink(code, this, null, BUF_64KB);
for (var i = 0; i < 100; i++)
assertEq(f(i), i);
var code = asmCompile('glob', 'imp', 'b', USE_ASM + HEAP_IMPORTS + 'function f(i,j,k) {i=i|0;j=j|0;k=k|0; i32[(i + (j<<2) & 0xffff) >> 2] = k } return f');
var f = asmLink(code, this, null, BUF_64KB);
for (var i = 0; i < 100; i++)
f(32, i, i);
var u32 = new Uint32Array(BUF_64KB);
for (var i = 0; i < 100; i++)
assertEq(u32[8+i], i);
var code = asmCompile('glob', 'imp', 'b', USE_ASM + HEAP_IMPORTS + 'function f(i,j) {i=i|0;j=j|0; return i32[(i + (j<<2) & 0xffff) >> 2]|0 } return f');
var f = asmLink(code, this, null, BUF_64KB);
for (var i = 0; i < 100; i++)
assertEq(f(32, i), i);
var code = asmCompile('glob', 'imp', 'b', USE_ASM + HEAP_IMPORTS + 'function f(i,j,k) {i=i|0;j=j|0;k=k|0; i32[(((i + (j<<2))|0) + 16 & 0xffff) >> 2] = k } return f');
var f = asmLink(code, this, null, BUF_64KB);
for (var i = 0; i < 100; i++)
f(32, i, i);
var u32 = new Uint32Array(BUF_64KB);
for (var i = 0; i < 100; i++)
assertEq(u32[8+i+4], i);
var code = asmCompile('glob', 'imp', 'b', USE_ASM + HEAP_IMPORTS + 'function f(i,j) {i=i|0;j=j|0; return i32[(((i + (j<<2))|0) + 16 & 0xffff) >> 2]|0 } return f');
var f = asmLink(code, this, null, BUF_64KB);
for (var i = 0; i < 100; i++)
assertEq(f(32, i), i);
var code = asmCompile('glob', 'imp', 'b', USE_ASM + HEAP_IMPORTS + 'function f(i,j) {i=i|0;j=j|0; return ((i32[(i+(j<<2)&0xffff)>>2]|0) + (i32[(((i+(j<<2))|0)+4&0xffff)>>2]|0))|0 } return f');
var f = asmLink(code, this, null, BUF_64KB);
var i32 = new Uint32Array(BUF_64KB);
i32[11] = 3;
i32[12] = 97;
assertEq(f(12,8), 100);
|