| 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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 // greater than number of counted instructions from code, as we are expecting | 357 // greater than number of counted instructions from code, as we are expecting |
| 358 // generation of trampoline in this case (when number of kFillInstr | 358 // generation of trampoline in this case (when number of kFillInstr |
| 359 // instructions is close to 32K) | 359 // instructions is close to 32K) |
| 360 CcTest::InitializeVM(); | 360 CcTest::InitializeVM(); |
| 361 Isolate* isolate = CcTest::i_isolate(); | 361 Isolate* isolate = CcTest::i_isolate(); |
| 362 HandleScope scope(isolate); | 362 HandleScope scope(isolate); |
| 363 MacroAssembler assembler(isolate, nullptr, 0, | 363 MacroAssembler assembler(isolate, nullptr, 0, |
| 364 v8::internal::CodeObjectRequired::kYes); | 364 v8::internal::CodeObjectRequired::kYes); |
| 365 MacroAssembler* masm = &assembler; | 365 MacroAssembler* masm = &assembler; |
| 366 | 366 |
| 367 const int kNumCases = 40; | 367 const int kSwitchTableCases = 40; |
| 368 const int kFillInstr = 32551; | 368 |
| 369 const int kMaxBranchOffset = (1 << (18 - 1)) - 1; | 369 const int kInstrSize = Assembler::kInstrSize; |
| 370 const int kTrampolineSlotsSize = 2 * Instruction::kInstrSize; | 370 const int kMaxBranchOffset = Assembler::kMaxBranchOffset; |
| 371 const int kTrampolineSlotsSize = Assembler::kTrampolineSlotsSize; |
| 372 const int kSwitchTablePrologueSize = MacroAssembler::kSwitchTablePrologueSize; |
| 373 |
| 371 const int kMaxOffsetForTrampolineStart = | 374 const int kMaxOffsetForTrampolineStart = |
| 372 kMaxBranchOffset - 16 * kTrampolineSlotsSize; | 375 kMaxBranchOffset - 16 * kTrampolineSlotsSize; |
| 376 const int kFillInstr = (kMaxOffsetForTrampolineStart / kInstrSize) - |
| 377 (kSwitchTablePrologueSize + 2 * kSwitchTableCases) - |
| 378 20; |
| 373 | 379 |
| 374 int values[kNumCases]; | 380 int values[kSwitchTableCases]; |
| 375 isolate->random_number_generator()->NextBytes(values, sizeof(values)); | 381 isolate->random_number_generator()->NextBytes(values, sizeof(values)); |
| 376 Label labels[kNumCases]; | 382 Label labels[kSwitchTableCases]; |
| 377 Label near_start, end, done; | 383 Label near_start, end, done; |
| 378 | 384 |
| 379 __ Push(ra); | 385 __ Push(ra); |
| 380 __ mov(v0, zero_reg); | 386 __ mov(v0, zero_reg); |
| 381 | 387 |
| 382 int offs1 = masm->pc_offset(); | 388 int offs1 = masm->pc_offset(); |
| 383 int gen_insn = 0; | 389 int gen_insn = 0; |
| 384 | 390 |
| 385 __ Branch(&end); | 391 __ Branch(&end); |
| 386 gen_insn += 2; | 392 gen_insn += Assembler::IsCompactBranchSupported() ? 1 : 2; |
| 387 __ bind(&near_start); | 393 __ bind(&near_start); |
| 388 | 394 |
| 389 // Generate slightly less than 32K instructions, which will soon require | 395 // Generate slightly less than 32K instructions, which will soon require |
| 390 // trampoline for branch distance fixup. | 396 // trampoline for branch distance fixup. |
| 391 for (int i = 0; i < kFillInstr; ++i) { | 397 for (int i = 0; i < kFillInstr; ++i) { |
| 392 __ addiu(v0, v0, 1); | 398 __ addiu(v0, v0, 1); |
| 393 } | 399 } |
| 394 gen_insn += kFillInstr; | 400 gen_insn += kFillInstr; |
| 395 | 401 |
| 396 __ GenerateSwitchTable(a0, kNumCases, | 402 __ GenerateSwitchTable(a0, kSwitchTableCases, |
| 397 [&labels](size_t i) { return labels + i; }); | 403 [&labels](size_t i) { return labels + i; }); |
| 398 gen_insn += (11 + 2 * kNumCases); | 404 gen_insn += (kSwitchTablePrologueSize + 2 * kSwitchTableCases); |
| 399 | 405 |
| 400 for (int i = 0; i < kNumCases; ++i) { | 406 for (int i = 0; i < kSwitchTableCases; ++i) { |
| 401 __ bind(&labels[i]); | 407 __ bind(&labels[i]); |
| 402 __ li(v0, values[i]); | 408 __ li(v0, values[i]); |
| 403 __ Branch(&done); | 409 __ Branch(&done); |
| 404 } | 410 } |
| 405 gen_insn += (4 * kNumCases); | 411 gen_insn += |
| 412 ((Assembler::IsCompactBranchSupported() ? 3 : 4) * kSwitchTableCases); |
| 406 | 413 |
| 407 // If offset from here to first branch instr is greater than max allowed | 414 // If offset from here to first branch instr is greater than max allowed |
| 408 // offset for trampoline ... | 415 // offset for trampoline ... |
| 409 CHECK_LT(kMaxOffsetForTrampolineStart, masm->pc_offset() - offs1); | 416 CHECK_LT(kMaxOffsetForTrampolineStart, masm->pc_offset() - offs1); |
| 410 // ... number of generated instructions must be greater then "gen_insn", | 417 // ... number of generated instructions must be greater then "gen_insn", |
| 411 // as we are expecting trampoline generation | 418 // as we are expecting trampoline generation |
| 412 CHECK_LT(gen_insn, (masm->pc_offset() - offs1) / Instruction::kInstrSize); | 419 CHECK_LT(gen_insn, (masm->pc_offset() - offs1) / kInstrSize); |
| 413 | 420 |
| 414 __ bind(&done); | 421 __ bind(&done); |
| 415 __ Pop(ra); | 422 __ Pop(ra); |
| 416 __ jr(ra); | 423 __ jr(ra); |
| 417 __ nop(); | 424 __ nop(); |
| 418 | 425 |
| 419 __ bind(&end); | 426 __ bind(&end); |
| 420 __ Branch(&near_start); | 427 __ Branch(&near_start); |
| 421 | 428 |
| 422 CodeDesc desc; | 429 CodeDesc desc; |
| 423 masm->GetCode(&desc); | 430 masm->GetCode(&desc); |
| 424 Handle<Code> code = isolate->factory()->NewCode( | 431 Handle<Code> code = isolate->factory()->NewCode( |
| 425 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | 432 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 426 #ifdef OBJECT_PRINT | 433 #ifdef OBJECT_PRINT |
| 427 code->Print(std::cout); | 434 code->Print(std::cout); |
| 428 #endif | 435 #endif |
| 429 F1 f = FUNCTION_CAST<F1>(code->entry()); | 436 F1 f = FUNCTION_CAST<F1>(code->entry()); |
| 430 for (int i = 0; i < kNumCases; ++i) { | 437 for (int i = 0; i < kSwitchTableCases; ++i) { |
| 431 int64_t res = reinterpret_cast<int64_t>( | 438 int64_t res = reinterpret_cast<int64_t>( |
| 432 CALL_GENERATED_CODE(isolate, f, i, 0, 0, 0, 0)); | 439 CALL_GENERATED_CODE(isolate, f, i, 0, 0, 0, 0)); |
| 433 ::printf("f(%d) = %" PRId64 "\n", i, res); | 440 ::printf("f(%d) = %" PRId64 "\n", i, res); |
| 434 CHECK_EQ(values[i], res); | 441 CHECK_EQ(values[i], res); |
| 435 } | 442 } |
| 436 } | 443 } |
| 437 | 444 |
| 438 static uint64_t run_lsa(uint32_t rt, uint32_t rs, int8_t sa) { | 445 static uint64_t run_lsa(uint32_t rt, uint32_t rs, int8_t sa) { |
| 439 Isolate* isolate = CcTest::i_isolate(); | 446 Isolate* isolate = CcTest::i_isolate(); |
| 440 HandleScope scope(isolate); | 447 HandleScope scope(isolate); |
| (...skipping 1520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1961 | 1968 |
| 1962 auto fn_2 = [](MacroAssembler* masm, uint64_t imm) { | 1969 auto fn_2 = [](MacroAssembler* masm, uint64_t imm) { |
| 1963 __ Sltu(v0, a0, a1); | 1970 __ Sltu(v0, a0, a1); |
| 1964 }; | 1971 }; |
| 1965 CHECK_EQ(rs < rd, run_Sltu(rs, rd, fn_2)); | 1972 CHECK_EQ(rs < rd, run_Sltu(rs, rd, fn_2)); |
| 1966 } | 1973 } |
| 1967 } | 1974 } |
| 1968 } | 1975 } |
| 1969 | 1976 |
| 1970 #undef __ | 1977 #undef __ |
| OLD | NEW |