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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 #endif | 343 #endif |
344 F1 f = FUNCTION_CAST<F1>(code->entry()); | 344 F1 f = FUNCTION_CAST<F1>(code->entry()); |
345 for (int i = 0; i < kNumCases; ++i) { | 345 for (int i = 0; i < kNumCases; ++i) { |
346 int64_t res = reinterpret_cast<int64_t>( | 346 int64_t res = reinterpret_cast<int64_t>( |
347 CALL_GENERATED_CODE(isolate, f, i, 0, 0, 0, 0)); | 347 CALL_GENERATED_CODE(isolate, f, i, 0, 0, 0, 0)); |
348 ::printf("f(%d) = %" PRId64 "\n", i, res); | 348 ::printf("f(%d) = %" PRId64 "\n", i, res); |
349 CHECK_EQ(values[i], res); | 349 CHECK_EQ(values[i], res); |
350 } | 350 } |
351 } | 351 } |
352 | 352 |
| 353 TEST(jump_tables6) { |
| 354 // Similar to test-assembler-mips jump_tables1, with extra test for branch |
| 355 // trampoline required after emission of the dd table (where trampolines are |
| 356 // blocked). This test checks if number of really generated instructions is |
| 357 // greater than number of counted instructions from code, as we are expecting |
| 358 // generation of trampoline in this case (when number of kFillInstr |
| 359 // instructions is close to 32K) |
| 360 CcTest::InitializeVM(); |
| 361 Isolate* isolate = CcTest::i_isolate(); |
| 362 HandleScope scope(isolate); |
| 363 MacroAssembler assembler(isolate, nullptr, 0, |
| 364 v8::internal::CodeObjectRequired::kYes); |
| 365 MacroAssembler* masm = &assembler; |
| 366 |
| 367 const int kNumCases = 40; |
| 368 const int kFillInstr = 32551; |
| 369 const int kMaxBranchOffset = (1 << (18 - 1)) - 1; |
| 370 const int kTrampolineSlotsSize = 2 * Instruction::kInstrSize; |
| 371 const int kMaxOffsetForTrampolineStart = |
| 372 kMaxBranchOffset - 16 * kTrampolineSlotsSize; |
| 373 |
| 374 int values[kNumCases]; |
| 375 isolate->random_number_generator()->NextBytes(values, sizeof(values)); |
| 376 Label labels[kNumCases]; |
| 377 Label near_start, end, done; |
| 378 |
| 379 __ Push(ra); |
| 380 __ mov(v0, zero_reg); |
| 381 |
| 382 int offs1 = masm->pc_offset(); |
| 383 int gen_insn = 0; |
| 384 |
| 385 __ Branch(&end); |
| 386 gen_insn += 2; |
| 387 __ bind(&near_start); |
| 388 |
| 389 // Generate slightly less than 32K instructions, which will soon require |
| 390 // trampoline for branch distance fixup. |
| 391 for (int i = 0; i < kFillInstr; ++i) { |
| 392 __ addiu(v0, v0, 1); |
| 393 } |
| 394 gen_insn += kFillInstr; |
| 395 |
| 396 __ GenerateSwitchTable(a0, kNumCases, |
| 397 [&labels](size_t i) { return labels + i; }); |
| 398 gen_insn += (11 + 2 * kNumCases); |
| 399 |
| 400 for (int i = 0; i < kNumCases; ++i) { |
| 401 __ bind(&labels[i]); |
| 402 __ li(v0, values[i]); |
| 403 __ Branch(&done); |
| 404 } |
| 405 gen_insn += (4 * kNumCases); |
| 406 |
| 407 // If offset from here to first branch instr is greater than max allowed |
| 408 // offset for trampoline ... |
| 409 CHECK_LT(kMaxOffsetForTrampolineStart, masm->pc_offset() - offs1); |
| 410 // ... number of generated instructions must be greater then "gen_insn", |
| 411 // as we are expecting trampoline generation |
| 412 CHECK_LT(gen_insn, (masm->pc_offset() - offs1) / Instruction::kInstrSize); |
| 413 |
| 414 __ bind(&done); |
| 415 __ Pop(ra); |
| 416 __ jr(ra); |
| 417 __ nop(); |
| 418 |
| 419 __ bind(&end); |
| 420 __ Branch(&near_start); |
| 421 |
| 422 CodeDesc desc; |
| 423 masm->GetCode(&desc); |
| 424 Handle<Code> code = isolate->factory()->NewCode( |
| 425 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 426 #ifdef OBJECT_PRINT |
| 427 code->Print(std::cout); |
| 428 #endif |
| 429 F1 f = FUNCTION_CAST<F1>(code->entry()); |
| 430 for (int i = 0; i < kNumCases; ++i) { |
| 431 int64_t res = reinterpret_cast<int64_t>( |
| 432 CALL_GENERATED_CODE(isolate, f, i, 0, 0, 0, 0)); |
| 433 ::printf("f(%d) = %" PRId64 "\n", i, res); |
| 434 CHECK_EQ(values[i], res); |
| 435 } |
| 436 } |
353 | 437 |
354 static uint64_t run_lsa(uint32_t rt, uint32_t rs, int8_t sa) { | 438 static uint64_t run_lsa(uint32_t rt, uint32_t rs, int8_t sa) { |
355 Isolate* isolate = CcTest::i_isolate(); | 439 Isolate* isolate = CcTest::i_isolate(); |
356 HandleScope scope(isolate); | 440 HandleScope scope(isolate); |
357 MacroAssembler assembler(isolate, nullptr, 0, | 441 MacroAssembler assembler(isolate, nullptr, 0, |
358 v8::internal::CodeObjectRequired::kYes); | 442 v8::internal::CodeObjectRequired::kYes); |
359 MacroAssembler* masm = &assembler; | 443 MacroAssembler* masm = &assembler; |
360 | 444 |
361 __ Lsa(v0, a0, a1, sa); | 445 __ Lsa(v0, a0, a1, sa); |
362 __ jr(ra); | 446 __ jr(ra); |
(...skipping 1505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1868 __ Sltu(v0, a0, Operand(imm)); | 1952 __ Sltu(v0, a0, Operand(imm)); |
1869 })); | 1953 })); |
1870 CHECK_EQ(rs < rd, | 1954 CHECK_EQ(rs < rd, |
1871 run_Sltu(rs, rd, [](MacroAssembler* masm, | 1955 run_Sltu(rs, rd, [](MacroAssembler* masm, |
1872 uint64_t imm) { __ Sltu(v0, a0, a1); })); | 1956 uint64_t imm) { __ Sltu(v0, a0, a1); })); |
1873 } | 1957 } |
1874 } | 1958 } |
1875 } | 1959 } |
1876 | 1960 |
1877 #undef __ | 1961 #undef __ |
OLD | NEW |