OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --harmony-atomics --harmony-sharedarraybuffer |
| 6 |
| 7 function Module(stdlib, foreign, heap) { |
| 8 "use asm"; |
| 9 var MEM8 = new stdlib.Int8Array(heap); |
| 10 var MEM16 = new stdlib.Int16Array(heap); |
| 11 var MEM32 = new stdlib.Int32Array(heap); |
| 12 var MEMU8 = new stdlib.Uint8Array(heap); |
| 13 var MEMU16 = new stdlib.Uint16Array(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; |
| 18 var fround = stdlib.Math.fround; |
| 19 |
| 20 function loadi8(i) { |
| 21 i = i | 0; |
| 22 return load(MEM8, i)|0; |
| 23 } |
| 24 |
| 25 function loadi16(i) { |
| 26 i = i | 0; |
| 27 return load(MEM16, i)|0; |
| 28 } |
| 29 |
| 30 function loadi32(i) { |
| 31 i = i | 0; |
| 32 return load(MEM32, i)|0; |
| 33 } |
| 34 |
| 35 function loadu8(i) { |
| 36 i = i | 0; |
| 37 return load(MEMU8, i)>>>0; |
| 38 } |
| 39 |
| 40 function loadu16(i) { |
| 41 i = i | 0; |
| 42 return load(MEMU16, i)>>>0; |
| 43 } |
| 44 |
| 45 function loadu32(i) { |
| 46 i = i | 0; |
| 47 return load(MEMU32, i)>>>0; |
| 48 } |
| 49 |
| 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 { |
| 61 loadi8: loadi8, |
| 62 loadi16: loadi16, |
| 63 loadi32: loadi32, |
| 64 loadu8: loadu8, |
| 65 loadu16: loadu16, |
| 66 loadu32: loadu32, |
| 67 loadf32: loadf32, |
| 68 loadf64: loadf64 |
| 69 }; |
| 70 } |
| 71 |
| 72 var sab = new SharedArrayBuffer(16); |
| 73 var m = Module(this, {}, sab); |
| 74 |
| 75 function clearArray() { |
| 76 var ui8 = new Uint8Array(sab); |
| 77 for (var i = 0; i < sab.byteLength; ++i) { |
| 78 ui8[i] = 0; |
| 79 } |
| 80 } |
| 81 |
| 82 function testElementType(taConstr, f, oobValue) { |
| 83 clearArray(); |
| 84 |
| 85 var ta = new taConstr(sab); |
| 86 var name = Object.prototype.toString.call(ta); |
| 87 ta[0] = 10; |
| 88 assertEquals(10, f(0), name); |
| 89 assertEquals(0, f(1), name); |
| 90 // out of bounds |
| 91 assertEquals(oobValue, f(-1), name); |
| 92 assertEquals(oobValue, f(ta.length), name); |
| 93 } |
| 94 |
| 95 testElementType(Int8Array, m.loadi8, 0); |
| 96 testElementType(Int16Array, m.loadi16, 0); |
| 97 testElementType(Int32Array, m.loadi32, 0); |
| 98 testElementType(Uint8Array, m.loadu8, 0); |
| 99 testElementType(Uint16Array, m.loadu16, 0); |
| 100 testElementType(Uint32Array, m.loadu32, 0); |
| 101 testElementType(Float32Array, m.loadf32, NaN); |
| 102 testElementType(Float64Array, m.loadf64, NaN); |
OLD | NEW |