Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: test/mjsunit/asm/atomics-store.js

Issue 1422533009: Support SAB atomics for offset-TypedArray (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: add a test case Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/mjsunit/asm/atomics-or.js ('k') | test/mjsunit/asm/atomics-sub.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 store = stdlib.Atomics.store; 15 var store = stdlib.Atomics.store;
16 var fround = stdlib.Math.fround; 16 var fround = stdlib.Math.fround;
17 17
18 function storei8(i, x) { 18 function storei8(i, x) {
19 i = i | 0; 19 i = i | 0;
20 x = x | 0; 20 x = x | 0;
21 return store(MEM8, i, x)|0; 21 return store(MEM8, i, x)|0;
22 } 22 }
23 23
24 function storei16(i, x) { 24 function storei16(i, x) {
(...skipping 29 matching lines...) Expand all
54 return { 54 return {
55 storei8: storei8, 55 storei8: storei8,
56 storei16: storei16, 56 storei16: storei16,
57 storei32: storei32, 57 storei32: storei32,
58 storeu8: storeu8, 58 storeu8: storeu8,
59 storeu16: storeu16, 59 storeu16: storeu16,
60 storeu32: storeu32, 60 storeu32: storeu32,
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, oobValue) { 71 function testElementType(taConstr, f, oobValue, 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(10, f(0, 10), name); 76 assertEquals(10, f(0, 10), name);
80 assertEquals(10, ta[0]); 77 assertEquals(10, ta[0]);
81 // out of bounds 78 // out of bounds
82 assertEquals(oobValue, f(-1, 0), name); 79 assertEquals(oobValue, f(-1, 0), name);
83 assertEquals(oobValue, f(ta.length, 0), name); 80 assertEquals(oobValue, f(ta.length, 0), name);
84 } 81 }
85 82
86 testElementType(Int8Array, m.storei8, 0); 83 function testElement(m, offset) {
87 testElementType(Int16Array, m.storei16, 0); 84 testElementType(Int8Array, m.storei8, 0, offset);
88 testElementType(Int32Array, m.storei32, 0); 85 testElementType(Int16Array, m.storei16, 0, offset);
89 testElementType(Uint8Array, m.storeu8, 0); 86 testElementType(Int32Array, m.storei32, 0, offset);
90 testElementType(Uint16Array, m.storeu16, 0); 87 testElementType(Uint8Array, m.storeu8, 0, offset);
91 testElementType(Uint32Array, m.storeu32, 0); 88 testElementType(Uint16Array, m.storeu16, 0, offset);
89 testElementType(Uint32Array, m.storeu32, 0, offset);
90 }
91
92 var offset = 0;
93 var sab = new SharedArrayBuffer(16);
94 var m1 = Module(this, {}, sab, offset);
95 testElement(m1, offset);
96
97 offset = 32;
98 sab = new SharedArrayBuffer(64);
99 var m2 = Module(this, {}, sab, offset);
100 testElement(m2, offset);
OLDNEW
« no previous file with comments | « test/mjsunit/asm/atomics-or.js ('k') | test/mjsunit/asm/atomics-sub.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698