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

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

Issue 2671803002: [wasm] Refactor the non-determinism detection in the interpreter. (Closed)
Patch Set: Also adjust copysign Created 3 years, 10 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-interpreter.cc ('k') | no next file » | 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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 // Grow memory by an invalid amount without initial memory. 336 // Grow memory by an invalid amount without initial memory.
337 WasmRunner<int32_t, uint32_t> r(kExecuteInterpreted); 337 WasmRunner<int32_t, uint32_t> r(kExecuteInterpreted);
338 r.module().AddMemory(WasmModule::kPageSize); 338 r.module().AddMemory(WasmModule::kPageSize);
339 BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0))); 339 BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0)));
340 CHECK_EQ(-1, r.Call(1048575)); 340 CHECK_EQ(-1, r.Call(1048575));
341 } 341 }
342 } 342 }
343 343
344 TEST(TestPossibleNondeterminism) { 344 TEST(TestPossibleNondeterminism) {
345 { 345 {
346 // F32Div may produced NaN 346 WasmRunner<int32_t, float> r(kExecuteInterpreted);
347 WasmRunner<float, float, float> r(kExecuteInterpreted); 347 BUILD(r, WASM_I32_REINTERPRET_F32(WASM_GET_LOCAL(0)));
348 BUILD(r, WASM_F32_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 348 r.Call(1048575.5f);
349 r.Call(1048575.5f, 2.5f);
350 CHECK(!r.possible_nondeterminism()); 349 CHECK(!r.possible_nondeterminism());
351 r.Call(0.0f, 0.0f); 350 r.Call(std::numeric_limits<float>::quiet_NaN());
352 CHECK(r.possible_nondeterminism()); 351 CHECK(r.possible_nondeterminism());
353 } 352 }
354 { 353 {
355 // F32Sqrt may produced NaN 354 WasmRunner<int64_t, double> r(kExecuteInterpreted);
356 WasmRunner<float, float> r(kExecuteInterpreted); 355 BUILD(r, WASM_I64_REINTERPRET_F64(WASM_GET_LOCAL(0)));
357 BUILD(r, WASM_F32_SQRT(WASM_GET_LOCAL(0))); 356 r.Call(16.0);
358 r.Call(16.0f);
359 CHECK(!r.possible_nondeterminism()); 357 CHECK(!r.possible_nondeterminism());
360 r.Call(-1048575.5f); 358 r.Call(std::numeric_limits<double>::quiet_NaN());
361 CHECK(r.possible_nondeterminism()); 359 CHECK(r.possible_nondeterminism());
362 } 360 }
363 { 361 {
364 // F32Mul may produced NaN 362 WasmRunner<float, float> r(kExecuteInterpreted);
365 WasmRunner<float, float, float> r(kExecuteInterpreted); 363 BUILD(r, WASM_F32_COPYSIGN(WASM_F32(42.0f), WASM_GET_LOCAL(0)));
366 BUILD(r, WASM_F32_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 364 r.Call(16.0f);
367 r.Call(1048575.5f, 2.5f);
368 CHECK(!r.possible_nondeterminism()); 365 CHECK(!r.possible_nondeterminism());
369 r.Call(std::numeric_limits<float>::infinity(), 0.0f); 366 r.Call(std::numeric_limits<double>::quiet_NaN());
370 CHECK(r.possible_nondeterminism()); 367 CHECK(r.possible_nondeterminism());
371 } 368 }
372 { 369 {
373 // F64Div may produced NaN 370 WasmRunner<double, double> r(kExecuteInterpreted);
374 WasmRunner<double, double, double> r(kExecuteInterpreted); 371 BUILD(r, WASM_F64_COPYSIGN(WASM_F64(42.0), WASM_GET_LOCAL(0)));
375 BUILD(r, WASM_F64_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 372 r.Call(16.0);
376 r.Call(1048575.5, 2.5);
377 CHECK(!r.possible_nondeterminism()); 373 CHECK(!r.possible_nondeterminism());
378 r.Call(0.0, 0.0); 374 r.Call(std::numeric_limits<double>::quiet_NaN());
379 CHECK(r.possible_nondeterminism()); 375 CHECK(r.possible_nondeterminism());
380 } 376 }
381 { 377 {
382 // F64Sqrt may produced NaN 378 int32_t index = 16;
383 WasmRunner<double, double> r(kExecuteInterpreted); 379 WasmRunner<int32_t, float> r(kExecuteInterpreted);
384 BUILD(r, WASM_F64_SQRT(WASM_GET_LOCAL(0))); 380 r.module().AddMemory(WasmModule::kPageSize);
385 r.Call(1048575.5); 381 BUILD(r, WASM_STORE_MEM(MachineType::Float32(), WASM_I32V(index),
382 WASM_GET_LOCAL(0)),
383 WASM_I32V(index));
384 r.Call(1345.3456f);
386 CHECK(!r.possible_nondeterminism()); 385 CHECK(!r.possible_nondeterminism());
387 r.Call(-1048575.5); 386 r.Call(std::numeric_limits<float>::quiet_NaN());
388 CHECK(r.possible_nondeterminism()); 387 CHECK(r.possible_nondeterminism());
389 } 388 }
390 { 389 {
391 // F64Mul may produced NaN 390 int32_t index = 16;
392 WasmRunner<double, double, double> r(kExecuteInterpreted); 391 WasmRunner<int32_t, double> r(kExecuteInterpreted);
393 BUILD(r, WASM_F64_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 392 r.module().AddMemory(WasmModule::kPageSize);
394 r.Call(1048575.5, 2.5); 393 BUILD(r, WASM_STORE_MEM(MachineType::Float64(), WASM_I32V(index),
394 WASM_GET_LOCAL(0)),
395 WASM_I32V(index));
396 r.Call(1345.3456);
395 CHECK(!r.possible_nondeterminism()); 397 CHECK(!r.possible_nondeterminism());
396 r.Call(std::numeric_limits<double>::infinity(), 0.0); 398 r.Call(std::numeric_limits<double>::quiet_NaN());
397 CHECK(r.possible_nondeterminism()); 399 CHECK(r.possible_nondeterminism());
398 } 400 }
399 } 401 }
400 } // namespace wasm 402 } // namespace wasm
401 } // namespace internal 403 } // namespace internal
402 } // namespace v8 404 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/wasm-interpreter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698