| Index: test/cctest/compiler/test-run-wasm-machops.cc
|
| diff --git a/test/cctest/compiler/test-run-wasm-machops.cc b/test/cctest/compiler/test-run-wasm-machops.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..31ce7528c04d814a4a7aff2c42ab13d2851c9cfc
|
| --- /dev/null
|
| +++ b/test/cctest/compiler/test-run-wasm-machops.cc
|
| @@ -0,0 +1,96 @@
|
| +// 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 <cmath>
|
| +#include <functional>
|
| +#include <limits>
|
| +
|
| +#include "src/base/bits.h"
|
| +#include "src/base/utils/random-number-generator.h"
|
| +#include "src/codegen.h"
|
| +#include "test/cctest/cctest.h"
|
| +#include "test/cctest/compiler/codegen-tester.h"
|
| +#include "test/cctest/compiler/graph-builder-tester.h"
|
| +#include "test/cctest/compiler/value-helper.h"
|
| +#include "test/cctest/wasm/wasm-run-utils.h"
|
| +
|
| +using namespace v8::base;
|
| +using namespace v8::internal::wasm;
|
| +using namespace v8::internal::compiler;
|
| +
|
| +template <typename CType>
|
| +static void RunLoadStoreRelocation(MachineType rep) {
|
| + RawMachineAssemblerTester<int32_t> r(MachineType::Int32());
|
| + const int kNumElems = 4;
|
| + CType buffer[kNumElems];
|
| + CType new_buffer[kNumElems];
|
| + Isolate* isolate = CcTest::i_isolate();
|
| +
|
| + for (int32_t x = 0; x < kNumElems; x++) {
|
| + int32_t y = kNumElems - x - 1;
|
| + // initialize the buffer with raw data.
|
| + byte* raw = reinterpret_cast<byte*>(buffer);
|
| + for (size_t i = 0; i < sizeof(buffer); i++) {
|
| + raw[i] = static_cast<byte>((i + sizeof(buffer)) ^ 0xAA);
|
| + }
|
| +
|
| + RawMachineAssemblerTester<int32_t> m;
|
| + int32_t OK = 0x29000 + x;
|
| + Node* base = m.RelocatableIntPtrConstant(reinterpret_cast<intptr_t>(buffer),
|
| + RelocInfo::WASM_MEMORY_REFERENCE);
|
| + Node* index0 = m.IntPtrConstant(x * sizeof(buffer[0]));
|
| + Node* load = m.Load(rep, base, index0);
|
| + Node* index1 = m.IntPtrConstant(y * sizeof(buffer[0]));
|
| + m.Store(rep.representation(), base, index1, load, kNoWriteBarrier);
|
| + m.Return(m.Int32Constant(OK));
|
| +
|
| + CHECK(buffer[x] != buffer[y]);
|
| + CHECK_EQ(OK, m.Call());
|
| + CHECK(buffer[x] == buffer[y]);
|
| + m.GenerateCode();
|
| +
|
| + // Initialize new buffer and set old_buffer to 0
|
| + byte* new_raw = reinterpret_cast<byte*>(new_buffer);
|
| + for (size_t i = 0; i < sizeof(buffer); i++) {
|
| + raw[i] = 0;
|
| + new_raw[i] = static_cast<byte>((i + sizeof(new_buffer)) ^ 0xAA);
|
| + }
|
| +
|
| + // Perform relocation on generated code
|
| + Handle<Code> code = m.GetCode();
|
| +
|
| + size_t offset = new_raw - raw;
|
| + bool modified = false;
|
| + int mode_mask = (1 << RelocInfo::WASM_MEMORY_REFERENCE);
|
| + for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) {
|
| + RelocInfo::Mode mode = it.rinfo()->rmode();
|
| + if (RelocInfo::IsWasmMemoryReference(mode)) {
|
| + // Patch addresses with change in memory start address
|
| + it.rinfo()->update_wasm_memory_reference(
|
| + it.rinfo()->wasm_memory_reference() + offset, SKIP_ICACHE_FLUSH);
|
| + modified = true;
|
| + }
|
| + }
|
| + if (modified) {
|
| + Assembler::FlushICache(isolate, code->instruction_start(),
|
| + code->instruction_size());
|
| + }
|
| +
|
| + CHECK(new_buffer[x] != new_buffer[y]);
|
| + CHECK_EQ(OK, m.Call());
|
| + CHECK(new_buffer[x] == new_buffer[y]);
|
| + }
|
| +}
|
| +
|
| +TEST(RunLoadStoreRelocation) {
|
| + RunLoadStoreRelocation<int8_t>(MachineType::Int8());
|
| + RunLoadStoreRelocation<uint8_t>(MachineType::Uint8());
|
| + RunLoadStoreRelocation<int16_t>(MachineType::Int16());
|
| + RunLoadStoreRelocation<uint16_t>(MachineType::Uint16());
|
| + RunLoadStoreRelocation<int32_t>(MachineType::Int32());
|
| + RunLoadStoreRelocation<uint32_t>(MachineType::Uint32());
|
| + RunLoadStoreRelocation<void*>(MachineType::AnyTagged());
|
| + RunLoadStoreRelocation<float>(MachineType::Float32());
|
| + RunLoadStoreRelocation<double>(MachineType::Float64());
|
| +}
|
|
|