2021-01-08 17:47:25 +00:00
|
|
|
// Copyright 2020 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 "src/wasm/wasm-opcodes-inl.h"
|
|
|
|
#include "test/cctest/cctest.h"
|
|
|
|
#include "test/cctest/wasm/wasm-run-utils.h"
|
|
|
|
#include "test/common/wasm/test-signatures.h"
|
|
|
|
#include "test/common/wasm/wasm-macro-gen.h"
|
2021-01-15 11:20:32 +00:00
|
|
|
#include "test/common/wasm/wasm-module-runner.h"
|
2021-01-08 17:47:25 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace wasm {
|
|
|
|
|
|
|
|
template <typename ReturnType, typename... ParamTypes>
|
|
|
|
class Memory64Runner : public WasmRunner<ReturnType, ParamTypes...> {
|
|
|
|
public:
|
|
|
|
explicit Memory64Runner(TestExecutionTier execution_tier)
|
|
|
|
: WasmRunner<ReturnType, ParamTypes...>(execution_tier) {
|
|
|
|
this->builder().EnableFeature(kFeature_memory64);
|
|
|
|
this->builder().SetMemory64();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
WASM_EXEC_TEST(Load) {
|
|
|
|
// TODO(clemensb): Implement memory64 in the interpreter.
|
|
|
|
if (execution_tier == TestExecutionTier::kInterpreter) return;
|
|
|
|
|
|
|
|
Memory64Runner<uint32_t, uint64_t> r(execution_tier);
|
|
|
|
uint32_t* memory =
|
|
|
|
r.builder().AddMemoryElems<uint32_t>(kWasmPageSize / sizeof(int32_t));
|
|
|
|
|
|
|
|
BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_LOCAL_GET(0)));
|
|
|
|
|
|
|
|
CHECK_EQ(0, r.Call(0));
|
|
|
|
|
2021-01-11 19:21:09 +00:00
|
|
|
#if V8_TARGET_BIG_ENDIAN
|
|
|
|
memory[0] = 0x78563412;
|
|
|
|
#else
|
2021-01-08 17:47:25 +00:00
|
|
|
memory[0] = 0x12345678;
|
2021-01-11 19:21:09 +00:00
|
|
|
#endif
|
2021-01-08 17:47:25 +00:00
|
|
|
CHECK_EQ(0x12345678, r.Call(0));
|
|
|
|
CHECK_EQ(0x123456, r.Call(1));
|
|
|
|
CHECK_EQ(0x1234, r.Call(2));
|
|
|
|
CHECK_EQ(0x12, r.Call(3));
|
|
|
|
CHECK_EQ(0x0, r.Call(4));
|
|
|
|
|
2021-01-08 17:58:20 +00:00
|
|
|
CHECK_TRAP(r.Call(-1));
|
|
|
|
CHECK_TRAP(r.Call(kWasmPageSize));
|
|
|
|
CHECK_TRAP(r.Call(kWasmPageSize - 3));
|
|
|
|
CHECK_EQ(0x0, r.Call(kWasmPageSize - 4));
|
|
|
|
CHECK_TRAP(r.Call(uint64_t{1} << 32));
|
2021-01-08 17:47:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(clemensb): Test atomic instructions.
|
|
|
|
|
2021-01-15 11:20:32 +00:00
|
|
|
WASM_EXEC_TEST(InitExpression) {
|
|
|
|
EXPERIMENTAL_FLAG_SCOPE(memory64);
|
|
|
|
Isolate* isolate = CcTest::InitIsolateOnce();
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
|
|
|
|
ErrorThrower thrower(isolate, "TestMemory64InitExpression");
|
|
|
|
|
|
|
|
const byte data[] = {
|
|
|
|
WASM_MODULE_HEADER, //
|
|
|
|
SECTION(Memory, //
|
|
|
|
ENTRY_COUNT(1), //
|
|
|
|
kMemory64WithMaximum, // type
|
|
|
|
1, // initial size
|
|
|
|
2), // maximum size
|
|
|
|
SECTION(Data, //
|
|
|
|
ENTRY_COUNT(1), //
|
|
|
|
0, // linear memory index
|
|
|
|
WASM_I64V_3(0xFFFF), kExprEnd, // destination offset
|
|
|
|
U32V_1(1), // source size
|
|
|
|
'c') // data bytes
|
|
|
|
};
|
|
|
|
|
|
|
|
testing::CompileAndInstantiateForTesting(
|
|
|
|
isolate, &thrower, ModuleWireBytes(data, data + arraysize(data)));
|
|
|
|
if (thrower.error()) {
|
|
|
|
thrower.Reify()->Print();
|
|
|
|
FATAL("compile or instantiate error");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-08 17:47:25 +00:00
|
|
|
} // namespace wasm
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|