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

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

Issue 2627543003: [wasm] Prerequisites for WebAssembly Table.Grow (Closed)
Patch Set: Rename update function Created 3 years, 11 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
« no previous file with comments | « src/x64/assembler-x64.cc ('k') | test/cctest/wasm/wasm-run-utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. Use of this 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 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #include <cmath> 5 #include <cmath>
6 #include <functional> 6 #include <functional>
7 #include <limits> 7 #include <limits>
8 8
9 #include "src/base/bits.h" 9 #include "src/base/bits.h"
10 #include "src/base/utils/random-number-generator.h" 10 #include "src/base/utils/random-number-generator.h"
(...skipping 22 matching lines...) Expand all
33 new_size); 33 new_size);
34 modified = true; 34 modified = true;
35 } 35 }
36 } 36 }
37 if (modified) { 37 if (modified) {
38 Assembler::FlushICache(isolate, code->instruction_start(), 38 Assembler::FlushICache(isolate, code->instruction_start(),
39 code->instruction_size()); 39 code->instruction_size());
40 } 40 }
41 } 41 }
42 42
43 static void UpdateFunctionTableSizeReferences(Handle<Code> code,
44 uint32_t old_size,
45 uint32_t new_size) {
46 Isolate* isolate = CcTest::i_isolate();
47 bool modified = false;
48 int mode_mask =
49 RelocInfo::ModeMask(RelocInfo::WASM_FUNCTION_TABLE_SIZE_REFERENCE);
50 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) {
51 RelocInfo::Mode mode = it.rinfo()->rmode();
52 if (RelocInfo::IsWasmFunctionTableSizeReference(mode)) {
53 it.rinfo()->update_wasm_function_table_size_reference(old_size, new_size);
54 modified = true;
55 }
56 }
57 if (modified) {
58 Assembler::FlushICache(isolate, code->instruction_start(),
59 code->instruction_size());
60 }
61 }
62
43 template <typename CType> 63 template <typename CType>
44 static void RunLoadStoreRelocation(MachineType rep) { 64 static void RunLoadStoreRelocation(MachineType rep) {
45 const int kNumElems = 2; 65 const int kNumElems = 2;
46 CType buffer[kNumElems]; 66 CType buffer[kNumElems];
47 CType new_buffer[kNumElems]; 67 CType new_buffer[kNumElems];
48 byte* raw = reinterpret_cast<byte*>(buffer); 68 byte* raw = reinterpret_cast<byte*>(buffer);
49 byte* new_raw = reinterpret_cast<byte*>(new_buffer); 69 byte* new_raw = reinterpret_cast<byte*>(new_buffer);
50 for (size_t i = 0; i < sizeof(buffer); i++) { 70 for (size_t i = 0; i < sizeof(buffer); i++) {
51 raw[i] = static_cast<byte>((i + sizeof(CType)) ^ 0xAA); 71 raw[i] = static_cast<byte>((i + sizeof(CType)) ^ 0xAA);
52 new_raw[i] = static_cast<byte>((i + sizeof(CType)) ^ 0xAA); 72 new_raw[i] = static_cast<byte>((i + sizeof(CType)) ^ 0xAA);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 RunLoadStoreRelocationOffset<uint8_t>(MachineType::Uint8()); 159 RunLoadStoreRelocationOffset<uint8_t>(MachineType::Uint8());
140 RunLoadStoreRelocationOffset<int16_t>(MachineType::Int16()); 160 RunLoadStoreRelocationOffset<int16_t>(MachineType::Int16());
141 RunLoadStoreRelocationOffset<uint16_t>(MachineType::Uint16()); 161 RunLoadStoreRelocationOffset<uint16_t>(MachineType::Uint16());
142 RunLoadStoreRelocationOffset<int32_t>(MachineType::Int32()); 162 RunLoadStoreRelocationOffset<int32_t>(MachineType::Int32());
143 RunLoadStoreRelocationOffset<uint32_t>(MachineType::Uint32()); 163 RunLoadStoreRelocationOffset<uint32_t>(MachineType::Uint32());
144 RunLoadStoreRelocationOffset<void*>(MachineType::AnyTagged()); 164 RunLoadStoreRelocationOffset<void*>(MachineType::AnyTagged());
145 RunLoadStoreRelocationOffset<float>(MachineType::Float32()); 165 RunLoadStoreRelocationOffset<float>(MachineType::Float32());
146 RunLoadStoreRelocationOffset<double>(MachineType::Float64()); 166 RunLoadStoreRelocationOffset<double>(MachineType::Float64());
147 } 167 }
148 168
149 TEST(Uint32LessThanRelocation) { 169 TEST(Uint32LessThanMemoryRelocation) {
150 RawMachineAssemblerTester<uint32_t> m; 170 RawMachineAssemblerTester<uint32_t> m;
151 RawMachineLabel within_bounds, out_of_bounds; 171 RawMachineLabel within_bounds, out_of_bounds;
152 Node* index = m.Int32Constant(0x200); 172 Node* index = m.Int32Constant(0x200);
153 Node* limit = 173 Node* limit =
154 m.RelocatableInt32Constant(0x200, RelocInfo::WASM_MEMORY_SIZE_REFERENCE); 174 m.RelocatableInt32Constant(0x200, RelocInfo::WASM_MEMORY_SIZE_REFERENCE);
155 Node* cond = m.AddNode(m.machine()->Uint32LessThan(), index, limit); 175 Node* cond = m.AddNode(m.machine()->Uint32LessThan(), index, limit);
156 m.Branch(cond, &within_bounds, &out_of_bounds); 176 m.Branch(cond, &within_bounds, &out_of_bounds);
157 m.Bind(&within_bounds); 177 m.Bind(&within_bounds);
158 m.Return(m.Int32Constant(0xaced)); 178 m.Return(m.Int32Constant(0xaced));
159 m.Bind(&out_of_bounds); 179 m.Bind(&out_of_bounds);
160 m.Return(m.Int32Constant(0xdeadbeef)); 180 m.Return(m.Int32Constant(0xdeadbeef));
161 // Check that index is out of bounds with current size 181 // Check that index is out of bounds with current size
162 CHECK_EQ(0xdeadbeef, m.Call()); 182 CHECK_EQ(0xdeadbeef, m.Call());
163 m.GenerateCode(); 183 m.GenerateCode();
164 184
165 Handle<Code> code = m.GetCode(); 185 Handle<Code> code = m.GetCode();
166 UpdateMemoryReferences(code, reinterpret_cast<Address>(1234), 186 UpdateMemoryReferences(code, reinterpret_cast<Address>(1234),
167 reinterpret_cast<Address>(1234), 0x200, 0x400); 187 reinterpret_cast<Address>(1234), 0x200, 0x400);
168 // Check that after limit is increased, index is within bounds. 188 // Check that after limit is increased, index is within bounds.
169 CHECK_EQ(0xacedu, m.Call()); 189 CHECK_EQ(0xacedu, m.Call());
170 } 190 }
191
192 TEST(Uint32LessThanFunctionTableRelocation) {
193 RawMachineAssemblerTester<uint32_t> m;
194 RawMachineLabel within_bounds, out_of_bounds;
195 Node* index = m.Int32Constant(0x200);
196 Node* limit = m.RelocatableInt32Constant(
197 0x200, RelocInfo::WASM_FUNCTION_TABLE_SIZE_REFERENCE);
198 Node* cond = m.AddNode(m.machine()->Uint32LessThan(), index, limit);
199 m.Branch(cond, &within_bounds, &out_of_bounds);
200 m.Bind(&within_bounds);
201 m.Return(m.Int32Constant(0xaced));
202 m.Bind(&out_of_bounds);
203 m.Return(m.Int32Constant(0xdeadbeef));
204 // Check that index is out of bounds with current size
205 CHECK_EQ(0xdeadbeef, m.Call());
206 m.GenerateCode();
207
208 Handle<Code> code = m.GetCode();
209 UpdateFunctionTableSizeReferences(code, 0x200, 0x400);
210 // Check that after limit is increased, index is within bounds.
211 CHECK_EQ(0xaced, m.Call());
212 }
OLDNEW
« no previous file with comments | « src/x64/assembler-x64.cc ('k') | test/cctest/wasm/wasm-run-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698