OLD | NEW |
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, false); |
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 * 2]; | 68 byte code[kMaxConsts * 2]; |
69 for (int count = 1; count < kMaxConsts; count++) { | 69 for (int count = 1; count < kMaxConsts; count++) { |
70 for (int i = 0; i < count; i++) { | 70 for (int i = 0; i < count; i++) { |
71 code[i * 2] = kExprI8Const; | 71 code[i * 2] = kExprI8Const; |
72 code[i * 2 + 1] = static_cast<byte>(count * 10 + i); | 72 code[i * 2 + 1] = static_cast<byte>(count * 10 + i); |
73 } | 73 } |
74 byte expected = static_cast<byte>(count * 11 - 1); | 74 byte expected = static_cast<byte>(count * 11 - 1); |
75 | 75 |
76 WasmRunner<int32_t> r(kExecuteInterpreted); | 76 WasmRunner<int32_t> r(kExecuteInterpreted); |
77 r.Build(code, code + (count * 2)); | 77 r.Build(code, code + (count * 2), false); |
78 CHECK_EQ(expected, r.Call()); | 78 CHECK_EQ(expected, r.Call()); |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
82 TEST(Run_WasmBlocksN) { | 82 TEST(Run_WasmBlocksN) { |
83 const int kMaxNops = 10; | 83 const int kMaxNops = 10; |
84 const int kExtra = 4; | 84 const int kExtra = 4; |
85 byte code[kMaxNops + kExtra]; | 85 byte code[kMaxNops + kExtra]; |
86 for (int nops = 0; nops < kMaxNops; nops++) { | 86 for (int nops = 0; nops < kMaxNops; nops++) { |
87 byte expected = static_cast<byte>(30 + nops); | 87 byte expected = static_cast<byte>(30 + nops); |
88 memset(code, kExprNop, sizeof(code)); | 88 memset(code, kExprNop, sizeof(code)); |
89 code[0] = kExprBlock; | 89 code[0] = kExprBlock; |
90 code[1 + nops] = kExprI8Const; | 90 code[1 + nops] = kExprI8Const; |
91 code[1 + nops + 1] = expected; | 91 code[1 + nops + 1] = expected; |
92 code[1 + nops + 2] = kExprEnd; | 92 code[1 + nops + 2] = kExprEnd; |
93 | 93 |
94 WasmRunner<int32_t> r(kExecuteInterpreted); | 94 WasmRunner<int32_t> r(kExecuteInterpreted); |
95 r.Build(code, code + nops + kExtra); | 95 r.Build(code, code + nops + kExtra, false); |
96 CHECK_EQ(expected, r.Call()); | 96 CHECK_EQ(expected, r.Call()); |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 TEST(Run_WasmBlockBreakN) { | 100 TEST(Run_WasmBlockBreakN) { |
101 const int kMaxNops = 10; | 101 const int kMaxNops = 10; |
102 const int kExtra = 6; | 102 const int kExtra = 6; |
103 byte code[kMaxNops + kExtra]; | 103 byte code[kMaxNops + kExtra]; |
104 for (int nops = 0; nops < kMaxNops; nops++) { | 104 for (int nops = 0; nops < kMaxNops; nops++) { |
105 // Place the break anywhere within the block. | 105 // Place the break anywhere within the block. |
106 for (int index = 0; index < nops; index++) { | 106 for (int index = 0; index < nops; index++) { |
107 memset(code, kExprNop, sizeof(code)); | 107 memset(code, kExprNop, sizeof(code)); |
108 code[0] = kExprBlock; | 108 code[0] = kExprBlock; |
109 code[sizeof(code) - 1] = kExprEnd; | 109 code[sizeof(code) - 1] = kExprEnd; |
110 | 110 |
111 int expected = nops * 11 + index; | 111 int expected = nops * 11 + index; |
112 code[1 + index + 0] = kExprI8Const; | 112 code[1 + index + 0] = kExprI8Const; |
113 code[1 + index + 1] = static_cast<byte>(expected); | 113 code[1 + index + 1] = static_cast<byte>(expected); |
114 code[1 + index + 2] = kExprBr; | 114 code[1 + index + 2] = kExprBr; |
115 code[1 + index + 3] = ARITY_1; | 115 code[1 + index + 3] = ARITY_1; |
116 code[1 + index + 4] = 0; | 116 code[1 + index + 4] = 0; |
117 | 117 |
118 WasmRunner<int32_t> r(kExecuteInterpreted); | 118 WasmRunner<int32_t> r(kExecuteInterpreted); |
119 r.Build(code, code + kMaxNops + kExtra); | 119 r.Build(code, code + kMaxNops + kExtra, false); |
120 CHECK_EQ(expected, r.Call()); | 120 CHECK_EQ(expected, r.Call()); |
121 } | 121 } |
122 } | 122 } |
123 } | 123 } |
124 | 124 |
125 TEST(Run_Wasm_nested_ifs_i) { | 125 TEST(Run_Wasm_nested_ifs_i) { |
126 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32(), | 126 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32(), |
127 MachineType::Int32()); | 127 MachineType::Int32()); |
128 | 128 |
129 BUILD(r, WASM_IF_ELSE( | 129 BUILD(r, WASM_IF_ELSE( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 static const int kLocalsDeclSize = 1; | 168 static const int kLocalsDeclSize = 1; |
169 static const int kNumBreakpoints = 3; | 169 static const int kNumBreakpoints = 3; |
170 byte code[] = {WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; | 170 byte code[] = {WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; |
171 std::unique_ptr<int[]> offsets = | 171 std::unique_ptr<int[]> offsets = |
172 Find(code, sizeof(code), kNumBreakpoints, kExprGetLocal, kExprGetLocal, | 172 Find(code, sizeof(code), kNumBreakpoints, kExprGetLocal, kExprGetLocal, |
173 kExprI32Add); | 173 kExprI32Add); |
174 | 174 |
175 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(), | 175 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(), |
176 MachineType::Uint32()); | 176 MachineType::Uint32()); |
177 | 177 |
178 r.Build(code, code + arraysize(code)); | 178 r.Build(code, code + arraysize(code), false); |
179 | 179 |
180 WasmInterpreter* interpreter = r.interpreter(); | 180 WasmInterpreter* interpreter = r.interpreter(); |
181 WasmInterpreter::Thread* thread = interpreter->GetThread(0); | 181 WasmInterpreter::Thread* thread = interpreter->GetThread(0); |
182 for (int i = 0; i < kNumBreakpoints; i++) { | 182 for (int i = 0; i < kNumBreakpoints; i++) { |
183 interpreter->SetBreakpoint(r.function(), kLocalsDeclSize + offsets[i], | 183 interpreter->SetBreakpoint(r.function(), kLocalsDeclSize + offsets[i], |
184 true); | 184 true); |
185 } | 185 } |
186 | 186 |
187 FOR_UINT32_INPUTS(a) { | 187 FOR_UINT32_INPUTS(a) { |
188 for (uint32_t b = 11; b < 3000000000u; b += 1000000000u) { | 188 for (uint32_t b = 11; b < 3000000000u; b += 1000000000u) { |
(...skipping 18 matching lines...) Expand all Loading... |
207 } | 207 } |
208 } | 208 } |
209 | 209 |
210 TEST(Step_I32Mul) { | 210 TEST(Step_I32Mul) { |
211 static const int kTraceLength = 4; | 211 static const int kTraceLength = 4; |
212 byte code[] = {WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; | 212 byte code[] = {WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; |
213 | 213 |
214 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(), | 214 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(), |
215 MachineType::Uint32()); | 215 MachineType::Uint32()); |
216 | 216 |
217 r.Build(code, code + arraysize(code)); | 217 r.Build(code, code + arraysize(code), false); |
218 | 218 |
219 WasmInterpreter* interpreter = r.interpreter(); | 219 WasmInterpreter* interpreter = r.interpreter(); |
220 WasmInterpreter::Thread* thread = interpreter->GetThread(0); | 220 WasmInterpreter::Thread* thread = interpreter->GetThread(0); |
221 | 221 |
222 FOR_UINT32_INPUTS(a) { | 222 FOR_UINT32_INPUTS(a) { |
223 for (uint32_t b = 33; b < 3000000000u; b += 1000000000u) { | 223 for (uint32_t b = 33; b < 3000000000u; b += 1000000000u) { |
224 thread->Reset(); | 224 thread->Reset(); |
225 WasmVal args[] = {WasmVal(*a), WasmVal(b)}; | 225 WasmVal args[] = {WasmVal(*a), WasmVal(b)}; |
226 thread->PushFrame(r.function(), args); | 226 thread->PushFrame(r.function(), args); |
227 | 227 |
(...skipping 18 matching lines...) Expand all Loading... |
246 TEST(Breakpoint_I32And_disable) { | 246 TEST(Breakpoint_I32And_disable) { |
247 static const int kLocalsDeclSize = 1; | 247 static const int kLocalsDeclSize = 1; |
248 static const int kNumBreakpoints = 1; | 248 static const int kNumBreakpoints = 1; |
249 byte code[] = {WASM_I32_AND(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; | 249 byte code[] = {WASM_I32_AND(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; |
250 std::unique_ptr<int[]> offsets = | 250 std::unique_ptr<int[]> offsets = |
251 Find(code, sizeof(code), kNumBreakpoints, kExprI32And); | 251 Find(code, sizeof(code), kNumBreakpoints, kExprI32And); |
252 | 252 |
253 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(), | 253 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(), |
254 MachineType::Uint32()); | 254 MachineType::Uint32()); |
255 | 255 |
256 r.Build(code, code + arraysize(code)); | 256 r.Build(code, code + arraysize(code), false); |
257 | 257 |
258 WasmInterpreter* interpreter = r.interpreter(); | 258 WasmInterpreter* interpreter = r.interpreter(); |
259 WasmInterpreter::Thread* thread = interpreter->GetThread(0); | 259 WasmInterpreter::Thread* thread = interpreter->GetThread(0); |
260 | 260 |
261 FOR_UINT32_INPUTS(a) { | 261 FOR_UINT32_INPUTS(a) { |
262 for (uint32_t b = 11; b < 3000000000u; b += 1000000000u) { | 262 for (uint32_t b = 11; b < 3000000000u; b += 1000000000u) { |
263 // Run with and without breakpoints. | 263 // Run with and without breakpoints. |
264 for (int do_break = 0; do_break < 2; do_break++) { | 264 for (int do_break = 0; do_break < 2; do_break++) { |
265 interpreter->SetBreakpoint(r.function(), kLocalsDeclSize + offsets[0], | 265 interpreter->SetBreakpoint(r.function(), kLocalsDeclSize + offsets[0], |
266 do_break); | 266 do_break); |
(...skipping 15 matching lines...) Expand all Loading... |
282 uint32_t expected = (*a) & (b); | 282 uint32_t expected = (*a) & (b); |
283 CHECK_EQ(expected, thread->GetReturnValue().to<uint32_t>()); | 283 CHECK_EQ(expected, thread->GetReturnValue().to<uint32_t>()); |
284 } | 284 } |
285 } | 285 } |
286 } | 286 } |
287 } | 287 } |
288 | 288 |
289 } // namespace wasm | 289 } // namespace wasm |
290 } // namespace internal | 290 } // namespace internal |
291 } // namespace v8 | 291 } // namespace v8 |
OLD | NEW |