OLD | NEW |
---|---|
(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 | |
17 using namespace v8::internal; | |
18 using namespace v8::internal::compiler; | |
19 | |
20 template <typename CType> | |
21 static void RunLoadStoreRelocation(MachineType rep) { | |
titzer
2016/03/23 20:35:36
Can you split out some simple cases (e.g. offset 0
gdeepti1
2016/03/31 22:29:54
Added a simple load/store test with 0 offset.
| |
22 RawMachineAssemblerTester<int32_t> r(MachineType::Int32()); | |
23 const int kNumElems = 4; | |
24 CType buffer[kNumElems]; | |
25 CType new_buffer[kNumElems + 1]; | |
26 Isolate* isolate = CcTest::i_isolate(); | |
27 | |
28 for (int32_t x = 0; x < kNumElems; x++) { | |
29 int32_t y = kNumElems - x - 1; | |
30 // initialize the buffer with raw data. | |
31 byte* raw = reinterpret_cast<byte*>(buffer); | |
32 for (size_t i = 0; i < sizeof(buffer); i++) { | |
33 raw[i] = static_cast<byte>((i + sizeof(buffer)) ^ 0xAA); | |
34 } | |
35 | |
36 RawMachineAssemblerTester<int32_t> m; | |
37 int32_t OK = 0x29000 + x; | |
38 Node* base = m.RelocatableIntPtrConstant(reinterpret_cast<intptr_t>(buffer), | |
39 RelocInfo::WASM_MEMORY_REFERENCE); | |
40 Node* index0 = m.IntPtrConstant(x * sizeof(buffer[0])); | |
41 Node* load = m.Load(rep, base, index0); | |
42 Node* index1 = m.IntPtrConstant(y * sizeof(buffer[0])); | |
43 m.Store(rep.representation(), base, index1, load, kNoWriteBarrier); | |
44 m.Return(m.Int32Constant(OK)); | |
45 | |
46 CHECK(buffer[x] != buffer[y]); | |
47 CHECK_EQ(OK, m.Call()); | |
48 CHECK(buffer[x] == buffer[y]); | |
49 m.GenerateCode(); | |
50 | |
51 // Initialize new buffer and set old_buffer to 0 | |
52 byte* new_raw = reinterpret_cast<byte*>(new_buffer); | |
53 for (size_t i = 0; i < sizeof(buffer); i++) { | |
54 raw[i] = 0; | |
55 new_raw[i] = static_cast<byte>((i + sizeof(buffer)) ^ 0xAA); | |
56 } | |
57 | |
58 // Perform relocation on generated code | |
59 Handle<Code> code = m.GetCode(); | |
titzer
2016/03/23 20:35:36
This is OK for now, but this operation probably ne
gdeepti1
2016/03/31 22:29:54
Pulled out a method to update memory references.
| |
60 | |
61 bool modified = false; | |
62 int mode_mask = (1 << RelocInfo::WASM_MEMORY_REFERENCE); | |
63 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { | |
64 RelocInfo::Mode mode = it.rinfo()->rmode(); | |
65 if (RelocInfo::IsWasmMemoryReference(mode)) { | |
66 // Patch addresses with change in memory start address | |
67 it.rinfo()->update_wasm_memory_reference(raw, new_raw, sizeof(buffer), | |
68 sizeof(new_buffer), | |
69 SKIP_ICACHE_FLUSH); | |
70 modified = true; | |
71 } | |
72 } | |
73 if (modified) { | |
74 Assembler::FlushICache(isolate, code->instruction_start(), | |
75 code->instruction_size()); | |
76 } | |
77 | |
78 CHECK(new_buffer[x] != new_buffer[y]); | |
79 CHECK_EQ(OK, m.Call()); | |
80 CHECK(new_buffer[x] == new_buffer[y]); | |
81 } | |
82 } | |
83 | |
84 TEST(RunLoadStoreRelocation) { | |
85 RunLoadStoreRelocation<int8_t>(MachineType::Int8()); | |
86 RunLoadStoreRelocation<uint8_t>(MachineType::Uint8()); | |
87 RunLoadStoreRelocation<int16_t>(MachineType::Int16()); | |
88 RunLoadStoreRelocation<uint16_t>(MachineType::Uint16()); | |
89 RunLoadStoreRelocation<int32_t>(MachineType::Int32()); | |
90 RunLoadStoreRelocation<uint32_t>(MachineType::Uint32()); | |
91 RunLoadStoreRelocation<void*>(MachineType::AnyTagged()); | |
92 RunLoadStoreRelocation<float>(MachineType::Float32()); | |
93 RunLoadStoreRelocation<double>(MachineType::Float64()); | |
94 } | |
OLD | NEW |