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 compareExchange = stdlib.Atomics.compareExchange; | 15 var compareExchange = stdlib.Atomics.compareExchange; |
16 var fround = stdlib.Math.fround; | 16 var fround = stdlib.Math.fround; |
17 | 17 |
18 function compareExchangei8(i, o, n) { | 18 function compareExchangei8(i, o, n) { |
19 i = i | 0; | 19 i = i | 0; |
20 o = o | 0; | 20 o = o | 0; |
21 n = n | 0; | 21 n = n | 0; |
22 return compareExchange(MEM8, i, o, n)|0; | 22 return compareExchange(MEM8, i, o, n)|0; |
23 } | 23 } |
24 | 24 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 return { | 60 return { |
61 compareExchangei8: compareExchangei8, | 61 compareExchangei8: compareExchangei8, |
62 compareExchangei16: compareExchangei16, | 62 compareExchangei16: compareExchangei16, |
63 compareExchangei32: compareExchangei32, | 63 compareExchangei32: compareExchangei32, |
64 compareExchangeu8: compareExchangeu8, | 64 compareExchangeu8: compareExchangeu8, |
65 compareExchangeu16: compareExchangeu16, | 65 compareExchangeu16: compareExchangeu16, |
66 compareExchangeu32: compareExchangeu32, | 66 compareExchangeu32: compareExchangeu32, |
67 }; | 67 }; |
68 } | 68 } |
69 | 69 |
70 var sab = new SharedArrayBuffer(16); | |
71 var m = Module(this, {}, sab); | |
72 | |
73 function clearArray() { | 70 function clearArray() { |
74 var ui8 = new Uint8Array(sab); | 71 var ui8 = new Uint8Array(sab); |
75 for (var i = 0; i < sab.byteLength; ++i) { | 72 for (var i = 0; i < sab.byteLength; ++i) { |
76 ui8[i] = 0; | 73 ui8[i] = 0; |
77 } | 74 } |
78 } | 75 } |
79 | 76 |
80 function testElementType(taConstr, f, oobValue) { | 77 function testElementType(taConstr, f, oobValue, offset) { |
81 clearArray(); | 78 clearArray(); |
82 | 79 |
83 var ta = new taConstr(sab); | 80 var ta = new taConstr(sab, offset); |
84 var name = Object.prototype.toString.call(ta); | 81 var name = Object.prototype.toString.call(ta); |
85 assertEquals(0, ta[0]); | 82 assertEquals(0, ta[0]); |
86 assertEquals(0, f(0, 0, 50), name); | 83 assertEquals(0, f(0, 0, 50), name); |
87 assertEquals(50, ta[0]); | 84 assertEquals(50, ta[0]); |
88 // Value is not equal to 0, so compareExchange won't store 100 | 85 // Value is not equal to 0, so compareExchange won't store 100 |
89 assertEquals(50, f(0, 0, 100), name); | 86 assertEquals(50, f(0, 0, 100), name); |
90 assertEquals(50, ta[0]); | 87 assertEquals(50, ta[0]); |
91 // out of bounds | 88 // out of bounds |
92 assertEquals(oobValue, f(-1, 0, 0), name); | 89 assertEquals(oobValue, f(-1, 0, 0), name); |
93 assertEquals(oobValue, f(ta.length, 0, 0), name); | 90 assertEquals(oobValue, f(ta.length, 0, 0), name); |
94 } | 91 } |
95 | 92 |
96 testElementType(Int8Array, m.compareExchangei8, 0); | 93 function testElement(m, offset) { |
97 testElementType(Int16Array, m.compareExchangei16, 0); | 94 testElementType(Int8Array, m.compareExchangei8, 0, offset); |
98 testElementType(Int32Array, m.compareExchangei32, 0); | 95 testElementType(Int16Array, m.compareExchangei16, 0, offset); |
99 testElementType(Uint8Array, m.compareExchangeu8, 0); | 96 testElementType(Int32Array, m.compareExchangei32, 0, offset); |
100 testElementType(Uint16Array, m.compareExchangeu16, 0); | 97 testElementType(Uint8Array, m.compareExchangeu8, 0, offset); |
101 testElementType(Uint32Array, m.compareExchangeu32, 0); | 98 testElementType(Uint16Array, m.compareExchangeu16, 0, offset); |
| 99 testElementType(Uint32Array, m.compareExchangeu32, 0, offset); |
| 100 } |
| 101 |
| 102 var offset = 0; |
| 103 var sab = new SharedArrayBuffer(16); |
| 104 var m1 = Module(this, {}, sab, offset); |
| 105 testElement(m1, offset); |
| 106 |
| 107 offset = 32; |
| 108 sab = new SharedArrayBuffer(64); |
| 109 var m2 = Module(this, {}, sab, offset); |
| 110 testElement(m2, offset); |
OLD | NEW |