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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 // greater than number of counted instructions from code, as we are expecting | 289 // greater than number of counted instructions from code, as we are expecting |
290 // generation of trampoline in this case (when number of kFillInstr | 290 // generation of trampoline in this case (when number of kFillInstr |
291 // instructions is close to 32K) | 291 // instructions is close to 32K) |
292 CcTest::InitializeVM(); | 292 CcTest::InitializeVM(); |
293 Isolate* isolate = CcTest::i_isolate(); | 293 Isolate* isolate = CcTest::i_isolate(); |
294 HandleScope scope(isolate); | 294 HandleScope scope(isolate); |
295 MacroAssembler assembler(isolate, nullptr, 0, | 295 MacroAssembler assembler(isolate, nullptr, 0, |
296 v8::internal::CodeObjectRequired::kYes); | 296 v8::internal::CodeObjectRequired::kYes); |
297 MacroAssembler* masm = &assembler; | 297 MacroAssembler* masm = &assembler; |
298 | 298 |
299 const int kNumCases = 40; | 299 const int kSwitchTableCases = 40; |
300 const int kFillInstr = 32551; | 300 const int kInstrSize = 4; |
ivica.bogosavljevic
2016/12/06 09:25:35
this constant is already defined, please reuse it
dusan.simicic
2016/12/06 14:19:39
Done.
| |
301 const int kMaxBranchOffset = (1 << (18 - 1)) - 1; | 301 const int kMaxBranchOffset = (1 << (18 - 1)) - 1; |
302 const int kTrampolineSlotsSize = 4 * Instruction::kInstrSize; | 302 #ifdef _MIPS_ARCH_MIPS32R6 |
303 const int kSwitchTablePrologueSize = 5; | |
ivica.bogosavljevic
2016/12/06 09:25:35
Create a constant and use it both here and in Gene
dusan.simicic
2016/12/06 14:19:40
Done.
| |
304 const int kTrampolineSlotsSize = 2 * kInstrSize; | |
305 #else | |
306 const int kSwitchTablePrologueSize = 10; | |
307 const int kTrampolineSlotsSize = 4 * kInstrSize; | |
ivica.bogosavljevic
2016/12/06 09:25:35
Generally this looks good, but these hardcoded num
dusan.simicic
2016/12/06 14:19:39
kTrampolineSlotsSize constant redefined as public
| |
308 #endif | |
303 const int kMaxOffsetForTrampolineStart = | 309 const int kMaxOffsetForTrampolineStart = |
304 kMaxBranchOffset - 16 * kTrampolineSlotsSize; | 310 kMaxBranchOffset - 16 * kTrampolineSlotsSize; |
311 const int kFillInstr = (kMaxOffsetForTrampolineStart / kInstrSize) - | |
312 (kSwitchTablePrologueSize + kSwitchTableCases) - 20; | |
305 | 313 |
306 int values[kNumCases]; | 314 int values[kSwitchTableCases]; |
307 isolate->random_number_generator()->NextBytes(values, sizeof(values)); | 315 isolate->random_number_generator()->NextBytes(values, sizeof(values)); |
308 Label labels[kNumCases]; | 316 Label labels[kSwitchTableCases]; |
309 Label near_start, end, done; | 317 Label near_start, end, done; |
310 | 318 |
311 __ Push(ra); | 319 __ Push(ra); |
312 __ mov(v0, zero_reg); | 320 __ mov(v0, zero_reg); |
313 | 321 |
314 int offs1 = masm->pc_offset(); | 322 int offs1 = masm->pc_offset(); |
315 int gen_insn = 0; | 323 int gen_insn = 0; |
316 | 324 |
317 __ Branch(&end); | 325 __ Branch(&end); |
318 gen_insn += 2; | 326 gen_insn += IsMipsArchVariant(kMips32r6) ? 1 : 2; |
ivica.bogosavljevic
2016/12/06 09:25:35
this count actually should be something like:
gen_
dusan.simicic
2016/12/06 14:19:39
Done.
| |
319 __ bind(&near_start); | 327 __ bind(&near_start); |
320 | 328 |
321 // Generate slightly less than 32K instructions, which will soon require | 329 // Generate slightly less than 32K instructions, which will soon require |
322 // trampoline for branch distance fixup. | 330 // trampoline for branch distance fixup. |
323 for (int i = 0; i < kFillInstr; ++i) { | 331 for (int i = 0; i < kFillInstr; ++i) { |
324 __ addiu(v0, v0, 1); | 332 __ addiu(v0, v0, 1); |
325 } | 333 } |
326 gen_insn += kFillInstr; | 334 gen_insn += kFillInstr; |
327 | 335 |
328 __ GenerateSwitchTable(a0, kNumCases, | 336 __ GenerateSwitchTable(a0, kSwitchTableCases, |
329 [&labels](size_t i) { return labels + i; }); | 337 [&labels](size_t i) { return labels + i; }); |
330 gen_insn += (10 + kNumCases); | 338 gen_insn += (kSwitchTablePrologueSize + kSwitchTableCases); |
331 | 339 |
332 for (int i = 0; i < kNumCases; ++i) { | 340 for (int i = 0; i < kSwitchTableCases; ++i) { |
333 __ bind(&labels[i]); | 341 __ bind(&labels[i]); |
334 __ li(v0, values[i]); | 342 __ li(v0, values[i]); |
335 __ Branch(&done); | 343 __ Branch(&done); |
336 } | 344 } |
337 gen_insn += (4 * kNumCases); | 345 gen_insn += ((IsMipsArchVariant(kMips32r6) ? 3 : 4) * kSwitchTableCases); |
338 | 346 |
339 // If offset from here to first branch instr is greater than max allowed | 347 // If offset from here to first branch instr is greater than max allowed |
340 // offset for trampoline ... | 348 // offset for trampoline ... |
341 CHECK_LT(kMaxOffsetForTrampolineStart, masm->pc_offset() - offs1); | 349 CHECK_LT(kMaxOffsetForTrampolineStart, masm->pc_offset() - offs1); |
342 // ... number of generated instructions must be greater then "gen_insn", | 350 // ... number of generated instructions must be greater then "gen_insn", |
343 // as we are expecting trampoline generation | 351 // as we are expecting trampoline generation |
344 CHECK_LT(gen_insn, (masm->pc_offset() - offs1) / Instruction::kInstrSize); | 352 CHECK_LT(gen_insn, (masm->pc_offset() - offs1) / kInstrSize); |
345 | 353 |
346 __ bind(&done); | 354 __ bind(&done); |
347 __ Pop(ra); | 355 __ Pop(ra); |
348 __ jr(ra); | 356 __ jr(ra); |
349 __ nop(); | 357 __ nop(); |
350 | 358 |
351 __ bind(&end); | 359 __ bind(&end); |
352 __ Branch(&near_start); | 360 __ Branch(&near_start); |
353 | 361 |
354 CodeDesc desc; | 362 CodeDesc desc; |
355 masm->GetCode(&desc); | 363 masm->GetCode(&desc); |
356 Handle<Code> code = isolate->factory()->NewCode( | 364 Handle<Code> code = isolate->factory()->NewCode( |
357 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | 365 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
358 #ifdef OBJECT_PRINT | 366 #ifdef OBJECT_PRINT |
359 code->Print(std::cout); | 367 code->Print(std::cout); |
360 #endif | 368 #endif |
361 F1 f = FUNCTION_CAST<F1>(code->entry()); | 369 F1 f = FUNCTION_CAST<F1>(code->entry()); |
362 for (int i = 0; i < kNumCases; ++i) { | 370 for (int i = 0; i < kSwitchTableCases; ++i) { |
363 int res = | 371 int res = |
364 reinterpret_cast<int>(CALL_GENERATED_CODE(isolate, f, i, 0, 0, 0, 0)); | 372 reinterpret_cast<int>(CALL_GENERATED_CODE(isolate, f, i, 0, 0, 0, 0)); |
365 ::printf("f(%d) = %d\n", i, res); | 373 ::printf("f(%d) = %d\n", i, res); |
366 CHECK_EQ(values[i], res); | 374 CHECK_EQ(values[i], res); |
367 } | 375 } |
368 } | 376 } |
369 | 377 |
370 static uint32_t run_lsa(uint32_t rt, uint32_t rs, int8_t sa) { | 378 static uint32_t run_lsa(uint32_t rt, uint32_t rs, int8_t sa) { |
371 Isolate* isolate = CcTest::i_isolate(); | 379 Isolate* isolate = CcTest::i_isolate(); |
372 HandleScope scope(isolate); | 380 HandleScope scope(isolate); |
(...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1352 | 1360 |
1353 auto fn_2 = [](MacroAssembler* masm, uint32_t imm) { | 1361 auto fn_2 = [](MacroAssembler* masm, uint32_t imm) { |
1354 __ Sltu(v0, a0, a1); | 1362 __ Sltu(v0, a0, a1); |
1355 }; | 1363 }; |
1356 CHECK_EQ(rs < rd, run_Sltu(rs, rd, fn_2)); | 1364 CHECK_EQ(rs < rd, run_Sltu(rs, rd, fn_2)); |
1357 } | 1365 } |
1358 } | 1366 } |
1359 } | 1367 } |
1360 | 1368 |
1361 #undef __ | 1369 #undef __ |
OLD | NEW |