| 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 |
| 301 const int kMaxBranchOffset = (1 << (18 - 1)) - 1; | 301 const int kInstrSize = Assembler::kInstrSize; |
| 302 const int kTrampolineSlotsSize = 4 * Instruction::kInstrSize; | 302 const int kMaxBranchOffset = Assembler::kMaxBranchOffset; |
| 303 const int kTrampolineSlotsSize = Assembler::kTrampolineSlotsSize; |
| 304 const int kSwitchTablePrologueSize = MacroAssembler::kSwitchTablePrologueSize; |
| 305 |
| 303 const int kMaxOffsetForTrampolineStart = | 306 const int kMaxOffsetForTrampolineStart = |
| 304 kMaxBranchOffset - 16 * kTrampolineSlotsSize; | 307 kMaxBranchOffset - 16 * kTrampolineSlotsSize; |
| 308 const int kFillInstr = (kMaxOffsetForTrampolineStart / kInstrSize) - |
| 309 (kSwitchTablePrologueSize + kSwitchTableCases) - 20; |
| 305 | 310 |
| 306 int values[kNumCases]; | 311 int values[kSwitchTableCases]; |
| 307 isolate->random_number_generator()->NextBytes(values, sizeof(values)); | 312 isolate->random_number_generator()->NextBytes(values, sizeof(values)); |
| 308 Label labels[kNumCases]; | 313 Label labels[kSwitchTableCases]; |
| 309 Label near_start, end, done; | 314 Label near_start, end, done; |
| 310 | 315 |
| 311 __ Push(ra); | 316 __ Push(ra); |
| 312 __ mov(v0, zero_reg); | 317 __ mov(v0, zero_reg); |
| 313 | 318 |
| 314 int offs1 = masm->pc_offset(); | 319 int offs1 = masm->pc_offset(); |
| 315 int gen_insn = 0; | 320 int gen_insn = 0; |
| 316 | 321 |
| 317 __ Branch(&end); | 322 __ Branch(&end); |
| 318 gen_insn += 2; | 323 gen_insn += Assembler::IsCompactBranchSupported() ? 1 : 2; |
| 319 __ bind(&near_start); | 324 __ bind(&near_start); |
| 320 | 325 |
| 321 // Generate slightly less than 32K instructions, which will soon require | 326 // Generate slightly less than 32K instructions, which will soon require |
| 322 // trampoline for branch distance fixup. | 327 // trampoline for branch distance fixup. |
| 323 for (int i = 0; i < kFillInstr; ++i) { | 328 for (int i = 0; i < kFillInstr; ++i) { |
| 324 __ addiu(v0, v0, 1); | 329 __ addiu(v0, v0, 1); |
| 325 } | 330 } |
| 326 gen_insn += kFillInstr; | 331 gen_insn += kFillInstr; |
| 327 | 332 |
| 328 __ GenerateSwitchTable(a0, kNumCases, | 333 __ GenerateSwitchTable(a0, kSwitchTableCases, |
| 329 [&labels](size_t i) { return labels + i; }); | 334 [&labels](size_t i) { return labels + i; }); |
| 330 gen_insn += (10 + kNumCases); | 335 gen_insn += (kSwitchTablePrologueSize + kSwitchTableCases); |
| 331 | 336 |
| 332 for (int i = 0; i < kNumCases; ++i) { | 337 for (int i = 0; i < kSwitchTableCases; ++i) { |
| 333 __ bind(&labels[i]); | 338 __ bind(&labels[i]); |
| 334 __ li(v0, values[i]); | 339 __ li(v0, values[i]); |
| 335 __ Branch(&done); | 340 __ Branch(&done); |
| 336 } | 341 } |
| 337 gen_insn += (4 * kNumCases); | 342 gen_insn += |
| 343 ((Assembler::IsCompactBranchSupported() ? 3 : 4) * kSwitchTableCases); |
| 338 | 344 |
| 339 // If offset from here to first branch instr is greater than max allowed | 345 // If offset from here to first branch instr is greater than max allowed |
| 340 // offset for trampoline ... | 346 // offset for trampoline ... |
| 341 CHECK_LT(kMaxOffsetForTrampolineStart, masm->pc_offset() - offs1); | 347 CHECK_LT(kMaxOffsetForTrampolineStart, masm->pc_offset() - offs1); |
| 342 // ... number of generated instructions must be greater then "gen_insn", | 348 // ... number of generated instructions must be greater then "gen_insn", |
| 343 // as we are expecting trampoline generation | 349 // as we are expecting trampoline generation |
| 344 CHECK_LT(gen_insn, (masm->pc_offset() - offs1) / Instruction::kInstrSize); | 350 CHECK_LT(gen_insn, (masm->pc_offset() - offs1) / kInstrSize); |
| 345 | 351 |
| 346 __ bind(&done); | 352 __ bind(&done); |
| 347 __ Pop(ra); | 353 __ Pop(ra); |
| 348 __ jr(ra); | 354 __ jr(ra); |
| 349 __ nop(); | 355 __ nop(); |
| 350 | 356 |
| 351 __ bind(&end); | 357 __ bind(&end); |
| 352 __ Branch(&near_start); | 358 __ Branch(&near_start); |
| 353 | 359 |
| 354 CodeDesc desc; | 360 CodeDesc desc; |
| 355 masm->GetCode(&desc); | 361 masm->GetCode(&desc); |
| 356 Handle<Code> code = isolate->factory()->NewCode( | 362 Handle<Code> code = isolate->factory()->NewCode( |
| 357 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | 363 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 358 #ifdef OBJECT_PRINT | 364 #ifdef OBJECT_PRINT |
| 359 code->Print(std::cout); | 365 code->Print(std::cout); |
| 360 #endif | 366 #endif |
| 361 F1 f = FUNCTION_CAST<F1>(code->entry()); | 367 F1 f = FUNCTION_CAST<F1>(code->entry()); |
| 362 for (int i = 0; i < kNumCases; ++i) { | 368 for (int i = 0; i < kSwitchTableCases; ++i) { |
| 363 int res = | 369 int res = |
| 364 reinterpret_cast<int>(CALL_GENERATED_CODE(isolate, f, i, 0, 0, 0, 0)); | 370 reinterpret_cast<int>(CALL_GENERATED_CODE(isolate, f, i, 0, 0, 0, 0)); |
| 365 ::printf("f(%d) = %d\n", i, res); | 371 ::printf("f(%d) = %d\n", i, res); |
| 366 CHECK_EQ(values[i], res); | 372 CHECK_EQ(values[i], res); |
| 367 } | 373 } |
| 368 } | 374 } |
| 369 | 375 |
| 370 static uint32_t run_lsa(uint32_t rt, uint32_t rs, int8_t sa) { | 376 static uint32_t run_lsa(uint32_t rt, uint32_t rs, int8_t sa) { |
| 371 Isolate* isolate = CcTest::i_isolate(); | 377 Isolate* isolate = CcTest::i_isolate(); |
| 372 HandleScope scope(isolate); | 378 HandleScope scope(isolate); |
| (...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1352 | 1358 |
| 1353 auto fn_2 = [](MacroAssembler* masm, uint32_t imm) { | 1359 auto fn_2 = [](MacroAssembler* masm, uint32_t imm) { |
| 1354 __ Sltu(v0, a0, a1); | 1360 __ Sltu(v0, a0, a1); |
| 1355 }; | 1361 }; |
| 1356 CHECK_EQ(rs < rd, run_Sltu(rs, rd, fn_2)); | 1362 CHECK_EQ(rs < rd, run_Sltu(rs, rd, fn_2)); |
| 1357 } | 1363 } |
| 1358 } | 1364 } |
| 1359 } | 1365 } |
| 1360 | 1366 |
| 1361 #undef __ | 1367 #undef __ |
| OLD | NEW |