Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: test/cctest/compiler/test-run-wasm-machops.cc

Issue 1759383003: [compiler] Add relocatable pointer constants for wasm memory references. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix mips/mips64 compile Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file.
4
5 #include <cmath>
6 #include <functional>
7 #include <limits>
8
9 #include "src/base/bits.h"
10 #include "src/base/utils/random-number-generator.h"
11 #include "src/codegen.h"
12 #include "test/cctest/cctest.h"
13 #include "test/cctest/compiler/codegen-tester.h"
14 #include "test/cctest/compiler/graph-builder-tester.h"
15 #include "test/cctest/compiler/value-helper.h"
16 #include "test/cctest/wasm/wasm-run-utils.h"
17
18 using namespace v8::base;
19 using namespace v8::internal::wasm;
20 using namespace v8::internal::compiler;
21
22 template <typename CType>
23 static void RunLoadStoreRelocation(MachineType rep) {
24 RawMachineAssemblerTester<int32_t> r(MachineType::Int32());
25 const int kNumElems = 4;
26 CType buffer[kNumElems];
27 CType new_buffer[kNumElems];
28 Isolate* isolate = CcTest::i_isolate();
29
30 for (int32_t x = 0; x < kNumElems; x++) {
31 int32_t y = kNumElems - x - 1;
32 // initialize the buffer with raw data.
33 byte* raw = reinterpret_cast<byte*>(buffer);
34 for (size_t i = 0; i < sizeof(buffer); i++) {
35 raw[i] = static_cast<byte>((i + sizeof(buffer)) ^ 0xAA);
36 }
37
38 RawMachineAssemblerTester<int32_t> m;
39 int32_t OK = 0x29000 + x;
40 Node* base = m.RelocatableIntPtrConstant(reinterpret_cast<intptr_t>(buffer),
41 RelocInfo::WASM_MEMORY_REFERENCE);
42 Node* index0 = m.IntPtrConstant(x * sizeof(buffer[0]));
43 Node* load = m.Load(rep, base, index0);
44 Node* index1 = m.IntPtrConstant(y * sizeof(buffer[0]));
45 m.Store(rep.representation(), base, index1, load, kNoWriteBarrier);
46 m.Return(m.Int32Constant(OK));
47
48 CHECK(buffer[x] != buffer[y]);
49 CHECK_EQ(OK, m.Call());
50 CHECK(buffer[x] == buffer[y]);
51 m.GenerateCode();
52
53 // Initialize new buffer and set old_buffer to 0
54 byte* new_raw = reinterpret_cast<byte*>(new_buffer);
55 for (size_t i = 0; i < sizeof(buffer); i++) {
56 raw[i] = 0;
57 new_raw[i] = static_cast<byte>((i + sizeof(new_buffer)) ^ 0xAA);
58 }
59
60 // Perform relocation on generated code
61 Handle<Code> code = m.GetCode();
62
63 size_t offset = new_raw - raw;
64 bool modified = false;
65 int mode_mask = (1 << RelocInfo::WASM_MEMORY_REFERENCE);
66 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) {
67 RelocInfo::Mode mode = it.rinfo()->rmode();
68 if (RelocInfo::IsWasmMemoryReference(mode)) {
69 // Patch addresses with change in memory start address
70 it.rinfo()->update_wasm_memory_reference(
71 it.rinfo()->wasm_memory_reference() + offset, SKIP_ICACHE_FLUSH);
72 modified = true;
73 }
74 }
75 if (modified) {
76 Assembler::FlushICache(isolate, code->instruction_start(),
77 code->instruction_size());
78 }
79
80 CHECK(new_buffer[x] != new_buffer[y]);
81 CHECK_EQ(OK, m.Call());
82 CHECK(new_buffer[x] == new_buffer[y]);
83 }
84 }
85
86 TEST(RunLoadStoreRelocation) {
87 RunLoadStoreRelocation<int8_t>(MachineType::Int8());
88 RunLoadStoreRelocation<uint8_t>(MachineType::Uint8());
89 RunLoadStoreRelocation<int16_t>(MachineType::Int16());
90 RunLoadStoreRelocation<uint16_t>(MachineType::Uint16());
91 RunLoadStoreRelocation<int32_t>(MachineType::Int32());
92 RunLoadStoreRelocation<uint32_t>(MachineType::Uint32());
93 RunLoadStoreRelocation<void*>(MachineType::AnyTagged());
94 RunLoadStoreRelocation<float>(MachineType::Float32());
95 RunLoadStoreRelocation<double>(MachineType::Float64());
96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698