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

Side by Side Diff: test/mjsunit/asm/atomics-load.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-exchange.js ('k') | test/mjsunit/asm/atomics-or.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 load = stdlib.Atomics.load; 15 var load = stdlib.Atomics.load;
16 var fround = stdlib.Math.fround; 16 var fround = stdlib.Math.fround;
17 17
18 function loadi8(i) { 18 function loadi8(i) {
19 i = i | 0; 19 i = i | 0;
20 return load(MEM8, i)|0; 20 return load(MEM8, i)|0;
21 } 21 }
22 22
23 function loadi16(i) { 23 function loadi16(i) {
24 i = i | 0; 24 i = i | 0;
(...skipping 23 matching lines...) Expand all
48 return { 48 return {
49 loadi8: loadi8, 49 loadi8: loadi8,
50 loadi16: loadi16, 50 loadi16: loadi16,
51 loadi32: loadi32, 51 loadi32: loadi32,
52 loadu8: loadu8, 52 loadu8: loadu8,
53 loadu16: loadu16, 53 loadu16: loadu16,
54 loadu32: loadu32, 54 loadu32: loadu32,
55 }; 55 };
56 } 56 }
57 57
58 var sab = new SharedArrayBuffer(16);
59 var m = Module(this, {}, sab);
60
61 function clearArray() { 58 function clearArray() {
62 var ui8 = new Uint8Array(sab); 59 var ui8 = new Uint8Array(sab);
63 for (var i = 0; i < sab.byteLength; ++i) { 60 for (var i = 0; i < sab.byteLength; ++i) {
64 ui8[i] = 0; 61 ui8[i] = 0;
65 } 62 }
66 } 63 }
67 64
68 function testElementType(taConstr, f, oobValue) { 65 function testElementType(taConstr, f, oobValue, offset) {
69 clearArray(); 66 clearArray();
70 67
71 var ta = new taConstr(sab); 68 var ta = new taConstr(sab, offset);
72 var name = Object.prototype.toString.call(ta); 69 var name = Object.prototype.toString.call(ta);
73 ta[0] = 10; 70 ta[0] = 10;
74 assertEquals(10, f(0), name); 71 assertEquals(10, f(0), name);
75 assertEquals(0, f(1), name); 72 assertEquals(0, f(1), name);
76 // out of bounds 73 // out of bounds
77 assertEquals(oobValue, f(-1), name); 74 assertEquals(oobValue, f(-1), name);
78 assertEquals(oobValue, f(ta.length), name); 75 assertEquals(oobValue, f(ta.length), name);
79 } 76 }
80 77
81 testElementType(Int8Array, m.loadi8, 0); 78 function testElement(m, offset) {
82 testElementType(Int16Array, m.loadi16, 0); 79 testElementType(Int8Array, m.loadi8, 0, offset);
83 testElementType(Int32Array, m.loadi32, 0); 80 testElementType(Int16Array, m.loadi16, 0, offset);
84 testElementType(Uint8Array, m.loadu8, 0); 81 testElementType(Int32Array, m.loadi32, 0, offset);
85 testElementType(Uint16Array, m.loadu16, 0); 82 testElementType(Uint8Array, m.loadu8, 0, offset);
86 testElementType(Uint32Array, m.loadu32, 0); 83 testElementType(Uint16Array, m.loadu16, 0, offset);
84 testElementType(Uint32Array, m.loadu32, 0, offset);
85 }
86
87 var offset = 0;
88 var sab = new SharedArrayBuffer(16);
89 var m1 = Module(this, {}, sab, offset);
90 testElement(m1, offset);
91
92 offset = 32;
93 sab = new SharedArrayBuffer(64);
94 var m2 = Module(this, {}, sab, offset);
95 testElement(m2, offset);
OLDNEW
« no previous file with comments | « test/mjsunit/asm/atomics-exchange.js ('k') | test/mjsunit/asm/atomics-or.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698