| 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 compareExchange = stdlib.Atomics.compareExchange; | 15 var compareExchange = stdlib.Atomics.compareExchange; |
| 18 var fround = stdlib.Math.fround; | 16 var fround = stdlib.Math.fround; |
| 19 | 17 |
| 20 function compareExchangei8(i, o, n) { | 18 function compareExchangei8(i, o, n) { |
| 21 i = i | 0; | 19 i = i | 0; |
| 22 o = o | 0; | 20 o = o | 0; |
| 23 n = n | 0; | 21 n = n | 0; |
| 24 return compareExchange(MEM8, i, o, n)|0; | 22 return compareExchange(MEM8, i, o, n)|0; |
| 25 } | 23 } |
| 26 | 24 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 52 return compareExchange(MEMU16, i, o, n)>>>0; | 50 return compareExchange(MEMU16, i, o, n)>>>0; |
| 53 } | 51 } |
| 54 | 52 |
| 55 function compareExchangeu32(i, o, n) { | 53 function compareExchangeu32(i, o, n) { |
| 56 i = i | 0; | 54 i = i | 0; |
| 57 o = o >>> 0; | 55 o = o >>> 0; |
| 58 n = n >>> 0; | 56 n = n >>> 0; |
| 59 return compareExchange(MEMU32, i, o, n)>>>0; | 57 return compareExchange(MEMU32, i, o, n)>>>0; |
| 60 } | 58 } |
| 61 | 59 |
| 62 function compareExchangef32(i, o, n) { | |
| 63 i = i | 0; | |
| 64 o = fround(o); | |
| 65 n = fround(n); | |
| 66 return fround(compareExchange(MEMF32, i, o, n)); | |
| 67 } | |
| 68 | |
| 69 function compareExchangef64(i, o, n) { | |
| 70 i = i | 0; | |
| 71 o = +o; | |
| 72 n = +n; | |
| 73 return +compareExchange(MEMF64, i, o, n); | |
| 74 } | |
| 75 | |
| 76 return { | 60 return { |
| 77 compareExchangei8: compareExchangei8, | 61 compareExchangei8: compareExchangei8, |
| 78 compareExchangei16: compareExchangei16, | 62 compareExchangei16: compareExchangei16, |
| 79 compareExchangei32: compareExchangei32, | 63 compareExchangei32: compareExchangei32, |
| 80 compareExchangeu8: compareExchangeu8, | 64 compareExchangeu8: compareExchangeu8, |
| 81 compareExchangeu16: compareExchangeu16, | 65 compareExchangeu16: compareExchangeu16, |
| 82 compareExchangeu32: compareExchangeu32, | 66 compareExchangeu32: compareExchangeu32, |
| 83 compareExchangef32: compareExchangef32, | |
| 84 compareExchangef64: compareExchangef64 | |
| 85 }; | 67 }; |
| 86 } | 68 } |
| 87 | 69 |
| 88 var sab = new SharedArrayBuffer(16); | 70 var sab = new SharedArrayBuffer(16); |
| 89 var m = Module(this, {}, sab); | 71 var m = Module(this, {}, sab); |
| 90 | 72 |
| 91 function clearArray() { | 73 function clearArray() { |
| 92 var ui8 = new Uint8Array(sab); | 74 var ui8 = new Uint8Array(sab); |
| 93 for (var i = 0; i < sab.byteLength; ++i) { | 75 for (var i = 0; i < sab.byteLength; ++i) { |
| 94 ui8[i] = 0; | 76 ui8[i] = 0; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 110 assertEquals(oobValue, f(-1, 0, 0), name); | 92 assertEquals(oobValue, f(-1, 0, 0), name); |
| 111 assertEquals(oobValue, f(ta.length, 0, 0), name); | 93 assertEquals(oobValue, f(ta.length, 0, 0), name); |
| 112 } | 94 } |
| 113 | 95 |
| 114 testElementType(Int8Array, m.compareExchangei8, 0); | 96 testElementType(Int8Array, m.compareExchangei8, 0); |
| 115 testElementType(Int16Array, m.compareExchangei16, 0); | 97 testElementType(Int16Array, m.compareExchangei16, 0); |
| 116 testElementType(Int32Array, m.compareExchangei32, 0); | 98 testElementType(Int32Array, m.compareExchangei32, 0); |
| 117 testElementType(Uint8Array, m.compareExchangeu8, 0); | 99 testElementType(Uint8Array, m.compareExchangeu8, 0); |
| 118 testElementType(Uint16Array, m.compareExchangeu16, 0); | 100 testElementType(Uint16Array, m.compareExchangeu16, 0); |
| 119 testElementType(Uint32Array, m.compareExchangeu32, 0); | 101 testElementType(Uint32Array, m.compareExchangeu32, 0); |
| 120 testElementType(Float32Array, m.compareExchangef32, NaN); | |
| 121 testElementType(Float64Array, m.compareExchangef64, NaN); | |
| OLD | NEW |