Chromium Code Reviews| 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 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 515 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseLsa); | 515 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseLsa); |
| 516 for (size_t i = 0; i < nr_test_cases; ++i) { | 516 for (size_t i = 0; i < nr_test_cases; ++i) { |
| 517 uint64_t res = run_dlsa(tc[i].rt, tc[i].rs, tc[i].sa); | 517 uint64_t res = run_dlsa(tc[i].rt, tc[i].rs, tc[i].sa); |
| 518 PrintF("0x%" PRIx64 " =? 0x%" PRIx64 " == Dlsa(v0, %" PRIx64 ", %" PRIx64 | 518 PrintF("0x%" PRIx64 " =? 0x%" PRIx64 " == Dlsa(v0, %" PRIx64 ", %" PRIx64 |
| 519 ", %hhu)\n", | 519 ", %hhu)\n", |
| 520 tc[i].expected_res, res, tc[i].rt, tc[i].rs, tc[i].sa); | 520 tc[i].expected_res, res, tc[i].rt, tc[i].rs, tc[i].sa); |
| 521 CHECK_EQ(tc[i].expected_res, res); | 521 CHECK_EQ(tc[i].expected_res, res); |
| 522 } | 522 } |
| 523 } | 523 } |
| 524 | 524 |
| 525 static const std::vector<uint32_t> uint32_test_values() { | |
|
ivica.bogosavljevic
2016/03/04 16:28:28
should be renamed to cvt_test_values or similar, s
Ilija.Pavlovic1
2016/03/07 08:21:07
The model for this form of input values is similar
Ilija.Pavlovic1
2016/03/07 08:21:07
The model for this form of input values is similar
Ilija.Pavlovic1
2016/03/07 08:21:07
Acknowledged.
| |
| 526 static const uint32_t kValues[] = {0x00000000, 0x00000001, 0x00ffff00, | |
| 527 0x7fffffff, 0x80000000, 0x80000001, | |
| 528 0x80ffff00, 0x8fffffff, 0xffffffff}; | |
| 529 return std::vector<uint32_t>(&kValues[0], &kValues[arraysize(kValues)]); | |
| 530 } | |
| 531 | |
| 532 static const std::vector<uint64_t> uint64_test_values() { | |
|
ivica.bogosavljevic
2016/03/04 16:28:28
Same as above
Ilija.Pavlovic1
2016/03/07 08:21:07
Acknowledged.
See previous comment.
| |
| 533 static const uint64_t kValues[] = { | |
| 534 0x0000000000000000, 0x0000000000000001, 0x0000ffffffff0000, | |
| 535 0x7fffffffffffffff, 0x8000000000000000, 0x8000000000000001, | |
| 536 0x8000ffffffff0000, 0x8fffffffffffffff, 0xffffffffffffffff}; | |
| 537 return std::vector<uint64_t>(&kValues[0], &kValues[arraysize(kValues)]); | |
| 538 } | |
| 539 | |
| 540 // Helper macros that can be used in FOR_INT32_INPUTS(i) { ... *i ... } | |
| 541 #define FOR_INPUTS(ctype, itype, var) \ | |
| 542 std::vector<ctype> var##_vec = itype##_test_values(); \ | |
| 543 for (std::vector<ctype>::iterator var = var##_vec.begin(); \ | |
| 544 var != var##_vec.end(); ++var) | |
| 545 | |
| 546 #define FOR_UINT32_INPUTS(var) FOR_INPUTS(uint32_t, uint32, var) | |
| 547 #define FOR_UINT64_INPUTS(var) FOR_INPUTS(uint64_t, uint64, var) | |
| 548 | |
| 549 template <typename RET_TYPE, typename IN_TYPE, typename Func> | |
| 550 RET_TYPE run_Cvt(IN_TYPE x, Func GenerateConvertInstructionFunc) { | |
|
ivica.bogosavljevic
2016/03/04 16:28:28
Very interesting. Leaner code, although more diffi
Ilija.Pavlovic1
2016/03/07 08:21:07
Acknowledged.
| |
| 551 typedef RET_TYPE (*F_CVT)(IN_TYPE x0, int x1, int x2, int x3, int x4); | |
| 552 | |
| 553 Isolate* isolate = CcTest::i_isolate(); | |
| 554 HandleScope scope(isolate); | |
| 555 MacroAssembler assm(isolate, nullptr, 0, | |
| 556 v8::internal::CodeObjectRequired::kYes); | |
| 557 MacroAssembler* masm = &assm; | |
| 558 | |
| 559 GenerateConvertInstructionFunc(masm); | |
| 560 __ jr(ra); | |
| 561 __ nop(); | |
| 562 | |
| 563 CodeDesc desc; | |
| 564 assm.GetCode(&desc); | |
| 565 Handle<Code> code = isolate->factory()->NewCode( | |
| 566 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | |
| 567 | |
| 568 F_CVT f = FUNCTION_CAST<F_CVT>(code->entry()); | |
| 569 | |
| 570 return CALL_GENERATED_CODE(isolate, f, x, 0, 0, 0, 0); | |
| 571 } | |
| 572 | |
| 573 TEST(Cvt_s_uw) { | |
| 574 CcTest::InitializeVM(); | |
| 575 FOR_UINT32_INPUTS(i) { | |
| 576 uint32_t input = *i; | |
| 577 CHECK_EQ(static_cast<float>(input), | |
| 578 run_Cvt<float>( | |
| 579 input, [](MacroAssembler* masm) { masm->Cvt_s_uw(f0, a0); })); | |
| 580 } | |
| 581 } | |
| 582 | |
| 583 TEST(Cvt_s_ul) { | |
| 584 CcTest::InitializeVM(); | |
| 585 FOR_UINT64_INPUTS(i) { | |
| 586 uint64_t input = *i; | |
| 587 CHECK_EQ(static_cast<float>(input), | |
| 588 run_Cvt<float>( | |
| 589 input, [](MacroAssembler* masm) { masm->Cvt_s_ul(f0, a0); })); | |
| 590 } | |
| 591 } | |
| 592 | |
| 593 TEST(Cvt_d_ul) { | |
| 594 CcTest::InitializeVM(); | |
| 595 FOR_UINT64_INPUTS(i) { | |
| 596 uint64_t input = *i; | |
| 597 CHECK_EQ(static_cast<double>(input), | |
| 598 run_Cvt<double>( | |
| 599 input, [](MacroAssembler* masm) { masm->Cvt_d_ul(f0, a0); })); | |
| 600 } | |
| 601 } | |
| 602 | |
| 525 #undef __ | 603 #undef __ |
| OLD | NEW |