Index: test/cctest/wasm/test-run-wasm-interpreter.cc |
diff --git a/test/cctest/wasm/test-run-wasm-interpreter.cc b/test/cctest/wasm/test-run-wasm-interpreter.cc |
index 0489d016d7ba4ef52fe67283fdcfcacebb5293f1..e716b29f7d66a180579b6a980544661e448c2c25 100644 |
--- a/test/cctest/wasm/test-run-wasm-interpreter.cc |
+++ b/test/cctest/wasm/test-run-wasm-interpreter.cc |
@@ -333,6 +333,72 @@ TEST(GrowMemoryInvalidSize) { |
} |
} |
+TEST(TestPossibleNondeterminism) { |
+ { |
+ // F32Div may produced NaN |
+ TestingModule module(kExecuteInterpreted); |
+ WasmRunner<float> r(&module, MachineType::Float32(), |
+ MachineType::Float32()); |
+ BUILD(r, WASM_F32_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
+ r.Call(1048575.5f, 2.5f); |
+ CHECK(!r.possible_nondeterminism()); |
+ r.Call(0.0f, 0.0f); |
+ CHECK(r.possible_nondeterminism()); |
+ } |
+ { |
+ // F32Sqrt may produced NaN |
+ TestingModule module(kExecuteInterpreted); |
+ WasmRunner<float> r(&module, MachineType::Float32()); |
+ BUILD(r, WASM_F32_SQRT(WASM_GET_LOCAL(0))); |
+ r.Call(16.0f); |
+ CHECK(!r.possible_nondeterminism()); |
+ r.Call(-1048575.5f); |
+ CHECK(r.possible_nondeterminism()); |
+ } |
+ { |
+ // F32Mul may produced NaN |
+ TestingModule module(kExecuteInterpreted); |
+ WasmRunner<float> r(&module, MachineType::Float32(), |
+ MachineType::Float32()); |
+ BUILD(r, WASM_F32_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
+ r.Call(1048575.5f, 2.5f); |
+ CHECK(!r.possible_nondeterminism()); |
+ r.Call(std::numeric_limits<float>::infinity(), 0.0f); |
+ CHECK(r.possible_nondeterminism()); |
+ } |
+ { |
+ // F64Div may produced NaN |
+ TestingModule module(kExecuteInterpreted); |
+ WasmRunner<double> r(&module, MachineType::Float64(), |
+ MachineType::Float64()); |
+ BUILD(r, WASM_F64_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
+ r.Call(1048575.5, 2.5); |
+ CHECK(!r.possible_nondeterminism()); |
+ r.Call(0.0, 0.0); |
+ CHECK(r.possible_nondeterminism()); |
+ } |
+ { |
+ // F64Sqrt may produced NaN |
+ TestingModule module(kExecuteInterpreted); |
+ WasmRunner<double> r(&module, MachineType::Float64()); |
+ BUILD(r, WASM_F64_SQRT(WASM_GET_LOCAL(0))); |
+ r.Call(1048575.5); |
+ CHECK(!r.possible_nondeterminism()); |
+ r.Call(-1048575.5); |
+ CHECK(r.possible_nondeterminism()); |
+ } |
+ { |
+ // F64Mul may produced NaN |
+ TestingModule module(kExecuteInterpreted); |
+ WasmRunner<double> r(&module, MachineType::Float64(), |
+ MachineType::Float64()); |
+ BUILD(r, WASM_F64_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
+ r.Call(1048575.5, 2.5); |
+ CHECK(!r.possible_nondeterminism()); |
+ r.Call(std::numeric_limits<double>::infinity(), 0.0); |
+ CHECK(r.possible_nondeterminism()); |
+ } |
+} |
} // namespace wasm |
} // namespace internal |
} // namespace v8 |