OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 178 |
179 | 179 |
180 TEST(jump_tables4) { | 180 TEST(jump_tables4) { |
181 // Similar to test-assembler-mips jump_tables1, with extra test for branch | 181 // Similar to test-assembler-mips jump_tables1, with extra test for branch |
182 // trampoline required before emission of the dd table (where trampolines are | 182 // trampoline required before emission of the dd table (where trampolines are |
183 // blocked), and proper transition to long-branch mode. | 183 // blocked), and proper transition to long-branch mode. |
184 // Regression test for v8:4294. | 184 // Regression test for v8:4294. |
185 CcTest::InitializeVM(); | 185 CcTest::InitializeVM(); |
186 Isolate* isolate = CcTest::i_isolate(); | 186 Isolate* isolate = CcTest::i_isolate(); |
187 HandleScope scope(isolate); | 187 HandleScope scope(isolate); |
188 MacroAssembler assembler(isolate, NULL, 0, | 188 MacroAssembler assembler(isolate, nullptr, 0, |
189 v8::internal::CodeObjectRequired::kYes); | 189 v8::internal::CodeObjectRequired::kYes); |
190 MacroAssembler* masm = &assembler; | 190 MacroAssembler* masm = &assembler; |
191 | 191 |
192 const int kNumCases = 512; | 192 const int kNumCases = 512; |
193 int values[kNumCases]; | 193 int values[kNumCases]; |
194 isolate->random_number_generator()->NextBytes(values, sizeof(values)); | 194 isolate->random_number_generator()->NextBytes(values, sizeof(values)); |
195 Label labels[kNumCases]; | 195 Label labels[kNumCases]; |
196 Label near_start, end; | 196 Label near_start, end, done; |
197 | 197 |
198 __ addiu(sp, sp, -4); | 198 __ Push(ra); |
199 __ sw(ra, MemOperand(sp)); | |
200 | |
201 __ mov(v0, zero_reg); | 199 __ mov(v0, zero_reg); |
202 | 200 |
203 __ Branch(&end); | 201 __ Branch(&end); |
204 __ bind(&near_start); | 202 __ bind(&near_start); |
205 | 203 |
206 // Generate slightly less than 32K instructions, which will soon require | 204 // Generate slightly less than 32K instructions, which will soon require |
207 // trampoline for branch distance fixup. | 205 // trampoline for branch distance fixup. |
208 for (int i = 0; i < 32768 - 256; ++i) { | 206 for (int i = 0; i < 32768 - 256; ++i) { |
209 __ addiu(v0, v0, 1); | 207 __ addiu(v0, v0, 1); |
210 } | 208 } |
211 | 209 |
212 Label done; | 210 __ GenerateSwitchTable(a0, kNumCases, |
213 { | 211 [&labels](size_t i) { return labels + i; }); |
214 __ BlockTrampolinePoolFor(kNumCases + 6); | |
215 PredictableCodeSizeScope predictable( | |
216 masm, (kNumCases + 6) * Assembler::kInstrSize); | |
217 Label here; | |
218 | |
219 __ bal(&here); | |
220 __ sll(at, a0, 2); // In delay slot. | |
221 __ bind(&here); | |
222 __ addu(at, at, ra); | |
223 __ lw(at, MemOperand(at, 4 * Assembler::kInstrSize)); | |
224 __ jr(at); | |
225 __ nop(); // Branch delay slot nop. | |
226 for (int i = 0; i < kNumCases; ++i) { | |
227 __ dd(&labels[i]); | |
228 } | |
229 } | |
230 | 212 |
231 for (int i = 0; i < kNumCases; ++i) { | 213 for (int i = 0; i < kNumCases; ++i) { |
232 __ bind(&labels[i]); | 214 __ bind(&labels[i]); |
233 __ lui(v0, (values[i] >> 16) & 0xffff); | 215 __ li(v0, values[i]); |
234 __ ori(v0, v0, values[i] & 0xffff); | |
235 __ Branch(&done); | 216 __ Branch(&done); |
236 } | 217 } |
237 | 218 |
238 __ bind(&done); | 219 __ bind(&done); |
239 __ lw(ra, MemOperand(sp)); | 220 __ Pop(ra); |
240 __ addiu(sp, sp, 4); | |
241 __ jr(ra); | 221 __ jr(ra); |
242 __ nop(); | 222 __ nop(); |
243 | 223 |
244 __ bind(&end); | 224 __ bind(&end); |
245 __ Branch(&near_start); | 225 __ Branch(&near_start); |
246 | 226 |
247 CodeDesc desc; | 227 CodeDesc desc; |
248 masm->GetCode(&desc); | 228 masm->GetCode(&desc); |
249 Handle<Code> code = isolate->factory()->NewCode( | 229 Handle<Code> code = isolate->factory()->NewCode( |
250 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | 230 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
(...skipping 21 matching lines...) Expand all Loading... |
272 MacroAssembler assembler(isolate, nullptr, 0, | 252 MacroAssembler assembler(isolate, nullptr, 0, |
273 v8::internal::CodeObjectRequired::kYes); | 253 v8::internal::CodeObjectRequired::kYes); |
274 MacroAssembler* masm = &assembler; | 254 MacroAssembler* masm = &assembler; |
275 | 255 |
276 const int kNumCases = 512; | 256 const int kNumCases = 512; |
277 int values[kNumCases]; | 257 int values[kNumCases]; |
278 isolate->random_number_generator()->NextBytes(values, sizeof(values)); | 258 isolate->random_number_generator()->NextBytes(values, sizeof(values)); |
279 Label labels[kNumCases]; | 259 Label labels[kNumCases]; |
280 Label done; | 260 Label done; |
281 | 261 |
282 __ addiu(sp, sp, -4); | 262 __ Push(ra); |
283 __ sw(ra, MemOperand(sp)); | |
284 | 263 |
285 { | 264 { |
286 __ BlockTrampolinePoolFor(kNumCases * 2 + 7 + 1); | 265 __ BlockTrampolinePoolFor(kNumCases + 6 + 1); |
287 PredictableCodeSizeScope predictable( | 266 PredictableCodeSizeScope predictable( |
288 masm, kNumCases * kPointerSize + ((7 + 1) * Assembler::kInstrSize)); | 267 masm, kNumCases * kPointerSize + ((6 + 1) * Assembler::kInstrSize)); |
289 Label here; | |
290 | 268 |
291 __ bal(&here); | 269 __ addiupc(at, 6 + 1); |
292 __ sll(at, a0, 2); // In delay slot. | 270 __ lsa(at, at, a0, 2); |
293 __ bind(&here); | 271 __ lw(at, MemOperand(at)); |
294 __ addu(at, at, ra); | |
295 __ lw(at, MemOperand(at, 6 * Assembler::kInstrSize)); | |
296 __ jalr(at); | 272 __ jalr(at); |
297 __ nop(); // Branch delay slot nop. | 273 __ nop(); // Branch delay slot nop. |
298 __ bc(&done); | 274 __ bc(&done); |
| 275 // A nop instruction must be generated by the forbidden slot guard |
| 276 // (Assembler::dd(Label*)). |
299 for (int i = 0; i < kNumCases; ++i) { | 277 for (int i = 0; i < kNumCases; ++i) { |
300 __ dd(&labels[i]); | 278 __ dd(&labels[i]); |
301 } | 279 } |
302 } | 280 } |
303 | 281 |
304 for (int i = 0; i < kNumCases; ++i) { | 282 for (int i = 0; i < kNumCases; ++i) { |
305 __ bind(&labels[i]); | 283 __ bind(&labels[i]); |
306 __ lui(v0, (values[i] >> 16) & 0xffff); | 284 __ li(v0, values[i]); |
307 __ ori(v0, v0, values[i] & 0xffff); | |
308 __ jr(ra); | 285 __ jr(ra); |
309 __ nop(); | 286 __ nop(); |
310 } | 287 } |
311 | 288 |
312 __ bind(&done); | 289 __ bind(&done); |
313 __ lw(ra, MemOperand(sp)); | 290 __ Pop(ra); |
314 __ addiu(sp, sp, 4); | |
315 __ jr(ra); | 291 __ jr(ra); |
316 __ nop(); | 292 __ nop(); |
317 | 293 |
318 CodeDesc desc; | 294 CodeDesc desc; |
319 masm->GetCode(&desc); | 295 masm->GetCode(&desc); |
320 Handle<Code> code = isolate->factory()->NewCode( | 296 Handle<Code> code = isolate->factory()->NewCode( |
321 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | 297 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
322 #ifdef OBJECT_PRINT | 298 #ifdef OBJECT_PRINT |
323 code->Print(std::cout); | 299 code->Print(std::cout); |
324 #endif | 300 #endif |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseLsa); | 383 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseLsa); |
408 for (size_t i = 0; i < nr_test_cases; ++i) { | 384 for (size_t i = 0; i < nr_test_cases; ++i) { |
409 uint32_t res = run_lsa(tc[i].rt, tc[i].rs, tc[i].sa); | 385 uint32_t res = run_lsa(tc[i].rt, tc[i].rs, tc[i].sa); |
410 PrintF("0x%x =? 0x%x == lsa(v0, %x, %x, %hhu)\n", tc[i].expected_res, res, | 386 PrintF("0x%x =? 0x%x == lsa(v0, %x, %x, %hhu)\n", tc[i].expected_res, res, |
411 tc[i].rt, tc[i].rs, tc[i].sa); | 387 tc[i].rt, tc[i].rs, tc[i].sa); |
412 CHECK_EQ(tc[i].expected_res, res); | 388 CHECK_EQ(tc[i].expected_res, res); |
413 } | 389 } |
414 } | 390 } |
415 | 391 |
416 #undef __ | 392 #undef __ |
OLD | NEW |