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) { |
8 "use asm"; | 8 "use asm"; |
9 var MEM8 = new stdlib.Int8Array(heap); | 9 var MEM8 = new stdlib.Int8Array(heap); |
10 var MEM16 = new stdlib.Int16Array(heap); | 10 var MEM16 = new stdlib.Int16Array(heap); |
11 var MEM32 = new stdlib.Int32Array(heap); | 11 var MEM32 = new stdlib.Int32Array(heap); |
12 var MEMU8 = new stdlib.Uint8Array(heap); | 12 var MEMU8 = new stdlib.Uint8Array(heap); |
13 var MEMU16 = new stdlib.Uint16Array(heap); | 13 var MEMU16 = new stdlib.Uint16Array(heap); |
14 var MEMU32 = new stdlib.Uint32Array(heap); | 14 var MEMU32 = new stdlib.Uint32Array(heap); |
15 var MEMF32 = new stdlib.Float32Array(heap); | |
16 var MEMF64 = new stdlib.Float64Array(heap); | |
17 var load = stdlib.Atomics.load; | 15 var load = stdlib.Atomics.load; |
18 var fround = stdlib.Math.fround; | 16 var fround = stdlib.Math.fround; |
19 | 17 |
20 function loadi8(i) { | 18 function loadi8(i) { |
21 i = i | 0; | 19 i = i | 0; |
22 return load(MEM8, i)|0; | 20 return load(MEM8, i)|0; |
23 } | 21 } |
24 | 22 |
25 function loadi16(i) { | 23 function loadi16(i) { |
26 i = i | 0; | 24 i = i | 0; |
(...skipping 13 matching lines...) Expand all Loading... |
40 function loadu16(i) { | 38 function loadu16(i) { |
41 i = i | 0; | 39 i = i | 0; |
42 return load(MEMU16, i)>>>0; | 40 return load(MEMU16, i)>>>0; |
43 } | 41 } |
44 | 42 |
45 function loadu32(i) { | 43 function loadu32(i) { |
46 i = i | 0; | 44 i = i | 0; |
47 return load(MEMU32, i)>>>0; | 45 return load(MEMU32, i)>>>0; |
48 } | 46 } |
49 | 47 |
50 function loadf32(i) { | |
51 i = i | 0; | |
52 return fround(load(MEMF32, i)); | |
53 } | |
54 | |
55 function loadf64(i) { | |
56 i = i | 0; | |
57 return +load(MEMF64, i); | |
58 } | |
59 | |
60 return { | 48 return { |
61 loadi8: loadi8, | 49 loadi8: loadi8, |
62 loadi16: loadi16, | 50 loadi16: loadi16, |
63 loadi32: loadi32, | 51 loadi32: loadi32, |
64 loadu8: loadu8, | 52 loadu8: loadu8, |
65 loadu16: loadu16, | 53 loadu16: loadu16, |
66 loadu32: loadu32, | 54 loadu32: loadu32, |
67 loadf32: loadf32, | |
68 loadf64: loadf64 | |
69 }; | 55 }; |
70 } | 56 } |
71 | 57 |
72 var sab = new SharedArrayBuffer(16); | 58 var sab = new SharedArrayBuffer(16); |
73 var m = Module(this, {}, sab); | 59 var m = Module(this, {}, sab); |
74 | 60 |
75 function clearArray() { | 61 function clearArray() { |
76 var ui8 = new Uint8Array(sab); | 62 var ui8 = new Uint8Array(sab); |
77 for (var i = 0; i < sab.byteLength; ++i) { | 63 for (var i = 0; i < sab.byteLength; ++i) { |
78 ui8[i] = 0; | 64 ui8[i] = 0; |
(...skipping 12 matching lines...) Expand all Loading... |
91 assertEquals(oobValue, f(-1), name); | 77 assertEquals(oobValue, f(-1), name); |
92 assertEquals(oobValue, f(ta.length), name); | 78 assertEquals(oobValue, f(ta.length), name); |
93 } | 79 } |
94 | 80 |
95 testElementType(Int8Array, m.loadi8, 0); | 81 testElementType(Int8Array, m.loadi8, 0); |
96 testElementType(Int16Array, m.loadi16, 0); | 82 testElementType(Int16Array, m.loadi16, 0); |
97 testElementType(Int32Array, m.loadi32, 0); | 83 testElementType(Int32Array, m.loadi32, 0); |
98 testElementType(Uint8Array, m.loadu8, 0); | 84 testElementType(Uint8Array, m.loadu8, 0); |
99 testElementType(Uint16Array, m.loadu16, 0); | 85 testElementType(Uint16Array, m.loadu16, 0); |
100 testElementType(Uint32Array, m.loadu32, 0); | 86 testElementType(Uint32Array, m.loadu32, 0); |
101 testElementType(Float32Array, m.loadf32, NaN); | |
102 testElementType(Float64Array, m.loadf64, NaN); | |
OLD | NEW |