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

Side by Side Diff: test/cctest/wasm/test-run-wasm-interpreter.cc

Issue 2361053004: Revert of [wasm] Master CL for Binary 0xC changes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 3 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 | « test/cctest/wasm/test-run-wasm-64.cc ('k') | test/cctest/wasm/test-run-wasm-js.cc » ('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 2016 the V8 project authors. All rights reserved. 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 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 #include <stdint.h> 5 #include <stdint.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 18 matching lines...) Expand all
29 TEST(Run_WasmInt8Const_i) { 29 TEST(Run_WasmInt8Const_i) {
30 WasmRunner<int32_t> r(kExecuteInterpreted); 30 WasmRunner<int32_t> r(kExecuteInterpreted);
31 const byte kExpectedValue = 109; 31 const byte kExpectedValue = 109;
32 // return(kExpectedValue) 32 // return(kExpectedValue)
33 BUILD(r, WASM_I8(kExpectedValue)); 33 BUILD(r, WASM_I8(kExpectedValue));
34 CHECK_EQ(kExpectedValue, r.Call()); 34 CHECK_EQ(kExpectedValue, r.Call());
35 } 35 }
36 36
37 TEST(Run_WasmIfElse) { 37 TEST(Run_WasmIfElse) {
38 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32()); 38 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32());
39 BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(9), WASM_I8(10))); 39 BUILD(r, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_I8(9), WASM_I8(10)));
40 CHECK_EQ(10, r.Call(0)); 40 CHECK_EQ(10, r.Call(0));
41 CHECK_EQ(9, r.Call(1)); 41 CHECK_EQ(9, r.Call(1));
42 } 42 }
43 43
44 TEST(Run_WasmIfReturn) { 44 TEST(Run_WasmIfReturn) {
45 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32()); 45 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32());
46 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_RETURN1(WASM_I8(77))), WASM_I8(65)); 46 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_RETURN1(WASM_I8(77))), WASM_I8(65));
47 CHECK_EQ(65, r.Call(0)); 47 CHECK_EQ(65, r.Call(0));
48 CHECK_EQ(77, r.Call(1)); 48 CHECK_EQ(77, r.Call(1));
49 } 49 }
50 50
51 TEST(Run_WasmNopsN) { 51 TEST(Run_WasmNopsN) {
52 const int kMaxNops = 10; 52 const int kMaxNops = 10;
53 byte code[kMaxNops + 2]; 53 byte code[kMaxNops + 2];
54 for (int nops = 0; nops < kMaxNops; nops++) { 54 for (int nops = 0; nops < kMaxNops; nops++) {
55 byte expected = static_cast<byte>(20 + nops); 55 byte expected = static_cast<byte>(20 + nops);
56 memset(code, kExprNop, sizeof(code)); 56 memset(code, kExprNop, sizeof(code));
57 code[nops] = kExprI8Const; 57 code[nops] = kExprI8Const;
58 code[nops + 1] = expected; 58 code[nops + 1] = expected;
59 59
60 WasmRunner<int32_t> r(kExecuteInterpreted); 60 WasmRunner<int32_t> r(kExecuteInterpreted);
61 r.Build(code, code + nops + 2); 61 r.Build(code, code + nops + 2);
62 CHECK_EQ(expected, r.Call()); 62 CHECK_EQ(expected, r.Call());
63 } 63 }
64 } 64 }
65 65
66 TEST(Run_WasmConstsN) { 66 TEST(Run_WasmConstsN) {
67 const int kMaxConsts = 10; 67 const int kMaxConsts = 10;
68 byte code[kMaxConsts * 3]; 68 byte code[kMaxConsts * 2];
69 int32_t expected = 0;
70 for (int count = 1; count < kMaxConsts; count++) { 69 for (int count = 1; count < kMaxConsts; count++) {
71 for (int i = 0; i < count; i++) { 70 for (int i = 0; i < count; i++) {
72 byte val = static_cast<byte>(count * 10 + i); 71 code[i * 2] = kExprI8Const;
73 code[i * 3] = kExprI8Const; 72 code[i * 2 + 1] = static_cast<byte>(count * 10 + i);
74 code[i * 3 + 1] = val;
75 if (i == (count - 1)) {
76 code[i * 3 + 2] = kExprNop;
77 expected = val;
78 } else {
79 code[i * 3 + 2] = kExprDrop;
80 }
81 } 73 }
74 byte expected = static_cast<byte>(count * 11 - 1);
82 75
83 WasmRunner<int32_t> r(kExecuteInterpreted); 76 WasmRunner<int32_t> r(kExecuteInterpreted);
84 r.Build(code, code + (count * 3)); 77 r.Build(code, code + (count * 2));
85 CHECK_EQ(expected, r.Call()); 78 CHECK_EQ(expected, r.Call());
86 } 79 }
87 } 80 }
88 81
89 TEST(Run_WasmBlocksN) { 82 TEST(Run_WasmBlocksN) {
90 const int kMaxNops = 10; 83 const int kMaxNops = 10;
91 const int kExtra = 5; 84 const int kExtra = 4;
92 byte code[kMaxNops + kExtra]; 85 byte code[kMaxNops + kExtra];
93 for (int nops = 0; nops < kMaxNops; nops++) { 86 for (int nops = 0; nops < kMaxNops; nops++) {
94 byte expected = static_cast<byte>(30 + nops); 87 byte expected = static_cast<byte>(30 + nops);
95 memset(code, kExprNop, sizeof(code)); 88 memset(code, kExprNop, sizeof(code));
96 code[0] = kExprBlock; 89 code[0] = kExprBlock;
97 code[1] = kLocalI32; 90 code[1 + nops] = kExprI8Const;
98 code[2 + nops] = kExprI8Const; 91 code[1 + nops + 1] = expected;
99 code[2 + nops + 1] = expected; 92 code[1 + nops + 2] = kExprEnd;
100 code[2 + nops + 2] = kExprEnd;
101 93
102 WasmRunner<int32_t> r(kExecuteInterpreted); 94 WasmRunner<int32_t> r(kExecuteInterpreted);
103 r.Build(code, code + nops + kExtra); 95 r.Build(code, code + nops + kExtra);
104 CHECK_EQ(expected, r.Call()); 96 CHECK_EQ(expected, r.Call());
105 } 97 }
106 } 98 }
107 99
108 TEST(Run_WasmBlockBreakN) { 100 TEST(Run_WasmBlockBreakN) {
109 const int kMaxNops = 10; 101 const int kMaxNops = 10;
110 const int kExtra = 6; 102 const int kExtra = 6;
111 byte code[kMaxNops + kExtra]; 103 byte code[kMaxNops + kExtra];
112 for (int nops = 0; nops < kMaxNops; nops++) { 104 for (int nops = 0; nops < kMaxNops; nops++) {
113 // Place the break anywhere within the block. 105 // Place the break anywhere within the block.
114 for (int index = 0; index < nops; index++) { 106 for (int index = 0; index < nops; index++) {
115 memset(code, kExprNop, sizeof(code)); 107 memset(code, kExprNop, sizeof(code));
116 code[0] = kExprBlock; 108 code[0] = kExprBlock;
117 code[1] = kLocalI32;
118 code[sizeof(code) - 1] = kExprEnd; 109 code[sizeof(code) - 1] = kExprEnd;
119 110
120 int expected = nops * 11 + index; 111 int expected = nops * 11 + index;
121 code[2 + index + 0] = kExprI8Const; 112 code[1 + index + 0] = kExprI8Const;
122 code[2 + index + 1] = static_cast<byte>(expected); 113 code[1 + index + 1] = static_cast<byte>(expected);
123 code[2 + index + 2] = kExprBr; 114 code[1 + index + 2] = kExprBr;
124 code[2 + index + 3] = 0; 115 code[1 + index + 3] = ARITY_1;
116 code[1 + index + 4] = 0;
125 117
126 WasmRunner<int32_t> r(kExecuteInterpreted); 118 WasmRunner<int32_t> r(kExecuteInterpreted);
127 r.Build(code, code + kMaxNops + kExtra); 119 r.Build(code, code + kMaxNops + kExtra);
128 CHECK_EQ(expected, r.Call()); 120 CHECK_EQ(expected, r.Call());
129 } 121 }
130 } 122 }
131 } 123 }
132 124
133 TEST(Run_Wasm_nested_ifs_i) { 125 TEST(Run_Wasm_nested_ifs_i) {
134 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32(), 126 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32(),
135 MachineType::Int32()); 127 MachineType::Int32());
136 128
137 BUILD(r, WASM_IF_ELSE_I( 129 BUILD(r, WASM_IF_ELSE(
138 WASM_GET_LOCAL(0), 130 WASM_GET_LOCAL(0),
139 WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I8(11), WASM_I8(12)), 131 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_I8(11), WASM_I8(12)),
140 WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I8(13), WASM_I8(14)))); 132 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_I8(13), WASM_I8(14))));
141 133
142 CHECK_EQ(11, r.Call(1, 1)); 134 CHECK_EQ(11, r.Call(1, 1));
143 CHECK_EQ(12, r.Call(1, 0)); 135 CHECK_EQ(12, r.Call(1, 0));
144 CHECK_EQ(13, r.Call(0, 1)); 136 CHECK_EQ(13, r.Call(0, 1));
145 CHECK_EQ(14, r.Call(0, 0)); 137 CHECK_EQ(14, r.Call(0, 0));
146 } 138 }
147 139
148 // Make tests more robust by not hard-coding offsets of various operations. 140 // Make tests more robust by not hard-coding offsets of various operations.
149 // The {Find} method finds the offsets for the given bytecodes, returning 141 // The {Find} method finds the offsets for the given bytecodes, returning
150 // the offsets in an array. 142 // the offsets in an array.
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0))); 293 BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0)));
302 CHECK_EQ(1, r.Call(1)); 294 CHECK_EQ(1, r.Call(1));
303 } 295 }
304 296
305 TEST(GrowMemoryPreservesData) { 297 TEST(GrowMemoryPreservesData) {
306 int32_t index = 16; 298 int32_t index = 16;
307 int32_t value = 2335; 299 int32_t value = 2335;
308 TestingModule module(kExecuteInterpreted); 300 TestingModule module(kExecuteInterpreted);
309 WasmRunner<int32_t> r(&module, MachineType::Uint32()); 301 WasmRunner<int32_t> r(&module, MachineType::Uint32());
310 module.AddMemory(WasmModule::kPageSize); 302 module.AddMemory(WasmModule::kPageSize);
311 BUILD(r, WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index), 303 BUILD(r, WASM_BLOCK(WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index),
312 WASM_I32V(value)), 304 WASM_I32V(value)),
313 WASM_GROW_MEMORY(WASM_GET_LOCAL(0)), WASM_DROP, 305 WASM_GROW_MEMORY(WASM_GET_LOCAL(0)),
314 WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V(index))); 306 WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V(index))));
315 CHECK_EQ(value, r.Call(1)); 307 CHECK_EQ(value, r.Call(1));
316 } 308 }
317 309
318 TEST(GrowMemoryInvalidSize) { 310 TEST(GrowMemoryInvalidSize) {
319 { 311 {
320 // Grow memory by an invalid amount without initial memory. 312 // Grow memory by an invalid amount without initial memory.
321 TestingModule module(kExecuteInterpreted); 313 TestingModule module(kExecuteInterpreted);
322 WasmRunner<int32_t> r(&module, MachineType::Uint32()); 314 WasmRunner<int32_t> r(&module, MachineType::Uint32());
323 BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0))); 315 BUILD(r, WASM_BLOCK(WASM_GROW_MEMORY(WASM_GET_LOCAL(0))));
324 CHECK_EQ(-1, r.Call(1048575)); 316 CHECK_EQ(-1, r.Call(1048575));
325 } 317 }
326 { 318 {
327 // Grow memory by an invalid amount without initial memory. 319 // Grow memory by an invalid amount without initial memory.
328 TestingModule module(kExecuteInterpreted); 320 TestingModule module(kExecuteInterpreted);
329 WasmRunner<int32_t> r(&module, MachineType::Uint32()); 321 WasmRunner<int32_t> r(&module, MachineType::Uint32());
330 module.AddMemory(WasmModule::kPageSize); 322 module.AddMemory(WasmModule::kPageSize);
331 BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0))); 323 BUILD(r, WASM_BLOCK(WASM_GROW_MEMORY(WASM_GET_LOCAL(0))));
332 CHECK_EQ(-1, r.Call(1048575)); 324 CHECK_EQ(-1, r.Call(1048575));
333 } 325 }
334 } 326 }
335 327
336 } // namespace wasm 328 } // namespace wasm
337 } // namespace internal 329 } // namespace internal
338 } // namespace v8 330 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/wasm/test-run-wasm-64.cc ('k') | test/cctest/wasm/test-run-wasm-js.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698