js/src/jit-test/tests/asm.js/testFastHeapAccess.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 load(libdir + "asm.js");
michael@0 2
michael@0 3 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');
michael@0 4 var f = asmLink(code, this, null, BUF_64KB);
michael@0 5 for (var i = 0; i < 100; i++)
michael@0 6 f(i, i);
michael@0 7 var u32 = new Uint32Array(BUF_64KB);
michael@0 8 for (var i = 0; i < 100; i++)
michael@0 9 assertEq(u32[8+i], i);
michael@0 10 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');
michael@0 11 var f = asmLink(code, this, null, BUF_64KB);
michael@0 12 for (var i = 0; i < 100; i++)
michael@0 13 assertEq(f(i), i);
michael@0 14
michael@0 15 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');
michael@0 16 var f = asmLink(code, this, null, BUF_64KB);
michael@0 17 for (var i = 0; i < 100; i++)
michael@0 18 f(i, i);
michael@0 19 var u32 = new Uint32Array(BUF_64KB);
michael@0 20 for (var i = 0; i < 100; i++)
michael@0 21 assertEq(u32[i], i);
michael@0 22 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');
michael@0 23 var f = asmLink(code, this, null, BUF_64KB);
michael@0 24 for (var i = 0; i < 100; i++)
michael@0 25 assertEq(f(i), i);
michael@0 26
michael@0 27 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');
michael@0 28 var f = asmLink(code, this, null, BUF_64KB);
michael@0 29 for (var i = 0; i < 100; i++)
michael@0 30 f(i, i);
michael@0 31 var u8 = new Uint8Array(BUF_64KB);
michael@0 32 for (var i = 0; i < 100; i++)
michael@0 33 assertEq(u8[i+20], i);
michael@0 34 var code = asmCompile('glob', 'imp', 'b', USE_ASM + HEAP_IMPORTS + 'function f(i) {i=i|0; return u8[i+20 & 0xffff]|0 } return f');
michael@0 35 var f = asmLink(code, this, null, BUF_64KB);
michael@0 36 for (var i = 0; i < 100; i++)
michael@0 37 assertEq(f(i), i);
michael@0 38
michael@0 39 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');
michael@0 40 var f = asmLink(code, this, null, BUF_64KB);
michael@0 41 for (var i = 0; i < 100; i++)
michael@0 42 f(32, i, i);
michael@0 43 var u32 = new Uint32Array(BUF_64KB);
michael@0 44 for (var i = 0; i < 100; i++)
michael@0 45 assertEq(u32[8+i], i);
michael@0 46 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');
michael@0 47 var f = asmLink(code, this, null, BUF_64KB);
michael@0 48 for (var i = 0; i < 100; i++)
michael@0 49 assertEq(f(32, i), i);
michael@0 50
michael@0 51 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');
michael@0 52 var f = asmLink(code, this, null, BUF_64KB);
michael@0 53 for (var i = 0; i < 100; i++)
michael@0 54 f(32, i, i);
michael@0 55 var u32 = new Uint32Array(BUF_64KB);
michael@0 56 for (var i = 0; i < 100; i++)
michael@0 57 assertEq(u32[8+i+4], i);
michael@0 58 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');
michael@0 59 var f = asmLink(code, this, null, BUF_64KB);
michael@0 60 for (var i = 0; i < 100; i++)
michael@0 61 assertEq(f(32, i), i);
michael@0 62
michael@0 63 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');
michael@0 64 var f = asmLink(code, this, null, BUF_64KB);
michael@0 65 var i32 = new Uint32Array(BUF_64KB);
michael@0 66 i32[11] = 3;
michael@0 67 i32[12] = 97;
michael@0 68 assertEq(f(12,8), 100);

mercurial