OLD | NEW |
---|---|
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 5368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5379 assm.GetCode(&desc); | 5379 assm.GetCode(&desc); |
5380 Handle<Code> code = isolate->factory()->NewCode( | 5380 Handle<Code> code = isolate->factory()->NewCode( |
5381 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | 5381 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
5382 F2 f = FUNCTION_CAST<F2>(code->entry()); | 5382 F2 f = FUNCTION_CAST<F2>(code->entry()); |
5383 | 5383 |
5384 int32_t res = reinterpret_cast<int32_t>( | 5384 int32_t res = reinterpret_cast<int32_t>( |
5385 CALL_GENERATED_CODE(isolate, f, 42, 42, 0, 0, 0)); | 5385 CALL_GENERATED_CODE(isolate, f, 42, 42, 0, 0, 0)); |
5386 CHECK_EQ(res, 0); | 5386 CHECK_EQ(res, 0); |
5387 } | 5387 } |
5388 | 5388 |
5389 TEST(madd_s_msub_s) { | |
5390 if (IsMipsArchVariant(kMips32r2)) { | |
balazs.kilvady
2016/09/07 18:32:47
In this kind of cases I prefer if (!cond) return;
Ilija.Pavlovic1
2016/09/09 12:35:18
The test is made as template so the logic (and che
| |
5391 CcTest::InitializeVM(); | |
5392 Isolate* isolate = CcTest::i_isolate(); | |
5393 HandleScope scope(isolate); | |
5394 MacroAssembler assm(isolate, NULL, 0, | |
5395 v8::internal::CodeObjectRequired::kYes); | |
5396 | |
5397 struct TestCase { | |
5398 float fr, fs, ft, fd_add, fd_sub; | |
5399 }; | |
5400 | |
balazs.kilvady
2016/09/07 18:32:47
If you use the same test values for all the 4 vari
Ilija.Pavlovic1
2016/09/09 12:35:18
Used std::sqrt().
Done.
| |
5401 float x = sqrtf(2.0); | |
5402 float y = sqrtf(3.0); | |
5403 float z = sqrtf(5.0); | |
5404 float x2 = 11.11, y2 = 22.22, z2 = 33.33; | |
5405 TestCase test_cases[] = { | |
5406 {x, y, z, 0.0, 0.0}, | |
5407 {x, y, -z, 0.0, 0.0}, | |
5408 {x, -y, z, 0.0, 0.0}, | |
5409 {x, -y, -z, 0.0, 0.0}, | |
5410 {-x, y, z, 0.0, 0.0}, | |
5411 {-x, y, -z, 0.0, 0.0}, | |
5412 {-x, -y, z, 0.0, 0.0}, | |
5413 {-x, -y, -z, 0.0, 0.0}, | |
5414 {-3.14, 0.2345, -123.000056, 0.0, 0.0}, | |
5415 {7.3, -23.257, -357.1357, 0.0, 0.0}, | |
5416 {x2, y2, z2, 0.0, 0.0}, | |
5417 {x2, y2, -z2, 0.0, 0.0}, | |
5418 {x2, -y2, z2, 0.0, 0.0}, | |
5419 {x2, -y2, -z2, 0.0, 0.0}, | |
5420 {-x2, y2, z2, 0.0, 0.0}, | |
5421 {-x2, y2, -z2, 0.0, 0.0}, | |
5422 {-x2, -y2, z2, 0.0, 0.0}, | |
5423 {-x2, -y2, -z2, 0.0, 0.0}, | |
5424 }; | |
5425 | |
5426 __ lwc1(f4, MemOperand(a0, offsetof(TestCase, fr))); | |
5427 __ lwc1(f6, MemOperand(a0, offsetof(TestCase, fs))); | |
5428 __ lwc1(f8, MemOperand(a0, offsetof(TestCase, ft))); | |
5429 __ lwc1(f16, MemOperand(a0, offsetof(TestCase, fr))); | |
5430 | |
5431 __ madd_s(f10, f4, f6, f8); | |
5432 __ swc1(f10, MemOperand(a0, offsetof(TestCase, fd_add))); | |
5433 __ msub_s(f16, f4, f6, f8); | |
5434 __ swc1(f16, MemOperand(a0, offsetof(TestCase, fd_sub))); | |
5435 | |
5436 __ jr(ra); | |
5437 __ nop(); | |
5438 | |
5439 CodeDesc desc; | |
5440 assm.GetCode(&desc); | |
5441 Handle<Code> code = isolate->factory()->NewCode( | |
5442 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | |
5443 F3 f = FUNCTION_CAST<F3>(code->entry()); | |
5444 | |
5445 const size_t kTableLength = sizeof(test_cases) / sizeof(TestCase); | |
5446 TestCase tc; | |
5447 for (size_t i = 0; i < kTableLength; i++) { | |
5448 tc.fr = test_cases[i].fr; | |
5449 tc.fs = test_cases[i].fs; | |
5450 tc.ft = test_cases[i].ft; | |
5451 | |
5452 (CALL_GENERATED_CODE(isolate, f, &tc, 0, 0, 0, 0)); | |
5453 | |
5454 float res_add = tc.fr + (tc.fs * tc.ft); | |
5455 float res_sub = (tc.fs * tc.ft) - tc.fr; | |
5456 | |
5457 CHECK_EQ(tc.fd_add, res_add); | |
5458 CHECK_EQ(tc.fd_sub, res_sub); | |
5459 } | |
5460 } | |
5461 } | |
5462 | |
5463 TEST(maddf_s_msubf_s) { | |
5464 if (IsMipsArchVariant(kMips32r6)) { | |
5465 CcTest::InitializeVM(); | |
5466 Isolate* isolate = CcTest::i_isolate(); | |
5467 HandleScope scope(isolate); | |
5468 MacroAssembler assm(isolate, NULL, 0, | |
5469 v8::internal::CodeObjectRequired::kYes); | |
5470 | |
5471 struct TestCase { | |
5472 float fr, fs, ft, fd_add, fd_sub; | |
5473 }; | |
5474 | |
5475 float x = sqrtf(2.0); | |
5476 float y = sqrtf(3.0); | |
5477 float z = sqrtf(5.0); | |
5478 float x2 = 11.11, y2 = 22.22, z2 = 33.33; | |
5479 TestCase test_cases[] = { | |
5480 {x, y, z, 0.0, 0.0}, | |
5481 {x, y, -z, 0.0, 0.0}, | |
5482 {x, -y, z, 0.0, 0.0}, | |
5483 {x, -y, -z, 0.0, 0.0}, | |
5484 {-x, y, z, 0.0, 0.0}, | |
5485 {-x, y, -z, 0.0, 0.0}, | |
5486 {-x, -y, z, 0.0, 0.0}, | |
5487 {-x, -y, -z, 0.0, 0.0}, | |
5488 {-3.14, 0.2345, -123.000056, 0.0, 0.0}, | |
5489 {7.3, -23.257, -357.1357, 0.0, 0.0}, | |
5490 {x2, y2, z2, 0.0, 0.0}, | |
5491 {x2, y2, -z2, 0.0, 0.0}, | |
5492 {x2, -y2, z2, 0.0, 0.0}, | |
5493 {x2, -y2, -z2, 0.0, 0.0}, | |
5494 {-x2, y2, z2, 0.0, 0.0}, | |
5495 {-x2, y2, -z2, 0.0, 0.0}, | |
5496 {-x2, -y2, z2, 0.0, 0.0}, | |
5497 {-x2, -y2, -z2, 0.0, 0.0}, | |
5498 }; | |
5499 | |
5500 __ lwc1(f4, MemOperand(a0, offsetof(TestCase, fr))); | |
5501 __ lwc1(f6, MemOperand(a0, offsetof(TestCase, fs))); | |
5502 __ lwc1(f8, MemOperand(a0, offsetof(TestCase, ft))); | |
5503 __ lwc1(f16, MemOperand(a0, offsetof(TestCase, fr))); | |
5504 | |
5505 __ maddf_s(f4, f6, f8); | |
5506 __ swc1(f4, MemOperand(a0, offsetof(TestCase, fd_add))); | |
5507 __ msubf_s(f16, f6, f8); | |
5508 __ swc1(f16, MemOperand(a0, offsetof(TestCase, fd_sub))); | |
5509 | |
5510 __ jr(ra); | |
5511 __ nop(); | |
5512 | |
5513 CodeDesc desc; | |
5514 assm.GetCode(&desc); | |
5515 Handle<Code> code = isolate->factory()->NewCode( | |
5516 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | |
5517 F3 f = FUNCTION_CAST<F3>(code->entry()); | |
5518 | |
5519 const size_t kTableLength = sizeof(test_cases) / sizeof(TestCase); | |
5520 TestCase tc; | |
5521 for (size_t i = 0; i < kTableLength; i++) { | |
5522 tc.fr = test_cases[i].fr; | |
5523 tc.fs = test_cases[i].fs; | |
5524 tc.ft = test_cases[i].ft; | |
5525 | |
5526 (CALL_GENERATED_CODE(isolate, f, &tc, 0, 0, 0, 0)); | |
5527 | |
5528 float res_add = tc.fr + (tc.fs * tc.ft); | |
5529 float res_sub = tc.fr - (tc.fs * tc.ft); | |
balazs.kilvady
2016/09/07 18:32:47
Looks good, but could you check the compiled code
Ilija.Pavlovic1
2016/09/09 12:35:18
The test is now template.
The formula is used for
| |
5530 CHECK_EQ(tc.fd_add, res_add); | |
5531 CHECK_EQ(tc.fd_sub, res_sub); | |
5532 } | |
5533 } | |
5534 } | |
5535 | |
5536 TEST(madd_d_msub_d) { | |
5537 if (IsMipsArchVariant(kMips32r2)) { | |
5538 CcTest::InitializeVM(); | |
5539 Isolate* isolate = CcTest::i_isolate(); | |
5540 HandleScope scope(isolate); | |
5541 MacroAssembler assm(isolate, NULL, 0, | |
5542 v8::internal::CodeObjectRequired::kYes); | |
5543 | |
5544 struct TestCase { | |
5545 double fr, fs, ft, fd_add, fd_sub; | |
5546 }; | |
5547 | |
5548 double x = sqrt(2.0); | |
5549 double y = sqrt(3.0); | |
5550 double z = sqrt(5.0); | |
5551 double x2 = 11.11, y2 = 22.22, z2 = 33.33; | |
5552 TestCase test_cases[] = { | |
5553 {x, y, z, 0.0, 0.0}, | |
5554 {x, y, -z, 0.0, 0.0}, | |
5555 {x, -y, z, 0.0, 0.0}, | |
5556 {x, -y, -z, 0.0, 0.0}, | |
5557 {-x, y, z, 0.0, 0.0}, | |
5558 {-x, y, -z, 0.0, 0.0}, | |
5559 {-x, -y, z, 0.0, 0.0}, | |
5560 {-x, -y, -z, 0.0, 0.0}, | |
5561 {-3.14, 0.2345, -123.000056, 0.0, 0.0}, | |
5562 {7.3, -23.257, -357.1357, 0.0, 0.0}, | |
5563 {x2, y2, z2, 0.0, 0.0}, | |
5564 {x2, y2, -z2, 0.0, 0.0}, | |
5565 {x2, -y2, z2, 0.0, 0.0}, | |
5566 {x2, -y2, -z2, 0.0, 0.0}, | |
5567 {-x2, y2, z2, 0.0, 0.0}, | |
5568 {-x2, y2, -z2, 0.0, 0.0}, | |
5569 {-x2, -y2, z2, 0.0, 0.0}, | |
5570 {-x2, -y2, -z2, 0.0, 0.0}, | |
5571 }; | |
5572 | |
5573 __ ldc1(f4, MemOperand(a0, offsetof(TestCase, fr))); | |
5574 __ ldc1(f6, MemOperand(a0, offsetof(TestCase, fs))); | |
5575 __ ldc1(f8, MemOperand(a0, offsetof(TestCase, ft))); | |
5576 __ ldc1(f16, MemOperand(a0, offsetof(TestCase, fr))); | |
5577 | |
5578 __ madd_d(f10, f4, f6, f8); | |
5579 __ sdc1(f10, MemOperand(a0, offsetof(TestCase, fd_add))); | |
5580 __ msub_d(f16, f4, f6, f8); | |
5581 __ sdc1(f16, MemOperand(a0, offsetof(TestCase, fd_sub))); | |
5582 | |
5583 __ jr(ra); | |
5584 __ nop(); | |
5585 | |
5586 CodeDesc desc; | |
5587 assm.GetCode(&desc); | |
5588 Handle<Code> code = isolate->factory()->NewCode( | |
5589 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | |
5590 F3 f = FUNCTION_CAST<F3>(code->entry()); | |
5591 | |
5592 const size_t kTableLength = sizeof(test_cases) / sizeof(TestCase); | |
5593 TestCase tc; | |
5594 for (size_t i = 0; i < kTableLength; i++) { | |
5595 tc.fr = test_cases[i].fr; | |
5596 tc.fs = test_cases[i].fs; | |
5597 tc.ft = test_cases[i].ft; | |
5598 | |
5599 (CALL_GENERATED_CODE(isolate, f, &tc, 0, 0, 0, 0)); | |
5600 | |
5601 double res_add = tc.fr + (tc.fs * tc.ft); | |
5602 double res_sub = (tc.fs * tc.ft) - tc.fr; | |
5603 CHECK_EQ(tc.fd_add, res_add); | |
5604 CHECK_EQ(tc.fd_sub, res_sub); | |
5605 } | |
5606 } | |
5607 } | |
5608 | |
5609 TEST(maddf_d_msubf_d) { | |
5610 if (IsMipsArchVariant(kMips32r6)) { | |
5611 CcTest::InitializeVM(); | |
5612 Isolate* isolate = CcTest::i_isolate(); | |
5613 HandleScope scope(isolate); | |
5614 MacroAssembler assm(isolate, NULL, 0, | |
5615 v8::internal::CodeObjectRequired::kYes); | |
5616 | |
5617 struct TestCase { | |
5618 double fr, fs, ft, fd_add, fd_sub; | |
5619 }; | |
5620 | |
5621 double x = sqrt(2.0); | |
5622 double y = sqrt(3.0); | |
5623 double z = sqrt(5.0); | |
5624 double x2 = 11.11, y2 = 22.22, z2 = 33.33; | |
5625 TestCase test_cases[] = { | |
5626 {x, y, z, 0.0, 0.0}, | |
5627 {x, y, -z, 0.0, 0.0}, | |
5628 {x, -y, z, 0.0, 0.0}, | |
5629 {x, -y, -z, 0.0, 0.0}, | |
5630 {-x, y, z, 0.0, 0.0}, | |
5631 {-x, y, -z, 0.0, 0.0}, | |
5632 {-x, -y, z, 0.0, 0.0}, | |
5633 {-x, -y, -z, 0.0, 0.0}, | |
5634 {-3.14, 0.2345, -123.000056, 0.0, 0.0}, | |
5635 {7.3, -23.257, -357.1357, 0.0, 0.0}, | |
5636 {x2, y2, z2, 0.0, 0.0}, | |
5637 {x2, y2, -z2, 0.0, 0.0}, | |
5638 {x2, -y2, z2, 0.0, 0.0}, | |
5639 {x2, -y2, -z2, 0.0, 0.0}, | |
5640 {-x2, y2, z2, 0.0, 0.0}, | |
5641 {-x2, y2, -z2, 0.0, 0.0}, | |
5642 {-x2, -y2, z2, 0.0, 0.0}, | |
5643 {-x2, -y2, -z2, 0.0, 0.0}, | |
5644 }; | |
5645 | |
5646 __ ldc1(f4, MemOperand(a0, offsetof(TestCase, fr))); | |
5647 __ ldc1(f6, MemOperand(a0, offsetof(TestCase, fs))); | |
5648 __ ldc1(f8, MemOperand(a0, offsetof(TestCase, ft))); | |
5649 __ ldc1(f16, MemOperand(a0, offsetof(TestCase, fr))); | |
5650 | |
5651 __ maddf_d(f4, f6, f8); | |
5652 __ sdc1(f4, MemOperand(a0, offsetof(TestCase, fd_add))); | |
5653 __ msubf_d(f16, f6, f8); | |
5654 __ sdc1(f16, MemOperand(a0, offsetof(TestCase, fd_sub))); | |
5655 | |
5656 __ jr(ra); | |
5657 __ nop(); | |
5658 | |
5659 CodeDesc desc; | |
5660 assm.GetCode(&desc); | |
5661 Handle<Code> code = isolate->factory()->NewCode( | |
5662 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | |
5663 F3 f = FUNCTION_CAST<F3>(code->entry()); | |
5664 | |
5665 const size_t kTableLength = sizeof(test_cases) / sizeof(TestCase); | |
5666 TestCase tc; | |
5667 for (size_t i = 0; i < kTableLength; i++) { | |
5668 tc.fr = test_cases[i].fr; | |
5669 tc.fs = test_cases[i].fs; | |
5670 tc.ft = test_cases[i].ft; | |
5671 | |
5672 (CALL_GENERATED_CODE(isolate, f, &tc, 0, 0, 0, 0)); | |
5673 | |
5674 double res_add = tc.fr + (tc.fs * tc.ft); | |
5675 double res_sub = tc.fr - (tc.fs * tc.ft); | |
5676 CHECK_EQ(tc.fd_add, res_add); | |
5677 CHECK_EQ(tc.fd_sub, res_sub); | |
5678 } | |
5679 } | |
5680 } | |
5681 | |
5389 #undef __ | 5682 #undef __ |
OLD | NEW |