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

Side by Side Diff: test/mjsunit/wasm/data-segments.js

Issue 2402373002: Revert of [wasm] Base address for data segments can also be the value of a global variable. (Closed)
Patch Set: Created 4 years, 2 months 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 | « src/wasm/wasm-module.cc ('k') | test/mjsunit/wasm/test-wasm-module-builder.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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: --expose-wasm
6
7 load("test/mjsunit/wasm/wasm-constants.js");
8 load("test/mjsunit/wasm/wasm-module-builder.js");
9
10 var debug = false;
11
12 function SimpleDataSegmentTest(offset) {
13 print("SimpleDataSegmentTest(" + offset + ")...");
14 var builder = new WasmModuleBuilder();
15 builder.addMemory(1, 1, false);
16 builder.addFunction("load", kSig_i_i)
17 .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0])
18 .exportAs("load");
19 builder.addDataSegment(offset, [9, 9, 9, 9]);
20
21 var buffer = builder.toBuffer(debug);
22 var instance = Wasm.instantiateModule(buffer);
23 for (var i = offset - 20; i < offset + 20; i += 4) {
24 if (i < 0) continue;
25 var expected = (i == offset) ? 151587081 : 0;
26 assertEquals(expected, instance.exports.load(i));
27 }
28 }
29
30 SimpleDataSegmentTest(0);
31 SimpleDataSegmentTest(4);
32 SimpleDataSegmentTest(12);
33 SimpleDataSegmentTest(1064);
34
35 function GlobalInitTest(offset) {
36 print("GlobalInitTest(" + offset + ")...");
37 var builder = new WasmModuleBuilder();
38 builder.addMemory(1, 1, false);
39 var g = builder.addGlobal(kAstI32, false);
40 g.init = offset;
41 builder.addFunction("load", kSig_i_i)
42 .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0])
43 .exportAs("load");
44 builder.addDataSegment(g.index, [7, 7, 7, 7], true);
45
46 var buffer = builder.toBuffer(debug);
47 var instance = Wasm.instantiateModule(buffer);
48 for (var i = offset - 20; i < offset + 20; i += 4) {
49 if (i < 0) continue;
50 var expected = i == offset ? 117901063 : 0;
51 assertEquals(expected, instance.exports.load(i));
52 }
53 }
54
55 GlobalInitTest(0);
56 GlobalInitTest(12);
57 GlobalInitTest(3040);
58
59 function GlobalImportedInitTest(pad) {
60 print("GlobaleImportedInitTest(" + pad + ")...");
61 var builder = new WasmModuleBuilder();
62 builder.addMemory(1, 1, false);
63
64 while (pad-- > 0) builder.addGlobal(kAstI32); // pad
65
66 var g = builder.addImportedGlobal("offset", undefined, kAstI32);
67
68 while (pad-- > 0) builder.addGlobal(kAstI32); // pad
69
70 builder.addFunction("load", kSig_i_i)
71 .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0])
72 .exportAs("load");
73 builder.addDataSegment(g.index, [5, 5, 5, 5], true);
74
75 var buffer = builder.toBuffer(debug);
76 var module = new WebAssembly.Module(buffer);
77
78 for (var offset of [0, 12, 192, 1024]) {
79 var instance = new WebAssembly.Instance(module, {offset: offset});
80 for (var i = offset - 20; i < offset + 20; i += 4) {
81 if (i < 0) continue;
82 var expected = i == offset ? 84215045 : 0;
83 assertEquals(expected, instance.exports.load(i));
84 }
85 }
86 }
87
88 GlobalImportedInitTest(0);
89 GlobalImportedInitTest(1);
90 GlobalImportedInitTest(4);
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.cc ('k') | test/mjsunit/wasm/test-wasm-module-builder.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698