Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(749)

Side by Side Diff: test/cctest/test-assembler-mips.cc

Issue 1144373003: MIPS: Implemented PC-relative instructions for R6. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Implementation BC and BALC. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 4244 matching lines...) Expand 10 before | Expand all | Expand 10 after
4255 __ lwc1(f2, MemOperand(a0, OFFSET_OF(Test, fOp2)) ); 4255 __ lwc1(f2, MemOperand(a0, OFFSET_OF(Test, fOp2)) );
4256 __ nop(); 4256 __ nop();
4257 __ div_s(f6, f4, f2); 4257 __ div_s(f6, f4, f2);
4258 __ swc1(f6, MemOperand(a0, OFFSET_OF(Test, fRes)) ); 4258 __ swc1(f6, MemOperand(a0, OFFSET_OF(Test, fRes)) );
4259 4259
4260 // Restore FCSR. 4260 // Restore FCSR.
4261 __ ctc1(a1, FCSR); 4261 __ ctc1(a1, FCSR);
4262 4262
4263 __ jr(ra); 4263 __ jr(ra);
4264 __ nop(); 4264 __ nop();
4265
4265 CodeDesc desc; 4266 CodeDesc desc;
4266 assm.GetCode(&desc); 4267 assm.GetCode(&desc);
4267 Handle<Code> code = isolate->factory()->NewCode( 4268 Handle<Code> code = isolate->factory()->NewCode(
4268 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); 4269 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
4270
4269 F3 f = FUNCTION_CAST<F3>(code->entry()); 4271 F3 f = FUNCTION_CAST<F3>(code->entry());
4270 4272
4271 (CALL_GENERATED_CODE(f, &test, 0, 0, 0, 0)); 4273 (CALL_GENERATED_CODE(f, &test, 0, 0, 0, 0));
4272 4274
4273 const int test_size = 3; 4275 const int test_size = 3;
4274 4276
4275 double dOp1[test_size] = { 4277 double dOp1[test_size] = {
4276 5.0, 4278 5.0,
4277 DBL_MAX, 4279 DBL_MAX,
4278 DBL_MAX, 4280 DBL_MAX,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
4336 test.dOp2 = -5.0; 4338 test.dOp2 = -5.0;
4337 test.fOp1 = std::numeric_limits<float>::quiet_NaN(); 4339 test.fOp1 = std::numeric_limits<float>::quiet_NaN();
4338 test.fOp2 = -5.0; 4340 test.fOp2 = -5.0;
4339 4341
4340 (CALL_GENERATED_CODE(f, &test, 0, 0, 0, 0)); 4342 (CALL_GENERATED_CODE(f, &test, 0, 0, 0, 0));
4341 CHECK_EQ(true, std::isnan(test.dRes)); 4343 CHECK_EQ(true, std::isnan(test.dRes));
4342 CHECK_EQ(true, std::isnan(test.fRes)); 4344 CHECK_EQ(true, std::isnan(test.fRes));
4343 } 4345 }
4344 4346
4345 4347
4348 uint32_t run_align(uint32_t rs, uint32_t rt, uint8_t bp) {
4349 Isolate* isolate = CcTest::i_isolate();
4350 HandleScope scope(isolate);
4351
4352 MacroAssembler assm(isolate, NULL, 0);
4353
4354 // ALIGN rd, rs, rt, bp
4355 __ align(v0, a0, a1, bp);
4356 __ jr(ra);
4357 __ nop();
4358
4359 CodeDesc desc;
4360 assm.GetCode(&desc);
4361 Handle<Code> code = isolate->factory()->NewCode(
4362 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
4363
4364 F2 f = FUNCTION_CAST<F2>(code->entry());
4365
4366 uint32_t rd =
4367 reinterpret_cast<uint32_t>(CALL_GENERATED_CODE(f, rs, rt, bp, 0, 0));
4368
4369 return rd;
4370 }
4371
4372
4373 TEST(r6_align) {
4374 if (IsMipsArchVariant(kMips32r6)) {
4375 CcTest::InitializeVM();
4376
4377 struct TestCaseAlign {
4378 uint32_t rd_expected;
4379 uint32_t rs;
4380 uint32_t rt;
4381 uint8_t bp;
4382 };
4383
4384 struct TestCaseAlign tc[] = {
4385 // rd_expected, rs, rt, bp
4386 { 0xaabbccdd, 0x11223344, 0xaabbccdd, 0 },
4387 { 0xbbccdd11, 0x11223344, 0xaabbccdd, 1 },
4388 { 0xccdd1122, 0x11223344, 0xaabbccdd, 2 },
4389 { 0xdd112233, 0x11223344, 0xaabbccdd, 3 },
4390 };
4391
4392 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseAlign);
4393 for (size_t i = 0; i < nr_test_cases; ++i) {
4394 CHECK_EQ(tc[i].rd_expected, run_align(tc[i].rs, tc[i].rt, tc[i].bp));
4395 }
4396 }
4397 }
4398
4399 uint32_t PC; // Program Counter
paul.l... 2015/06/11 05:56:32 nit: period at end.
ilija.pavlovic 2015/06/12 09:51:33 Done.
4400
4401 uint32_t run_aluipc(int16_t imm16) {
4402 Isolate* isolate = CcTest::i_isolate();
4403 HandleScope scope(isolate);
4404
4405 MacroAssembler assm(isolate, NULL, 0);
4406
4407 // ALUIPC rs, imm16
4408 __ aluipc(v0, imm16);
4409 __ jr(ra);
4410 __ nop();
4411
4412 CodeDesc desc;
4413 assm.GetCode(&desc);
4414 Handle<Code> code = isolate->factory()->NewCode(
4415 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
4416
4417 F2 f = FUNCTION_CAST<F2>(code->entry());
4418 PC = (uint32_t) f; // set program counter
paul.l... 2015/06/11 05:56:32 nit: Start with capital, end with period. Many mor
ilija.pavlovic 2015/06/12 09:51:33 Done.
4419
4420 uint32_t rs =
4421 reinterpret_cast<uint32_t>(CALL_GENERATED_CODE(f, imm16, 0, 0, 0, 0));
4422
4423 return rs;
4424 }
4425
4426
4427 TEST(r6_aluipc) {
4428 if (IsMipsArchVariant(kMips32r6)) {
4429 CcTest::InitializeVM();
4430
4431 struct TestCaseAluipc {
4432 uint32_t rs_expected;
4433 int16_t imm16;
4434 };
4435
4436 struct TestCaseAluipc tc[] = {
4437 // rs_expected has formal arguments
4438 // rs_expected, imm16
4439 { 0x0, -32768 }, // 0x8000
4440 { 0x0, -1 }, // 0xFFFF
4441 { 0x0, 0 },
4442 { 0x0, 1 },
4443 { 0x0, 32767 }, // 0x7FFF
4444 };
4445
4446 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseAluipc);
4447 for (size_t i = 0; i < nr_test_cases; ++i) {
4448 PC = 0;
4449 uint32_t rs = run_aluipc(tc[i].imm16);
4450 // Now, the program_counter (PC) is set
4451 uint32_t rs_expected = ~0x0FFFF & (PC + (tc[i].imm16 << 16));
4452 CHECK_EQ(rs_expected, rs);
4453 }
4454 }
4455 }
4456
4457
4458 uint32_t run_auipc(int16_t imm16) {
4459 Isolate* isolate = CcTest::i_isolate();
4460 HandleScope scope(isolate);
4461
4462 MacroAssembler assm(isolate, NULL, 0);
4463
4464 // AUIPC rs, imm16
4465 __ auipc(v0, imm16);
4466 __ jr(ra);
4467 __ nop();
4468
4469 CodeDesc desc;
4470 assm.GetCode(&desc);
4471 Handle<Code> code = isolate->factory()->NewCode(
4472 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
4473
4474 F2 f = FUNCTION_CAST<F2>(code->entry());
4475 PC = (uint32_t) f; // set program counter
4476
4477 uint32_t rs =
4478 reinterpret_cast<uint32_t>(CALL_GENERATED_CODE(f, imm16, 0, 0, 0, 0));
4479
4480 return rs;
4481 }
4482
4483
4484 TEST(r6_auipc) {
4485 if (IsMipsArchVariant(kMips32r6)) {
4486 CcTest::InitializeVM();
4487
4488 struct TestCaseAuipc {
4489 uint32_t rs_expected;
4490 int16_t imm16;
4491 };
4492
4493 struct TestCaseAuipc tc[] = {
4494 // rs_expected has formal arguments
4495 // rs_expected, imm16
4496 { 0x0, -32768 }, // 0x8000
4497 { 0x0, -1 }, // 0xFFFF
4498 { 0x0, 0 },
4499 { 0x0, 1 },
4500 { 0x0, 32767 }, // 0x7FFF
4501 };
4502
4503 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseAuipc);
4504 for (size_t i = 0; i < nr_test_cases; ++i) {
4505 PC = 0;
4506 uint32_t rs = run_auipc(tc[i].imm16);
4507 // Now, the program_counter (PC) is set
4508 uint32_t rs_expected = PC + (tc[i].imm16 << 16);
4509 CHECK_EQ(rs_expected, rs);
4510 }
4511 }
4512 }
4513
4514
4515 uint32_t run_lwpc(int rs, int offset) {
4516 Isolate* isolate = CcTest::i_isolate();
4517 HandleScope scope(isolate);
4518
4519 MacroAssembler assm(isolate, NULL, 0);
4520
4521 // 256k instructions; 2^8k
4522 // addiu t3, a4, 0xffff; (0x250fffff)
paul.l... 2015/06/11 05:56:32 You have mips64 register names here. This is addiu
ilija.pavlovic 2015/06/12 09:51:33 Adapted names in the code comment. addiu t7, t0, 0
4523 // ...
4524 // addiu t0, a4, 0x0000; (0x250c0000)
4525 uint32_t addiu_start_1 = 0x25000000;
4526 for (int32_t i = 0xfffff; i >= 0xc0000; --i) {
4527 uint32_t addiu_new = addiu_start_1 + i;
4528 __ dd(addiu_new);
4529 }
4530
4531 __ lwpc(t8, offset); // offset 0; 0xef080000 (t8 register)
4532 __ mov(v0, t8);
4533
4534 // 256k instructions; 2^8k
4535 // addiu a4, a4, 0x0000; (0x25080000)
4536 // ...
4537 // addiu a7, a4, 0xffff; (0x250bffff)
4538 uint32_t addiu_start_2 = 0x25000000;
4539 for (int32_t i = 0x80000; i <= 0xbffff; ++i) {
4540 uint32_t addiu_new = addiu_start_2 + i;
4541 __ dd(addiu_new);
4542 }
4543
4544 __ jr(ra);
4545 __ nop();
4546
4547 CodeDesc desc;
4548 assm.GetCode(&desc);
4549 Handle<Code> code = isolate->factory()->NewCode(
4550 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
4551
4552 F2 f = FUNCTION_CAST<F2>(code->entry());
4553
4554 uint32_t res =
4555 reinterpret_cast<uint32_t>(CALL_GENERATED_CODE(f, rs, offset, 0, 0, 0));
4556
4557 return res;
4558 }
4559
4560
4561 TEST(r6_lwpc) {
4562 if (IsMipsArchVariant(kMips32r6)) {
4563 CcTest::InitializeVM();
4564
4565 struct TestCaseLwpc {
4566 int rs;
4567 int offset;
4568 uint32_t expected_rs;
4569 };
4570
4571 struct TestCaseLwpc tc[] = {
4572 // rs, offset, expected_rs_value
4573 { t8.code(), -262144, 0x250fffff }, // offset 0x40000
paul.l... 2015/06/11 05:56:31 I do not see the point of having 'rs' parameter in
ilija.pavlovic 2015/06/12 09:51:33 I tried to mimic (or follow) the format "LWPC rs,
4574 { t8.code(), -4, 0x250c0003 },
4575 { t8.code(), -1, 0x250c0000 },
4576 { t8.code(), 0, 0xef080000 },
4577 { t8.code(), 1, 0x03001025 }, // mov(v0, t8)
4578 { t8.code(), 2, 0x25080000 },
4579 { t8.code(), 4, 0x25080002 },
4580 { t8.code(), 262143, 0x250bfffd }, // offset 0x3ffff
4581 };
4582
4583 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseLwpc);
4584 for (size_t i = 0; i < nr_test_cases; ++i) {
4585 uint32_t res = run_lwpc(tc[i].rs, tc[i].offset);
4586 CHECK_EQ(tc[i].expected_rs, res);
4587 }
4588 }
4589 }
4590
4591
4592 uint32_t run_jic(int rt, int16_t offset) {
4593 Isolate* isolate = CcTest::i_isolate();
4594 HandleScope scope(isolate);
4595
4596 MacroAssembler assm(isolate, NULL, 0);
4597
4598 Label get_program_counter, stop_execution;
4599 __ push(ra);
4600 __ li(v0, 0);
4601 __ li(t1, 0x66);
4602
4603 __ addiu(v0, v0, 0x1); // <-- offset = -32
4604 __ addiu(v0, v0, 0x2);
4605 __ addiu(v0, v0, 0x10);
4606 __ addiu(v0, v0, 0x20);
4607 __ beq(v0, t1, &stop_execution);
4608 __ nop();
4609
4610 __ bal(&get_program_counter); // t0 <- program counter
4611 __ nop();
4612 __ jic(t0, offset); // JIC rt, offset
4613
4614 __ addiu(v0, v0, 0x100);
4615 __ addiu(v0, v0, 0x200);
4616 __ addiu(v0, v0, 0x1000);
4617 __ addiu(v0, v0, 0x2000); // <--- offset = 16
4618 __ pop(ra);
4619 __ jr(ra);
4620 __ nop();
4621
4622 __ bind(&get_program_counter);
4623 __ mov(t0, ra);
4624 __ jr(ra);
4625 __ nop();
4626
4627 __ bind(&stop_execution);
4628 __ pop(ra);
4629 __ jr(ra);
4630 __ nop();
4631
4632 CodeDesc desc;
4633 assm.GetCode(&desc);
4634 Handle<Code> code = isolate->factory()->NewCode(
4635 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
4636
4637 F2 f = FUNCTION_CAST<F2>(code->entry());
4638
4639 uint32_t res =
4640 reinterpret_cast<uint32_t>(CALL_GENERATED_CODE(f, rt, offset, 0, 0, 0));
4641
4642 return res;
4643 }
4644
4645
4646 TEST(r6_jic) {
4647 if (IsMipsArchVariant(kMips32r6)) {
4648 CcTest::InitializeVM();
4649
4650 struct TestCaseJic {
4651 uint32_t rt;
4652 int16_t offset;
4653 uint32_t expected_res;
4654 };
4655
4656 struct TestCaseJic tc[] = {
4657 // rt - formal argument; will contain value of the program counter
paul.l... 2015/06/11 05:56:32 the rt parameter in this table appears unused in r
ilija.pavlovic 2015/06/12 09:51:33 Similar explanation as for LWPC. rt is removed fro
4658 // rt offset, expected_result
4659 { 0, 16, 0x2033 },
4660 //{ 0, 0, 0x0 }, // JIC in loop
paul.l... 2015/06/11 05:56:32 Don't leave in the commented out case.
ilija.pavlovic 2015/06/12 09:51:33 The line is deleted. Done.
4661 { 0, 4, 0x3333 },
4662 { 0, -32, 0x66 },
4663 };
4664
4665 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseJic);
4666 for (size_t i = 0; i < nr_test_cases; ++i) {
4667 uint32_t res = run_jic(tc[i].rt, tc[i].offset);
4668 CHECK_EQ(tc[i].expected_res, res);
4669 }
4670 }
4671 }
4672
4673
4674 uint64_t run_beqzc(int32_t rs, int32_t offset) {
4675 Isolate* isolate = CcTest::i_isolate();
4676 HandleScope scope(isolate);
4677
4678 MacroAssembler assm(isolate, NULL, 0);
4679
4680 Label stop_execution;
4681 __ li(v0, 0);
4682 __ li(t1, 0x66);
4683 __ push(ra);
4684
4685 __ addiu(v0, v0, 0x1); // <-- offset = -32
4686 __ addiu(v0, v0, 0x2);
4687 __ addiu(v0, v0, 0x10);
4688 __ addiu(v0, v0, 0x20);
4689 __ beq(v0, t1, &stop_execution);
4690 __ nop();
4691
4692 __ beqzc(a0, offset); // BEQZC rs, offset
4693
4694 __ addiu(v0, v0, 0x1);
4695 __ addiu(v0, v0, 0x100);
4696 __ addiu(v0, v0, 0x200);
4697 __ addiu(v0, v0, 0x1000);
4698 __ addiu(v0, v0, 0x2000); // <--- offset = 16
4699 __ jr(ra);
4700 __ nop();
4701
4702 __ bind(&stop_execution);
4703 __ pop(ra);
4704 __ jr(ra);
4705 __ nop();
4706
4707 CodeDesc desc;
4708 assm.GetCode(&desc);
4709 Handle<Code> code = isolate->factory()->NewCode(
4710 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
4711
4712 F2 f = FUNCTION_CAST<F2>(code->entry());
4713
4714 uint32_t res =
4715 reinterpret_cast<uint32_t>(CALL_GENERATED_CODE(f, rs, offset, 0, 0, 0));
4716
4717 return res;
4718 }
4719
4720
4721 TEST(r6_beqzc) {
4722 if (IsMipsArchVariant(kMips32r6)) {
4723 CcTest::InitializeVM();
4724
4725 struct TestCaseBeqzc {
4726 uint32_t rs;
paul.l... 2015/06/11 05:56:32 The 'rs' was confusing here, because the instructi
ilija.pavlovic 2015/06/12 09:51:33 The parameter 'rt' renamed into 'rt_value'. Done.
4727 int32_t offset;
4728 uint32_t expected_res;
4729 };
4730
4731 struct TestCaseBeqzc tc[] = {
4732 // rs, offset, expected_result
4733 { 0x0, -8, 0x66 },
4734 { 0x0, 0, 0x3334 },
4735 { 0x0, 1, 0x3333 },
4736 { 0xabc, 1, 0x3334 },
4737 { 0x0, 4, 0x2033 },
4738 };
4739
4740 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseBeqzc);
4741 for (size_t i = 0; i < nr_test_cases; ++i) {
4742 uint32_t res = run_beqzc(tc[i].rs, tc[i].offset);
4743 CHECK_EQ(tc[i].expected_res, res);
4744 }
4745 }
4746 }
4747
4748
4749 uint32_t run_jialc(int rt, int16_t offset) {
4750 Isolate* isolate = CcTest::i_isolate();
4751 HandleScope scope(isolate);
4752
4753 MacroAssembler assm(isolate, NULL, 0);
4754
4755 Label main_block, get_program_counter;
4756 __ push(ra);
4757 __ li(v0, 0);
4758 __ beq(v0, v0, &main_block);
4759 __ nop();
4760
4761 // Block 1
4762 __ addiu(v0, v0, 0x1); // <-- offset = -40
4763 __ addiu(v0, v0, 0x2);
4764 __ jr(ra);
4765 __ nop();
4766
4767 // Block 2
4768 __ addiu(v0, v0, 0x10); // <-- offset = -24
4769 __ addiu(v0, v0, 0x20);
4770 __ jr(ra);
4771 __ nop();
4772
4773 // Block 3 (Main)
4774 __ bind(&main_block);
4775 __ bal(&get_program_counter); // t0 <- program counter
4776 __ nop();
4777 __ jialc(t0, offset); // JIALC rt, offset
4778 __ addiu(v0, v0, 0x4);
4779 __ pop(ra);
4780 __ jr(ra);
4781 __ nop();
4782
4783 // Block 4
4784 __ addiu(v0, v0, 0x100); // <-- offset = 20
4785 __ addiu(v0, v0, 0x200);
4786 __ jr(ra);
4787 __ nop();
4788
4789 // Block 5
4790 __ addiu(v0, v0, 0x1000); // <--- offset = 36
4791 __ addiu(v0, v0, 0x2000);
4792 __ jr(ra);
4793 __ nop();
4794
4795 __ bind(&get_program_counter);
4796 __ mov(t0, ra);
4797 __ jr(ra);
4798 __ nop();
4799
4800
4801 CodeDesc desc;
4802 assm.GetCode(&desc);
4803 Handle<Code> code = isolate->factory()->NewCode(
4804 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
4805
4806 F2 f = FUNCTION_CAST<F2>(code->entry());
4807
4808 uint32_t res =
4809 reinterpret_cast<uint32_t>(CALL_GENERATED_CODE(f, rt, offset, 0, 0, 0));
4810
4811 return res;
4812 }
4813
4814
4815 TEST(r6_jialc) {
4816 if (IsMipsArchVariant(kMips32r6)) {
4817 CcTest::InitializeVM();
4818
4819 struct TestCaseJialc {
4820 uint32_t rt;
4821 int16_t offset;
4822 uint32_t expected_res;
4823 };
4824
4825 struct TestCaseJialc tc[] = {
4826 // rt - formal argument; will contain value of the program counter
paul.l... 2015/06/11 05:56:31 Again, rt is unused here, I suggest removing it fo
ilija.pavlovic 2015/06/12 09:51:33 Corrections performed similarly previous test case
4827 // rt, offset, expected_result
4828 { 0, -40, 0x7 },
4829 { 0, -24, 0x34 },
4830 { 0, 20, 0x304 },
4831 { 0, 36, 0x3004 }
4832 };
4833
4834 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseJialc);
4835 for (size_t i = 0; i < nr_test_cases; ++i) {
4836 uint32_t res = run_jialc(tc[i].rt, tc[i].offset);
4837 CHECK_EQ(tc[i].expected_res, res);
4838 }
4839 }
4840 }
4841
4842
4843 uint64_t run_addiupc(int32_t imm19) {
4844 Isolate* isolate = CcTest::i_isolate();
4845 HandleScope scope(isolate);
4846
4847 MacroAssembler assm(isolate, NULL, 0);
4848
4849 // ADDIUPC rs, imm19
4850 __ addiupc(v0, imm19);
4851 __ jr(ra);
4852 __ nop();
4853
4854 CodeDesc desc;
4855 assm.GetCode(&desc);
4856 Handle<Code> code = isolate->factory()->NewCode(
4857 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
4858
4859 F2 f = FUNCTION_CAST<F2>(code->entry());
4860 PC = (uint32_t) f; // set program counter
4861
4862 uint32_t rs =
4863 reinterpret_cast<uint32_t>(CALL_GENERATED_CODE(f, imm19, 0, 0, 0, 0));
4864
4865 return rs;
4866 }
4867
4868
4869 TEST(r6_addiupc) {
4870 if (IsMipsArchVariant(kMips32r6)) {
4871 CcTest::InitializeVM();
4872
4873 struct TestCaseAddiupc {
4874 uint32_t rs_expected;
4875 int32_t imm19;
4876 };
4877
4878 struct TestCaseAddiupc tc[] = {
4879 // rs_expected - formal argument; will be calculated later
4880 // rs_expected, imm19
4881 { 0x0, -262144 }, // 0x40000
4882 { 0x0, -1 }, // 0x7FFFF
4883 { 0x0, 0 },
4884 { 0x0, 1 }, // 0x00001
4885 { 0x0, 262143 } // 0x3FFFF
4886 };
4887
4888 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseAddiupc);
4889 for (size_t i = 0; i < nr_test_cases; ++i) {
4890 PC = 0;
4891 uint32_t rs = run_addiupc(tc[i].imm19);
4892 // Now, the program_counter (PC) is set
4893 uint32_t rs_expected = PC + (tc[i].imm19 << 2);
4894 CHECK_EQ(rs_expected, rs);
4895 }
4896 }
4897 }
4898
4899
4900 int32_t run_bc(int32_t offset) {
4901 Isolate* isolate = CcTest::i_isolate();
4902 HandleScope scope(isolate);
4903
4904 MacroAssembler assm(isolate, NULL, 0);
4905
4906 Label continue_1, stop_execution;
4907 __ push(ra);
4908 __ li(v0, 0);
4909 __ li(t8, 0);
4910 __ li(t9, 2); // condition for the stopping execution
4911
4912 uint32_t instruction_addiu = 0x24420001; // addiu v0, v0, 1
4913 for (int32_t i = -100; i <= -11; ++i) {
paul.l... 2015/06/11 05:56:32 In my earlier test code for bc & balc I generated
ilija.pavlovic 2015/06/12 09:51:33 Actually, in the first version this test case had
4914 __ dd(instruction_addiu);
4915 }
4916
4917 __ addiu(t8, t8, 1); // -10
4918
4919 __ beq(t8, t9, &stop_execution); // -9
4920 __ nop(); // -8
4921 __ beq(t8, t8, &continue_1); // -7
4922 __ nop(); // -6
4923
4924 __ bind(&stop_execution);
4925 __ pop(ra); // -5, -4
4926 __ jr(ra); // -3
4927 __ nop(); // -2
4928
4929 __ bind(&continue_1);
4930 __ bc(offset); // -1
4931
4932 for (int32_t i = 0; i <= 99; ++i) {
4933 __ dd(instruction_addiu);
4934 }
4935
4936 __ pop(ra);
4937 __ jr(ra);
4938 __ nop();
4939
4940 CodeDesc desc;
4941 assm.GetCode(&desc);
4942 Handle<Code> code = isolate->factory()->NewCode(
4943 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
4944
4945 F2 f = FUNCTION_CAST<F2>(code->entry());
4946
4947 int32_t res =
4948 reinterpret_cast<int32_t>(CALL_GENERATED_CODE(f, offset, 0, 0, 0, 0));
4949
4950 return res;
4951 }
4952
4953
4954 TEST(r6_bc) {
4955 if (IsMipsArchVariant(kMips32r6)) {
4956 CcTest::InitializeVM();
4957
4958 struct TestCaseBc {
4959 int32_t offset;
4960 int32_t expected_res;
4961 };
4962
4963 struct TestCaseBc tc[] = {
4964 // offset, expected_result
4965 { -100, (abs(-100) - 10) * 2 },
4966 { -11, (abs(-100) - 10 + 1) },
4967 { 0, (abs(-100) - 10 + 1 + 99) },
4968 { 1, (abs(-100) - 10 + 99) },
4969 { 99, (abs(-100) - 10 + 1) },
4970 };
4971
4972 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseBc);
4973 for (size_t i = 0; i < nr_test_cases; ++i) {
4974 int32_t res = run_bc(tc[i].offset);
4975 CHECK_EQ(tc[i].expected_res, res);
4976 }
4977 }
4978 }
4979
4980
4981 int32_t run_balc(int32_t offset) {
4982 Isolate* isolate = CcTest::i_isolate();
4983 HandleScope scope(isolate);
4984
4985 MacroAssembler assm(isolate, NULL, 0);
4986
4987 Label continue_1, stop_execution;
4988 __ push(ra);
4989 __ li(v0, 0);
4990 __ li(t8, 0);
4991 __ li(t9, 2); // condition for stopping execution
4992
4993 __ beq(t8, t8, &continue_1);
4994 __ nop();
4995
4996 uint32_t instruction_addiu = 0x24420001; // addiu v0, v0, 1
4997 for (int32_t i = -117; i <= -57; ++i) {
4998 __ dd(instruction_addiu);
4999 }
5000 __ jr(ra); // -56
5001 __ nop(); // -55
5002
5003 for (int32_t i = -54; i <= -4; ++i) {
5004 __ dd(instruction_addiu);
5005 }
5006 __ jr(ra); // -3
5007 __ nop(); // -2
5008
5009 __ bind(&continue_1);
5010 __ balc(offset); // -1
5011
5012 __ pop(ra); // 0, 1
5013 __ jr(ra); // 2
5014 __ nop(); // 3
5015
5016 for (int32_t i = 4; i <= 44; ++i) {
5017 __ dd(instruction_addiu);
5018 }
5019 __ jr(ra);
5020 __ nop();
5021
5022 CodeDesc desc;
5023 assm.GetCode(&desc);
5024 Handle<Code> code = isolate->factory()->NewCode(
5025 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
5026
5027 F2 f = FUNCTION_CAST<F2>(code->entry());
5028
5029 int32_t res =
5030 reinterpret_cast<int32_t>(CALL_GENERATED_CODE(f, offset, 0, 0, 0, 0));
5031
5032 return res;
5033 }
5034
5035
5036 TEST(r6_balc) {
5037 if (IsMipsArchVariant(kMips32r6)) {
5038 CcTest::InitializeVM();
5039
5040 struct TestCaseBalc {
5041 int32_t offset;
5042 int32_t expected_res;
5043 };
5044
5045 struct TestCaseBalc tc[] = {
5046 // offset, expected_result
5047 { -117, 61 },
5048 { -54, 51 },
5049 { 0, 0 },
5050 { 4, 41 },
5051 };
5052
5053 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseBalc);
5054 for (size_t i = 0; i < nr_test_cases; ++i) {
5055 int32_t res = run_balc(tc[i].offset);
5056 CHECK_EQ(tc[i].expected_res, res);
5057 }
5058 }
5059 }
5060
5061
4346 #undef __ 5062 #undef __
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698