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