OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --harmony-sharedarraybuffer | 5 // Flags: --harmony-sharedarraybuffer |
6 | 6 |
7 function Module(stdlib, foreign, heap) { | 7 function Module(stdlib, foreign, heap, offset) { |
8 "use asm"; | 8 "use asm"; |
9 var MEM8 = new stdlib.Int8Array(heap); | 9 var MEM8 = new stdlib.Int8Array(heap, offset); |
10 var MEM16 = new stdlib.Int16Array(heap); | 10 var MEM16 = new stdlib.Int16Array(heap, offset); |
11 var MEM32 = new stdlib.Int32Array(heap); | 11 var MEM32 = new stdlib.Int32Array(heap, offset); |
12 var MEMU8 = new stdlib.Uint8Array(heap); | 12 var MEMU8 = new stdlib.Uint8Array(heap, offset); |
13 var MEMU16 = new stdlib.Uint16Array(heap); | 13 var MEMU16 = new stdlib.Uint16Array(heap, offset); |
14 var MEMU32 = new stdlib.Uint32Array(heap); | 14 var MEMU32 = new stdlib.Uint32Array(heap, offset); |
15 var xor = stdlib.Atomics.xor; | 15 var xor = stdlib.Atomics.xor; |
16 var fround = stdlib.Math.fround; | 16 var fround = stdlib.Math.fround; |
17 | 17 |
18 function xori8(i, x) { | 18 function xori8(i, x) { |
19 i = i | 0; | 19 i = i | 0; |
20 x = x | 0; | 20 x = x | 0; |
21 return xor(MEM8, i, x)|0; | 21 return xor(MEM8, i, x)|0; |
22 } | 22 } |
23 | 23 |
24 function xori16(i, x) { | 24 function xori16(i, x) { |
(...skipping 29 matching lines...) Expand all Loading... |
54 return { | 54 return { |
55 xori8: xori8, | 55 xori8: xori8, |
56 xori16: xori16, | 56 xori16: xori16, |
57 xori32: xori32, | 57 xori32: xori32, |
58 xoru8: xoru8, | 58 xoru8: xoru8, |
59 xoru16: xoru16, | 59 xoru16: xoru16, |
60 xoru32: xoru32, | 60 xoru32: xoru32, |
61 }; | 61 }; |
62 } | 62 } |
63 | 63 |
64 var sab = new SharedArrayBuffer(16); | |
65 var m = Module(this, {}, sab); | |
66 | |
67 function clearArray() { | 64 function clearArray() { |
68 var ui8 = new Uint8Array(sab); | 65 var ui8 = new Uint8Array(sab); |
69 for (var i = 0; i < sab.byteLength; ++i) { | 66 for (var i = 0; i < sab.byteLength; ++i) { |
70 ui8[i] = 0; | 67 ui8[i] = 0; |
71 } | 68 } |
72 } | 69 } |
73 | 70 |
74 function testElementType(taConstr, f) { | 71 function testElementType(taConstr, f, offset) { |
75 clearArray(); | 72 clearArray(); |
76 | 73 |
77 var ta = new taConstr(sab); | 74 var ta = new taConstr(sab, offset); |
78 var name = Object.prototype.toString.call(ta); | 75 var name = Object.prototype.toString.call(ta); |
79 assertEquals(0, f(0, 0xf), name); | 76 assertEquals(0, f(0, 0xf), name); |
80 assertEquals(0xf, ta[0]); | 77 assertEquals(0xf, ta[0]); |
81 assertEquals(0xf, f(0, 0x11), name); | 78 assertEquals(0xf, f(0, 0x11), name); |
82 assertEquals(0x1e, ta[0]); | 79 assertEquals(0x1e, ta[0]); |
83 // out of bounds | 80 // out of bounds |
84 assertEquals(0, f(-1, 0), name); | 81 assertEquals(0, f(-1, 0), name); |
85 assertEquals(0, f(ta.length, 0), name); | 82 assertEquals(0, f(ta.length, 0), name); |
86 } | 83 } |
87 | 84 |
88 testElementType(Int8Array, m.xori8); | 85 function testElement(m, offset) { |
89 testElementType(Int16Array, m.xori16); | 86 testElementType(Int8Array, m.xori8, offset); |
90 testElementType(Int32Array, m.xori32); | 87 testElementType(Int16Array, m.xori16, offset); |
91 testElementType(Uint8Array, m.xoru8); | 88 testElementType(Int32Array, m.xori32, offset); |
92 testElementType(Uint16Array, m.xoru16); | 89 testElementType(Uint8Array, m.xoru8, offset); |
93 testElementType(Uint32Array, m.xoru32); | 90 testElementType(Uint16Array, m.xoru16, offset); |
| 91 testElementType(Uint32Array, m.xoru32, offset); |
| 92 } |
| 93 |
| 94 var offset = 0; |
| 95 var sab = new SharedArrayBuffer(16); |
| 96 var m1 = Module(this, {}, sab, offset); |
| 97 testElement(m1, offset); |
| 98 |
| 99 offset = 32; |
| 100 sab = new SharedArrayBuffer(64); |
| 101 var m2 = Module(this, {}, sab, offset); |
| 102 testElement(m2, offset); |
OLD | NEW |