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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 { | 326 { |
327 // Grow memory by an invalid amount without initial memory. | 327 // Grow memory by an invalid amount without initial memory. |
328 TestingModule module(kExecuteInterpreted); | 328 TestingModule module(kExecuteInterpreted); |
329 WasmRunner<int32_t> r(&module, MachineType::Uint32()); | 329 WasmRunner<int32_t> r(&module, MachineType::Uint32()); |
330 module.AddMemory(WasmModule::kPageSize); | 330 module.AddMemory(WasmModule::kPageSize); |
331 BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0))); | 331 BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0))); |
332 CHECK_EQ(-1, r.Call(1048575)); | 332 CHECK_EQ(-1, r.Call(1048575)); |
333 } | 333 } |
334 } | 334 } |
335 | 335 |
| 336 TEST(TestPossibleNondeterminism) { |
| 337 { |
| 338 // F32Div may produced NaN |
| 339 TestingModule module(kExecuteInterpreted); |
| 340 WasmRunner<float> r(&module, MachineType::Float32(), |
| 341 MachineType::Float32()); |
| 342 BUILD(r, WASM_F32_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
| 343 r.Call(1048575.5f, 2.5f); |
| 344 CHECK(!r.possible_nondeterminism()); |
| 345 r.Call(0.0f, 0.0f); |
| 346 CHECK(r.possible_nondeterminism()); |
| 347 } |
| 348 { |
| 349 // F32Sqrt may produced NaN |
| 350 TestingModule module(kExecuteInterpreted); |
| 351 WasmRunner<float> r(&module, MachineType::Float32()); |
| 352 BUILD(r, WASM_F32_SQRT(WASM_GET_LOCAL(0))); |
| 353 r.Call(16.0f); |
| 354 CHECK(!r.possible_nondeterminism()); |
| 355 r.Call(-1048575.5f); |
| 356 CHECK(r.possible_nondeterminism()); |
| 357 } |
| 358 { |
| 359 // F32Mul may produced NaN |
| 360 TestingModule module(kExecuteInterpreted); |
| 361 WasmRunner<float> r(&module, MachineType::Float32(), |
| 362 MachineType::Float32()); |
| 363 BUILD(r, WASM_F32_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
| 364 r.Call(1048575.5f, 2.5f); |
| 365 CHECK(!r.possible_nondeterminism()); |
| 366 r.Call(std::numeric_limits<float>::infinity(), 0.0f); |
| 367 CHECK(r.possible_nondeterminism()); |
| 368 } |
| 369 { |
| 370 // F64Div may produced NaN |
| 371 TestingModule module(kExecuteInterpreted); |
| 372 WasmRunner<double> r(&module, MachineType::Float64(), |
| 373 MachineType::Float64()); |
| 374 BUILD(r, WASM_F64_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
| 375 r.Call(1048575.5, 2.5); |
| 376 CHECK(!r.possible_nondeterminism()); |
| 377 r.Call(0.0, 0.0); |
| 378 CHECK(r.possible_nondeterminism()); |
| 379 } |
| 380 { |
| 381 // F64Sqrt may produced NaN |
| 382 TestingModule module(kExecuteInterpreted); |
| 383 WasmRunner<double> r(&module, MachineType::Float64()); |
| 384 BUILD(r, WASM_F64_SQRT(WASM_GET_LOCAL(0))); |
| 385 r.Call(1048575.5); |
| 386 CHECK(!r.possible_nondeterminism()); |
| 387 r.Call(-1048575.5); |
| 388 CHECK(r.possible_nondeterminism()); |
| 389 } |
| 390 { |
| 391 // F64Mul may produced NaN |
| 392 TestingModule module(kExecuteInterpreted); |
| 393 WasmRunner<double> r(&module, MachineType::Float64(), |
| 394 MachineType::Float64()); |
| 395 BUILD(r, WASM_F64_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
| 396 r.Call(1048575.5, 2.5); |
| 397 CHECK(!r.possible_nondeterminism()); |
| 398 r.Call(std::numeric_limits<double>::infinity(), 0.0); |
| 399 CHECK(r.possible_nondeterminism()); |
| 400 } |
| 401 } |
336 } // namespace wasm | 402 } // namespace wasm |
337 } // namespace internal | 403 } // namespace internal |
338 } // namespace v8 | 404 } // namespace v8 |
OLD | NEW |