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

Side by Side Diff: test/cctest/test-macro-assembler-mips.cc

Issue 2530143002: MIPS: Fix trampoline emission after switch table generation (Closed)
Patch Set: Created 4 years 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/mips64/assembler-mips64.cc ('k') | test/cctest/test-macro-assembler-mips64.cc » ('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 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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 #endif 275 #endif
276 F1 f = FUNCTION_CAST<F1>(code->entry()); 276 F1 f = FUNCTION_CAST<F1>(code->entry());
277 for (int i = 0; i < kNumCases; ++i) { 277 for (int i = 0; i < kNumCases; ++i) {
278 int32_t res = reinterpret_cast<int32_t>( 278 int32_t res = reinterpret_cast<int32_t>(
279 CALL_GENERATED_CODE(isolate, f, i, 0, 0, 0, 0)); 279 CALL_GENERATED_CODE(isolate, f, i, 0, 0, 0, 0));
280 ::printf("f(%d) = %d\n", i, res); 280 ::printf("f(%d) = %d\n", i, res);
281 CHECK_EQ(values[i], res); 281 CHECK_EQ(values[i], res);
282 } 282 }
283 } 283 }
284 284
285 TEST(jump_tables6) {
286 // Similar to test-assembler-mips jump_tables1, with extra test for branch
287 // trampoline required after emission of the dd table (where trampolines are
288 // blocked). This test checks if number of really generated instructions is
289 // greater than number of counted instructions from code, as we are expecting
290 // generation of trampoline in this case (when number of kFillInstr
291 // instructions is close to 32K)
292 CcTest::InitializeVM();
293 Isolate* isolate = CcTest::i_isolate();
294 HandleScope scope(isolate);
295 MacroAssembler assembler(isolate, nullptr, 0,
296 v8::internal::CodeObjectRequired::kYes);
297 MacroAssembler* masm = &assembler;
298
299 const int kNumCases = 40;
300 const int kFillInstr = 32551;
301 const int kMaxBranchOffset = (1 << (18 - 1)) - 1;
302 const int kTrampolineSlotsSize = 4 * Instruction::kInstrSize;
303 const int kMaxOffsetForTrampolineStart =
304 kMaxBranchOffset - 16 * kTrampolineSlotsSize;
305
306 int values[kNumCases];
307 isolate->random_number_generator()->NextBytes(values, sizeof(values));
308 Label labels[kNumCases];
309 Label near_start, end, done;
310
311 __ Push(ra);
312 __ mov(v0, zero_reg);
313
314 int offs1 = masm->pc_offset();
315 int gen_insn = 0;
316
317 __ Branch(&end);
318 gen_insn += 2;
319 __ bind(&near_start);
320
321 // Generate slightly less than 32K instructions, which will soon require
322 // trampoline for branch distance fixup.
323 for (int i = 0; i < kFillInstr; ++i) {
324 __ addiu(v0, v0, 1);
325 }
326 gen_insn += kFillInstr;
327
328 __ GenerateSwitchTable(a0, kNumCases,
329 [&labels](size_t i) { return labels + i; });
330 gen_insn += (10 + kNumCases);
331
332 for (int i = 0; i < kNumCases; ++i) {
333 __ bind(&labels[i]);
334 __ li(v0, values[i]);
335 __ Branch(&done);
336 }
337 gen_insn += (4 * kNumCases);
338
339 // If offset from here to first branch instr is greater than max allowed
340 // offset for trampoline ...
341 CHECK_LT(kMaxOffsetForTrampolineStart, masm->pc_offset() - offs1);
342 // ... number of generated instructions must be greater then "gen_insn",
343 // as we are expecting trampoline generation
344 CHECK_LT(gen_insn, (masm->pc_offset() - offs1) / Instruction::kInstrSize);
345
346 __ bind(&done);
347 __ Pop(ra);
348 __ jr(ra);
349 __ nop();
350
351 __ bind(&end);
352 __ Branch(&near_start);
353
354 CodeDesc desc;
355 masm->GetCode(&desc);
356 Handle<Code> code = isolate->factory()->NewCode(
357 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
358 #ifdef OBJECT_PRINT
359 code->Print(std::cout);
360 #endif
361 F1 f = FUNCTION_CAST<F1>(code->entry());
362 for (int i = 0; i < kNumCases; ++i) {
363 int res =
364 reinterpret_cast<int>(CALL_GENERATED_CODE(isolate, f, i, 0, 0, 0, 0));
365 ::printf("f(%d) = %d\n", i, res);
366 CHECK_EQ(values[i], res);
367 }
368 }
285 369
286 static uint32_t run_lsa(uint32_t rt, uint32_t rs, int8_t sa) { 370 static uint32_t run_lsa(uint32_t rt, uint32_t rs, int8_t sa) {
287 Isolate* isolate = CcTest::i_isolate(); 371 Isolate* isolate = CcTest::i_isolate();
288 HandleScope scope(isolate); 372 HandleScope scope(isolate);
289 MacroAssembler assembler(isolate, nullptr, 0, 373 MacroAssembler assembler(isolate, nullptr, 0,
290 v8::internal::CodeObjectRequired::kYes); 374 v8::internal::CodeObjectRequired::kYes);
291 MacroAssembler* masm = &assembler; 375 MacroAssembler* masm = &assembler;
292 376
293 __ Lsa(v0, a0, a1, sa); 377 __ Lsa(v0, a0, a1, sa);
294 __ jr(ra); 378 __ jr(ra);
(...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 __ Sltu(v0, a0, Operand(imm)); 1346 __ Sltu(v0, a0, Operand(imm));
1263 })); 1347 }));
1264 CHECK_EQ(rs < rd, 1348 CHECK_EQ(rs < rd,
1265 run_Sltu(rs, rd, [](MacroAssembler* masm, 1349 run_Sltu(rs, rd, [](MacroAssembler* masm,
1266 uint32_t imm) { __ Sltu(v0, a0, a1); })); 1350 uint32_t imm) { __ Sltu(v0, a0, a1); }));
1267 } 1351 }
1268 } 1352 }
1269 } 1353 }
1270 1354
1271 #undef __ 1355 #undef __
OLDNEW
« no previous file with comments | « src/mips64/assembler-mips64.cc ('k') | test/cctest/test-macro-assembler-mips64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698