2016-05-25 08:32:37 +00:00
|
|
|
// Copyright 2016 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2016-07-25 10:24:45 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2019-05-21 09:30:15 +00:00
|
|
|
#include "src/codegen/assembler-inl.h"
|
2016-05-25 08:32:37 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
|
|
|
#include "test/cctest/compiler/value-helper.h"
|
|
|
|
#include "test/cctest/wasm/wasm-run-utils.h"
|
2016-10-05 11:59:47 +00:00
|
|
|
#include "test/common/wasm/test-signatures.h"
|
2020-06-23 07:48:53 +00:00
|
|
|
#include "test/common/wasm/wasm-interpreter.h"
|
2017-04-25 11:29:17 +00:00
|
|
|
#include "test/common/wasm/wasm-macro-gen.h"
|
2016-05-25 08:32:37 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace wasm {
|
2017-09-21 03:29:52 +00:00
|
|
|
namespace test_run_wasm_interpreter {
|
2016-05-25 08:32:37 +00:00
|
|
|
|
|
|
|
TEST(Run_WasmInt8Const_i) {
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<int32_t> r(TestExecutionTier::kInterpreter);
|
2016-05-25 08:32:37 +00:00
|
|
|
const byte kExpectedValue = 109;
|
|
|
|
// return(kExpectedValue)
|
2017-01-09 13:57:26 +00:00
|
|
|
BUILD(r, WASM_I32V_2(kExpectedValue));
|
2016-05-25 08:32:37 +00:00
|
|
|
CHECK_EQ(kExpectedValue, r.Call());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Run_WasmIfElse) {
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<int32_t, int32_t> r(TestExecutionTier::kInterpreter);
|
2017-01-09 13:57:26 +00:00
|
|
|
BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I32V_1(9), WASM_I32V_1(10)));
|
2016-05-25 08:32:37 +00:00
|
|
|
CHECK_EQ(10, r.Call(0));
|
|
|
|
CHECK_EQ(9, r.Call(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Run_WasmIfReturn) {
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<int32_t, int32_t> r(TestExecutionTier::kInterpreter);
|
2017-01-09 13:57:26 +00:00
|
|
|
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_RETURN1(WASM_I32V_2(77))),
|
|
|
|
WASM_I32V_2(65));
|
2016-05-25 08:32:37 +00:00
|
|
|
CHECK_EQ(65, r.Call(0));
|
|
|
|
CHECK_EQ(77, r.Call(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Run_WasmNopsN) {
|
|
|
|
const int kMaxNops = 10;
|
|
|
|
byte code[kMaxNops + 2];
|
|
|
|
for (int nops = 0; nops < kMaxNops; nops++) {
|
|
|
|
byte expected = static_cast<byte>(20 + nops);
|
|
|
|
memset(code, kExprNop, sizeof(code));
|
2017-01-09 13:57:26 +00:00
|
|
|
code[nops] = kExprI32Const;
|
2016-05-25 08:32:37 +00:00
|
|
|
code[nops + 1] = expected;
|
|
|
|
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<int32_t> r(TestExecutionTier::kInterpreter);
|
2016-05-25 08:32:37 +00:00
|
|
|
r.Build(code, code + nops + 2);
|
|
|
|
CHECK_EQ(expected, r.Call());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Run_WasmConstsN) {
|
2017-01-09 13:57:26 +00:00
|
|
|
const int kMaxConsts = 5;
|
2016-09-27 20:46:10 +00:00
|
|
|
byte code[kMaxConsts * 3];
|
|
|
|
int32_t expected = 0;
|
2016-05-25 08:32:37 +00:00
|
|
|
for (int count = 1; count < kMaxConsts; count++) {
|
|
|
|
for (int i = 0; i < count; i++) {
|
2016-09-27 20:46:10 +00:00
|
|
|
byte val = static_cast<byte>(count * 10 + i);
|
2017-01-09 13:57:26 +00:00
|
|
|
code[i * 3] = kExprI32Const;
|
2016-09-27 20:46:10 +00:00
|
|
|
code[i * 3 + 1] = val;
|
|
|
|
if (i == (count - 1)) {
|
|
|
|
code[i * 3 + 2] = kExprNop;
|
|
|
|
expected = val;
|
|
|
|
} else {
|
|
|
|
code[i * 3 + 2] = kExprDrop;
|
|
|
|
}
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<int32_t> r(TestExecutionTier::kInterpreter);
|
2016-09-27 20:46:10 +00:00
|
|
|
r.Build(code, code + (count * 3));
|
2016-05-25 08:32:37 +00:00
|
|
|
CHECK_EQ(expected, r.Call());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Run_WasmBlocksN) {
|
|
|
|
const int kMaxNops = 10;
|
2016-09-27 20:46:10 +00:00
|
|
|
const int kExtra = 5;
|
2016-05-25 08:32:37 +00:00
|
|
|
byte code[kMaxNops + kExtra];
|
|
|
|
for (int nops = 0; nops < kMaxNops; nops++) {
|
|
|
|
byte expected = static_cast<byte>(30 + nops);
|
|
|
|
memset(code, kExprNop, sizeof(code));
|
|
|
|
code[0] = kExprBlock;
|
2016-09-27 20:46:10 +00:00
|
|
|
code[1] = kLocalI32;
|
2017-01-09 13:57:26 +00:00
|
|
|
code[2 + nops] = kExprI32Const;
|
2016-09-27 20:46:10 +00:00
|
|
|
code[2 + nops + 1] = expected;
|
|
|
|
code[2 + nops + 2] = kExprEnd;
|
2016-05-25 08:32:37 +00:00
|
|
|
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<int32_t> r(TestExecutionTier::kInterpreter);
|
2016-05-25 08:32:37 +00:00
|
|
|
r.Build(code, code + nops + kExtra);
|
|
|
|
CHECK_EQ(expected, r.Call());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Run_WasmBlockBreakN) {
|
|
|
|
const int kMaxNops = 10;
|
|
|
|
const int kExtra = 6;
|
2017-01-09 13:57:26 +00:00
|
|
|
int run = 0;
|
2016-05-25 08:32:37 +00:00
|
|
|
byte code[kMaxNops + kExtra];
|
|
|
|
for (int nops = 0; nops < kMaxNops; nops++) {
|
|
|
|
// Place the break anywhere within the block.
|
|
|
|
for (int index = 0; index < nops; index++) {
|
|
|
|
memset(code, kExprNop, sizeof(code));
|
|
|
|
code[0] = kExprBlock;
|
2016-09-27 20:46:10 +00:00
|
|
|
code[1] = kLocalI32;
|
2016-05-25 08:32:37 +00:00
|
|
|
code[sizeof(code) - 1] = kExprEnd;
|
|
|
|
|
2017-01-09 13:57:26 +00:00
|
|
|
int expected = run++;
|
|
|
|
code[2 + index + 0] = kExprI32Const;
|
2016-09-27 20:46:10 +00:00
|
|
|
code[2 + index + 1] = static_cast<byte>(expected);
|
|
|
|
code[2 + index + 2] = kExprBr;
|
|
|
|
code[2 + index + 3] = 0;
|
2016-05-25 08:32:37 +00:00
|
|
|
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<int32_t> r(TestExecutionTier::kInterpreter);
|
2016-05-25 08:32:37 +00:00
|
|
|
r.Build(code, code + kMaxNops + kExtra);
|
|
|
|
CHECK_EQ(expected, r.Call());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Run_Wasm_nested_ifs_i) {
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<int32_t, int32_t, int32_t> r(TestExecutionTier::kInterpreter);
|
2016-05-25 08:32:37 +00:00
|
|
|
|
2017-01-09 13:57:26 +00:00
|
|
|
BUILD(
|
|
|
|
r,
|
|
|
|
WASM_IF_ELSE_I(
|
|
|
|
WASM_GET_LOCAL(0),
|
|
|
|
WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I32V_1(11), WASM_I32V_1(12)),
|
|
|
|
WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I32V_1(13), WASM_I32V_1(14))));
|
2016-05-25 08:32:37 +00:00
|
|
|
|
|
|
|
CHECK_EQ(11, r.Call(1, 1));
|
|
|
|
CHECK_EQ(12, r.Call(1, 0));
|
|
|
|
CHECK_EQ(13, r.Call(0, 1));
|
|
|
|
CHECK_EQ(14, r.Call(0, 0));
|
|
|
|
}
|
|
|
|
|
2019-02-27 18:43:47 +00:00
|
|
|
// Repeated from test-run-wasm.cc to avoid poluting header files.
|
|
|
|
template <typename T>
|
|
|
|
static T factorial(T v) {
|
|
|
|
T expected = 1;
|
|
|
|
for (T i = v; i > 1; i--) {
|
|
|
|
expected *= i;
|
|
|
|
}
|
|
|
|
return expected;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Basic test of return call in interpreter. Good old factorial.
|
|
|
|
TEST(Run_Wasm_returnCallFactorial) {
|
|
|
|
EXPERIMENTAL_FLAG_SCOPE(return_call);
|
|
|
|
// Run in bounded amount of stack - 8kb.
|
|
|
|
FlagScope<int32_t> stack_size(&v8::internal::FLAG_stack_size, 8);
|
|
|
|
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<uint32_t, int32_t> r(TestExecutionTier::kInterpreter);
|
2019-02-27 18:43:47 +00:00
|
|
|
|
|
|
|
WasmFunctionCompiler& fact_aux_fn =
|
|
|
|
r.NewFunction<int32_t, int32_t, int32_t>("fact_aux");
|
|
|
|
|
|
|
|
BUILD(r, WASM_RETURN_CALL_FUNCTION(fact_aux_fn.function_index(),
|
|
|
|
WASM_GET_LOCAL(0), WASM_I32V(1)));
|
|
|
|
|
|
|
|
BUILD(fact_aux_fn,
|
|
|
|
WASM_IF_ELSE_I(
|
|
|
|
WASM_I32_EQ(WASM_I32V(1), WASM_GET_LOCAL(0)), WASM_GET_LOCAL(1),
|
|
|
|
WASM_RETURN_CALL_FUNCTION(
|
|
|
|
fact_aux_fn.function_index(),
|
|
|
|
WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I32V(1)),
|
|
|
|
WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))));
|
|
|
|
|
|
|
|
// Runs out of stack space without using return call.
|
|
|
|
uint32_t test_values[] = {1, 2, 5, 10, 20, 20000};
|
|
|
|
|
|
|
|
for (uint32_t v : test_values) {
|
|
|
|
uint32_t found = r.Call(v);
|
|
|
|
CHECK_EQ(factorial(v), found);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Run_Wasm_returnCallFactorial64) {
|
|
|
|
EXPERIMENTAL_FLAG_SCOPE(return_call);
|
|
|
|
|
|
|
|
int32_t test_values[] = {1, 2, 5, 10, 20};
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<int64_t, int32_t> r(TestExecutionTier::kInterpreter);
|
2019-02-27 18:43:47 +00:00
|
|
|
|
|
|
|
WasmFunctionCompiler& fact_aux_fn =
|
|
|
|
r.NewFunction<int64_t, int32_t, int64_t>("fact_aux");
|
|
|
|
|
|
|
|
BUILD(r, WASM_RETURN_CALL_FUNCTION(fact_aux_fn.function_index(),
|
|
|
|
WASM_GET_LOCAL(0), WASM_I64V(1)));
|
|
|
|
|
|
|
|
BUILD(fact_aux_fn,
|
|
|
|
WASM_IF_ELSE_L(
|
|
|
|
WASM_I32_EQ(WASM_I32V(1), WASM_GET_LOCAL(0)), WASM_GET_LOCAL(1),
|
|
|
|
WASM_RETURN_CALL_FUNCTION(
|
|
|
|
fact_aux_fn.function_index(),
|
|
|
|
WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I32V(1)),
|
|
|
|
WASM_I64_MUL(WASM_I64_SCONVERT_I32(WASM_GET_LOCAL(0)),
|
|
|
|
WASM_GET_LOCAL(1)))));
|
|
|
|
|
|
|
|
for (int32_t v : test_values) {
|
|
|
|
CHECK_EQ(factorial<int64_t>(v), r.Call(v));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Run_Wasm_returnCallIndirectFactorial) {
|
|
|
|
EXPERIMENTAL_FLAG_SCOPE(return_call);
|
|
|
|
|
|
|
|
TestSignatures sigs;
|
|
|
|
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<uint32_t, uint32_t> r(TestExecutionTier::kInterpreter);
|
2019-02-27 18:43:47 +00:00
|
|
|
|
|
|
|
WasmFunctionCompiler& fact_aux_fn = r.NewFunction(sigs.i_ii(), "fact_aux");
|
|
|
|
fact_aux_fn.SetSigIndex(0);
|
|
|
|
|
2019-05-22 14:04:36 +00:00
|
|
|
byte sig_index = r.builder().AddSignature(sigs.i_ii());
|
2019-02-27 18:43:47 +00:00
|
|
|
|
|
|
|
// Function table.
|
|
|
|
uint16_t indirect_function_table[] = {
|
|
|
|
static_cast<uint16_t>(fact_aux_fn.function_index())};
|
|
|
|
|
|
|
|
r.builder().AddIndirectFunctionTable(indirect_function_table,
|
|
|
|
arraysize(indirect_function_table));
|
|
|
|
|
2019-11-28 13:55:59 +00:00
|
|
|
BUILD(r, WASM_RETURN_CALL_INDIRECT(sig_index, WASM_GET_LOCAL(0), WASM_I32V(1),
|
|
|
|
WASM_ZERO));
|
2019-02-27 18:43:47 +00:00
|
|
|
|
2019-11-28 13:55:59 +00:00
|
|
|
BUILD(
|
|
|
|
fact_aux_fn,
|
|
|
|
WASM_IF_ELSE_I(
|
|
|
|
WASM_I32_EQ(WASM_I32V(1), WASM_GET_LOCAL(0)), WASM_GET_LOCAL(1),
|
|
|
|
WASM_RETURN_CALL_INDIRECT(
|
|
|
|
sig_index, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I32V(1)),
|
|
|
|
WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_ZERO)));
|
2019-02-27 18:43:47 +00:00
|
|
|
|
|
|
|
uint32_t test_values[] = {1, 2, 5, 10, 20};
|
|
|
|
|
|
|
|
for (uint32_t v : test_values) {
|
|
|
|
CHECK_EQ(factorial(v), r.Call(v));
|
|
|
|
}
|
|
|
|
}
|
2016-05-30 10:02:34 +00:00
|
|
|
// Make tests more robust by not hard-coding offsets of various operations.
|
|
|
|
// The {Find} method finds the offsets for the given bytecodes, returning
|
|
|
|
// the offsets in an array.
|
2016-07-25 10:24:45 +00:00
|
|
|
std::unique_ptr<int[]> Find(byte* code, size_t code_size, int n, ...) {
|
2016-05-30 10:02:34 +00:00
|
|
|
va_list vl;
|
|
|
|
va_start(vl, n);
|
|
|
|
|
2016-07-25 10:24:45 +00:00
|
|
|
std::unique_ptr<int[]> offsets(new int[n]);
|
2016-05-30 10:02:34 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
offsets[i] = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pos = 0;
|
|
|
|
WasmOpcode current = static_cast<WasmOpcode>(va_arg(vl, int));
|
|
|
|
for (size_t i = 0; i < code_size; i++) {
|
|
|
|
if (code[i] == current) {
|
|
|
|
offsets[pos++] = static_cast<int>(i);
|
|
|
|
if (pos == n) break;
|
|
|
|
current = static_cast<WasmOpcode>(va_arg(vl, int));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
va_end(vl);
|
|
|
|
|
|
|
|
return offsets;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Step_I32Mul) {
|
2017-01-27 09:48:08 +00:00
|
|
|
static const int kTraceLength = 4;
|
2016-05-30 10:02:34 +00:00
|
|
|
byte code[] = {WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))};
|
2016-05-25 08:32:37 +00:00
|
|
|
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<int32_t, uint32_t, uint32_t> r(TestExecutionTier::kInterpreter);
|
2016-05-30 10:02:34 +00:00
|
|
|
|
|
|
|
r.Build(code, code + arraysize(code));
|
|
|
|
|
|
|
|
WasmInterpreter* interpreter = r.interpreter();
|
|
|
|
|
|
|
|
FOR_UINT32_INPUTS(a) {
|
|
|
|
for (uint32_t b = 33; b < 3000000000u; b += 1000000000u) {
|
2020-06-05 11:05:04 +00:00
|
|
|
interpreter->Reset();
|
2019-02-01 10:37:04 +00:00
|
|
|
WasmValue args[] = {WasmValue(a), WasmValue(b)};
|
2020-06-05 11:05:04 +00:00
|
|
|
interpreter->InitFrame(r.function(), args);
|
2016-05-30 10:02:34 +00:00
|
|
|
|
|
|
|
// Run instructions one by one.
|
|
|
|
for (int i = 0; i < kTraceLength - 1; i++) {
|
2020-06-05 11:05:04 +00:00
|
|
|
interpreter->Step();
|
|
|
|
// Check the interpreter stopped.
|
|
|
|
CHECK_EQ(WasmInterpreter::PAUSED, interpreter->state());
|
2016-05-30 10:02:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run last instruction.
|
2020-06-05 11:05:04 +00:00
|
|
|
interpreter->Step();
|
2016-05-30 10:02:34 +00:00
|
|
|
|
2020-06-05 11:05:04 +00:00
|
|
|
// Check the interpreter finished with the right value.
|
|
|
|
CHECK_EQ(WasmInterpreter::FINISHED, interpreter->state());
|
2019-02-01 10:37:04 +00:00
|
|
|
uint32_t expected = (a) * (b);
|
2020-06-05 11:05:04 +00:00
|
|
|
CHECK_EQ(expected, interpreter->GetReturnValue().to<uint32_t>());
|
2016-05-30 10:02:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-26 17:28:37 +00:00
|
|
|
TEST(MemoryGrow) {
|
2017-01-11 17:24:00 +00:00
|
|
|
{
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<int32_t, uint32_t> r(TestExecutionTier::kInterpreter);
|
2018-01-11 11:49:29 +00:00
|
|
|
r.builder().AddMemory(kWasmPageSize);
|
2017-08-19 16:34:11 +00:00
|
|
|
r.builder().SetMaxMemPages(10);
|
2017-01-11 17:24:00 +00:00
|
|
|
BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0)));
|
|
|
|
CHECK_EQ(1, r.Call(1));
|
|
|
|
}
|
|
|
|
{
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<int32_t, uint32_t> r(TestExecutionTier::kInterpreter);
|
2018-01-11 11:49:29 +00:00
|
|
|
r.builder().AddMemory(kWasmPageSize);
|
2017-08-19 16:34:11 +00:00
|
|
|
r.builder().SetMaxMemPages(10);
|
2017-01-11 17:24:00 +00:00
|
|
|
BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0)));
|
|
|
|
CHECK_EQ(-1, r.Call(11));
|
|
|
|
}
|
2016-09-14 09:19:02 +00:00
|
|
|
}
|
|
|
|
|
2018-10-26 17:28:37 +00:00
|
|
|
TEST(MemoryGrowPreservesData) {
|
2016-09-14 09:19:02 +00:00
|
|
|
int32_t index = 16;
|
|
|
|
int32_t value = 2335;
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<int32_t, uint32_t> r(TestExecutionTier::kInterpreter);
|
2018-01-11 11:49:29 +00:00
|
|
|
r.builder().AddMemory(kWasmPageSize);
|
2016-09-27 20:46:10 +00:00
|
|
|
BUILD(r, WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index),
|
|
|
|
WASM_I32V(value)),
|
|
|
|
WASM_GROW_MEMORY(WASM_GET_LOCAL(0)), WASM_DROP,
|
|
|
|
WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V(index)));
|
2016-09-14 09:19:02 +00:00
|
|
|
CHECK_EQ(value, r.Call(1));
|
|
|
|
}
|
2016-09-15 09:26:52 +00:00
|
|
|
|
2018-10-26 17:28:37 +00:00
|
|
|
TEST(MemoryGrowInvalidSize) {
|
2017-04-28 08:04:11 +00:00
|
|
|
// Grow memory by an invalid amount without initial memory.
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<int32_t, uint32_t> r(TestExecutionTier::kInterpreter);
|
2018-01-11 11:49:29 +00:00
|
|
|
r.builder().AddMemory(kWasmPageSize);
|
2017-04-28 08:04:11 +00:00
|
|
|
BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0)));
|
|
|
|
CHECK_EQ(-1, r.Call(1048575));
|
2016-09-15 09:26:52 +00:00
|
|
|
}
|
|
|
|
|
2019-04-03 11:06:41 +00:00
|
|
|
TEST(ReferenceTypeLocals) {
|
|
|
|
{
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<int32_t> r(TestExecutionTier::kInterpreter);
|
2020-06-23 13:41:10 +00:00
|
|
|
BUILD(r, WASM_REF_IS_NULL(WASM_REF_NULL(kLocalExternRef)));
|
2019-04-03 11:06:41 +00:00
|
|
|
CHECK_EQ(1, r.Call());
|
|
|
|
}
|
|
|
|
{
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<int32_t> r(TestExecutionTier::kInterpreter);
|
2020-06-09 15:54:14 +00:00
|
|
|
r.AllocateLocal(kWasmExternRef);
|
2020-06-23 13:41:10 +00:00
|
|
|
BUILD(r, WASM_REF_IS_NULL(WASM_GET_LOCAL(0)));
|
2019-04-03 11:06:41 +00:00
|
|
|
CHECK_EQ(1, r.Call());
|
|
|
|
}
|
2019-04-05 12:12:50 +00:00
|
|
|
{
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<int32_t> r(TestExecutionTier::kInterpreter);
|
2020-06-09 15:54:14 +00:00
|
|
|
r.AllocateLocal(kWasmExternRef);
|
|
|
|
BUILD(r,
|
2020-06-23 13:41:10 +00:00
|
|
|
WASM_REF_IS_NULL(WASM_TEE_LOCAL(0, WASM_REF_NULL(kLocalExternRef))));
|
2019-04-05 12:12:50 +00:00
|
|
|
CHECK_EQ(1, r.Call());
|
|
|
|
}
|
2019-04-03 11:06:41 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 14:27:23 +00:00
|
|
|
TEST(TestPossibleNondeterminism) {
|
|
|
|
{
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<int32_t, float> r(TestExecutionTier::kInterpreter);
|
2017-02-03 09:51:04 +00:00
|
|
|
BUILD(r, WASM_I32_REINTERPRET_F32(WASM_GET_LOCAL(0)));
|
|
|
|
r.Call(1048575.5f);
|
2016-10-20 14:27:23 +00:00
|
|
|
CHECK(!r.possible_nondeterminism());
|
2017-02-03 09:51:04 +00:00
|
|
|
r.Call(std::numeric_limits<float>::quiet_NaN());
|
2017-10-26 07:45:12 +00:00
|
|
|
CHECK(!r.possible_nondeterminism());
|
2016-10-20 14:27:23 +00:00
|
|
|
}
|
|
|
|
{
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<int64_t, double> r(TestExecutionTier::kInterpreter);
|
2017-02-03 09:51:04 +00:00
|
|
|
BUILD(r, WASM_I64_REINTERPRET_F64(WASM_GET_LOCAL(0)));
|
|
|
|
r.Call(16.0);
|
2016-10-20 14:27:23 +00:00
|
|
|
CHECK(!r.possible_nondeterminism());
|
2017-02-03 09:51:04 +00:00
|
|
|
r.Call(std::numeric_limits<double>::quiet_NaN());
|
2017-10-26 07:45:12 +00:00
|
|
|
CHECK(!r.possible_nondeterminism());
|
2016-10-20 14:27:23 +00:00
|
|
|
}
|
|
|
|
{
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<float, float> r(TestExecutionTier::kInterpreter);
|
2017-02-03 09:51:04 +00:00
|
|
|
BUILD(r, WASM_F32_COPYSIGN(WASM_F32(42.0f), WASM_GET_LOCAL(0)));
|
|
|
|
r.Call(16.0f);
|
2016-10-20 14:27:23 +00:00
|
|
|
CHECK(!r.possible_nondeterminism());
|
2017-02-03 09:51:04 +00:00
|
|
|
r.Call(std::numeric_limits<double>::quiet_NaN());
|
2017-10-26 07:45:12 +00:00
|
|
|
CHECK(!r.possible_nondeterminism());
|
2016-10-20 14:27:23 +00:00
|
|
|
}
|
|
|
|
{
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<double, double> r(TestExecutionTier::kInterpreter);
|
2017-02-03 09:51:04 +00:00
|
|
|
BUILD(r, WASM_F64_COPYSIGN(WASM_F64(42.0), WASM_GET_LOCAL(0)));
|
|
|
|
r.Call(16.0);
|
2016-10-20 14:27:23 +00:00
|
|
|
CHECK(!r.possible_nondeterminism());
|
2017-02-03 09:51:04 +00:00
|
|
|
r.Call(std::numeric_limits<double>::quiet_NaN());
|
2017-10-26 07:45:12 +00:00
|
|
|
CHECK(!r.possible_nondeterminism());
|
2016-10-20 14:27:23 +00:00
|
|
|
}
|
|
|
|
{
|
2017-02-03 09:51:04 +00:00
|
|
|
int32_t index = 16;
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<int32_t, float> r(TestExecutionTier::kInterpreter);
|
2018-01-11 11:49:29 +00:00
|
|
|
r.builder().AddMemory(kWasmPageSize);
|
2017-02-03 09:51:04 +00:00
|
|
|
BUILD(r, WASM_STORE_MEM(MachineType::Float32(), WASM_I32V(index),
|
|
|
|
WASM_GET_LOCAL(0)),
|
|
|
|
WASM_I32V(index));
|
|
|
|
r.Call(1345.3456f);
|
2016-10-20 14:27:23 +00:00
|
|
|
CHECK(!r.possible_nondeterminism());
|
2017-02-03 09:51:04 +00:00
|
|
|
r.Call(std::numeric_limits<float>::quiet_NaN());
|
2017-10-26 07:45:12 +00:00
|
|
|
CHECK(!r.possible_nondeterminism());
|
2016-10-20 14:27:23 +00:00
|
|
|
}
|
|
|
|
{
|
2017-02-03 09:51:04 +00:00
|
|
|
int32_t index = 16;
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<int32_t, double> r(TestExecutionTier::kInterpreter);
|
2018-01-11 11:49:29 +00:00
|
|
|
r.builder().AddMemory(kWasmPageSize);
|
2017-02-03 09:51:04 +00:00
|
|
|
BUILD(r, WASM_STORE_MEM(MachineType::Float64(), WASM_I32V(index),
|
|
|
|
WASM_GET_LOCAL(0)),
|
|
|
|
WASM_I32V(index));
|
|
|
|
r.Call(1345.3456);
|
2016-10-20 14:27:23 +00:00
|
|
|
CHECK(!r.possible_nondeterminism());
|
2017-02-03 09:51:04 +00:00
|
|
|
r.Call(std::numeric_limits<double>::quiet_NaN());
|
2017-10-26 07:45:12 +00:00
|
|
|
CHECK(!r.possible_nondeterminism());
|
|
|
|
}
|
|
|
|
{
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<float, float> r(TestExecutionTier::kInterpreter);
|
2017-10-26 07:45:12 +00:00
|
|
|
BUILD(r, WASM_F32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
|
|
|
|
r.Call(1048575.5f);
|
|
|
|
CHECK(!r.possible_nondeterminism());
|
|
|
|
r.Call(std::numeric_limits<float>::quiet_NaN());
|
|
|
|
CHECK(r.possible_nondeterminism());
|
|
|
|
}
|
|
|
|
{
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<double, double> r(TestExecutionTier::kInterpreter);
|
2017-10-26 07:45:12 +00:00
|
|
|
BUILD(r, WASM_F64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
|
|
|
|
r.Call(16.0);
|
|
|
|
CHECK(!r.possible_nondeterminism());
|
|
|
|
r.Call(std::numeric_limits<double>::quiet_NaN());
|
|
|
|
CHECK(r.possible_nondeterminism());
|
|
|
|
}
|
|
|
|
{
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<int32_t, float> r(TestExecutionTier::kInterpreter);
|
2017-10-26 07:45:12 +00:00
|
|
|
BUILD(r, WASM_F32_EQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
|
|
|
|
r.Call(16.0);
|
|
|
|
CHECK(!r.possible_nondeterminism());
|
|
|
|
r.Call(std::numeric_limits<float>::quiet_NaN());
|
|
|
|
CHECK(!r.possible_nondeterminism());
|
|
|
|
}
|
|
|
|
{
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<int32_t, double> r(TestExecutionTier::kInterpreter);
|
2017-10-26 07:45:12 +00:00
|
|
|
BUILD(r, WASM_F64_EQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
|
|
|
|
r.Call(16.0);
|
|
|
|
CHECK(!r.possible_nondeterminism());
|
|
|
|
r.Call(std::numeric_limits<double>::quiet_NaN());
|
|
|
|
CHECK(!r.possible_nondeterminism());
|
|
|
|
}
|
|
|
|
{
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<float, float> r(TestExecutionTier::kInterpreter);
|
2017-10-26 07:45:12 +00:00
|
|
|
BUILD(r, WASM_F32_MIN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
|
|
|
|
r.Call(1048575.5f);
|
|
|
|
CHECK(!r.possible_nondeterminism());
|
|
|
|
r.Call(std::numeric_limits<float>::quiet_NaN());
|
|
|
|
CHECK(r.possible_nondeterminism());
|
|
|
|
}
|
|
|
|
{
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<double, double> r(TestExecutionTier::kInterpreter);
|
2017-10-26 07:45:12 +00:00
|
|
|
BUILD(r, WASM_F64_MAX(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
|
|
|
|
r.Call(16.0);
|
|
|
|
CHECK(!r.possible_nondeterminism());
|
|
|
|
r.Call(std::numeric_limits<double>::quiet_NaN());
|
2016-10-20 14:27:23 +00:00
|
|
|
CHECK(r.possible_nondeterminism());
|
|
|
|
}
|
|
|
|
}
|
2017-03-21 10:54:14 +00:00
|
|
|
|
2017-04-03 07:44:47 +00:00
|
|
|
TEST(InterpreterLoadWithoutMemory) {
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<int32_t, int32_t> r(TestExecutionTier::kInterpreter);
|
2017-08-19 16:34:11 +00:00
|
|
|
r.builder().AddMemory(0);
|
2017-04-03 07:44:47 +00:00
|
|
|
BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0)));
|
|
|
|
CHECK_TRAP32(r.Call(0));
|
|
|
|
}
|
|
|
|
|
2020-07-31 08:18:58 +00:00
|
|
|
TEST(Regress1111015) {
|
|
|
|
EXPERIMENTAL_FLAG_SCOPE(return_call);
|
2020-08-04 11:09:23 +00:00
|
|
|
WasmRunner<uint32_t> r(TestExecutionTier::kInterpreter);
|
2020-07-31 08:18:58 +00:00
|
|
|
WasmFunctionCompiler& f = r.NewFunction<int32_t>("f");
|
|
|
|
BUILD(r, WASM_BLOCK_I(WASM_RETURN_CALL_FUNCTION0(f.function_index()),
|
|
|
|
kExprDrop));
|
|
|
|
BUILD(f, WASM_I32V(0));
|
|
|
|
r.Call();
|
|
|
|
}
|
|
|
|
|
2017-09-21 03:29:52 +00:00
|
|
|
} // namespace test_run_wasm_interpreter
|
2016-05-25 08:32:37 +00:00
|
|
|
} // namespace wasm
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|