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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 | 382 |
383 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseLsa); | 383 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseLsa); |
384 for (size_t i = 0; i < nr_test_cases; ++i) { | 384 for (size_t i = 0; i < nr_test_cases; ++i) { |
385 uint32_t res = run_lsa(tc[i].rt, tc[i].rs, tc[i].sa); | 385 uint32_t res = run_lsa(tc[i].rt, tc[i].rs, tc[i].sa); |
386 PrintF("0x%x =? 0x%x == lsa(v0, %x, %x, %hhu)\n", tc[i].expected_res, res, | 386 PrintF("0x%x =? 0x%x == lsa(v0, %x, %x, %hhu)\n", tc[i].expected_res, res, |
387 tc[i].rt, tc[i].rs, tc[i].sa); | 387 tc[i].rt, tc[i].rs, tc[i].sa); |
388 CHECK_EQ(tc[i].expected_res, res); | 388 CHECK_EQ(tc[i].expected_res, res); |
389 } | 389 } |
390 } | 390 } |
391 | 391 |
392 static const std::vector<uint32_t> uint32_test_values() { | 392 static const std::vector<uint32_t> cvt_trunc_uint32_test_values() { |
393 static const uint32_t kValues[] = {0x00000000, 0x00000001, 0x00ffff00, | 393 static const uint32_t kValues[] = {0x00000000, 0x00000001, 0x00ffff00, |
394 0x7fffffff, 0x80000000, 0x80000001, | 394 0x7fffffff, 0x80000000, 0x80000001, |
395 0x80ffff00, 0x8fffffff, 0xffffffff}; | 395 0x80ffff00, 0x8fffffff, 0xffffffff}; |
396 return std::vector<uint32_t>(&kValues[0], &kValues[arraysize(kValues)]); | 396 return std::vector<uint32_t>(&kValues[0], &kValues[arraysize(kValues)]); |
397 } | 397 } |
398 | 398 |
399 static const std::vector<int32_t> int32_test_values() { | 399 static const std::vector<int32_t> cvt_trunc_int32_test_values() { |
400 static const int32_t kValues[] = { | 400 static const int32_t kValues[] = { |
401 static_cast<int32_t>(0x00000000), static_cast<int32_t>(0x00000001), | 401 static_cast<int32_t>(0x00000000), static_cast<int32_t>(0x00000001), |
402 static_cast<int32_t>(0x00ffff00), static_cast<int32_t>(0x7fffffff), | 402 static_cast<int32_t>(0x00ffff00), static_cast<int32_t>(0x7fffffff), |
403 static_cast<int32_t>(0x80000000), static_cast<int32_t>(0x80000001), | 403 static_cast<int32_t>(0x80000000), static_cast<int32_t>(0x80000001), |
404 static_cast<int32_t>(0x80ffff00), static_cast<int32_t>(0x8fffffff), | 404 static_cast<int32_t>(0x80ffff00), static_cast<int32_t>(0x8fffffff), |
405 static_cast<int32_t>(0xffffffff)}; | 405 static_cast<int32_t>(0xffffffff)}; |
406 return std::vector<int32_t>(&kValues[0], &kValues[arraysize(kValues)]); | 406 return std::vector<int32_t>(&kValues[0], &kValues[arraysize(kValues)]); |
407 } | 407 } |
408 | 408 |
409 // Helper macros that can be used in FOR_INT32_INPUTS(i) { ... *i ... } | 409 // Helper macros that can be used in FOR_INT32_INPUTS(i) { ... *i ... } |
410 #define FOR_INPUTS(ctype, itype, var) \ | 410 #define FOR_INPUTS(ctype, itype, var, test_vector) \ |
411 std::vector<ctype> var##_vec = itype##_test_values(); \ | 411 std::vector<ctype> var##_vec = test_vector(); \ |
412 for (std::vector<ctype>::iterator var = var##_vec.begin(); \ | 412 for (std::vector<ctype>::iterator var = var##_vec.begin(); \ |
413 var != var##_vec.end(); ++var) | 413 var != var##_vec.end(); ++var) |
414 | 414 |
415 #define FOR_UINT32_INPUTS(var) FOR_INPUTS(uint32_t, uint32, var) | 415 #define FOR_INPUTS2(ctype, itype, var, var2, test_vector) \ |
416 #define FOR_INT32_INPUTS(var) FOR_INPUTS(int32_t, int32, var) | 416 std::vector<ctype> var##_vec = test_vector(); \ |
| 417 std::vector<ctype>::iterator var; \ |
| 418 std::vector<ctype>::reverse_iterator var2; \ |
| 419 for (var = var##_vec.begin(), var2 = var##_vec.rbegin(); \ |
| 420 var != var##_vec.end(); ++var, ++var2) |
| 421 |
| 422 #define FOR_UINT32_INPUTS(var, test_vector) \ |
| 423 FOR_INPUTS(uint32_t, uint32, var, test_vector) |
| 424 #define FOR_INT32_INPUTS(var, test_vector) \ |
| 425 FOR_INPUTS(int32_t, int32, var, test_vector) |
| 426 #define FOR_INT32_INPUTS2(var, var2, test_vector) \ |
| 427 FOR_INPUTS2(int32_t, int32, var, var2, test_vector) |
| 428 |
| 429 #define FOR_UINT64_INPUTS(var, test_vector) \ |
| 430 FOR_INPUTS(uint64_t, uint32, var, test_vector) |
417 | 431 |
418 template <typename RET_TYPE, typename IN_TYPE, typename Func> | 432 template <typename RET_TYPE, typename IN_TYPE, typename Func> |
419 RET_TYPE run_Cvt(IN_TYPE x, Func GenerateConvertInstructionFunc) { | 433 RET_TYPE run_Cvt(IN_TYPE x, Func GenerateConvertInstructionFunc) { |
420 typedef RET_TYPE (*F_CVT)(IN_TYPE x0, int x1, int x2, int x3, int x4); | 434 typedef RET_TYPE (*F_CVT)(IN_TYPE x0, int x1, int x2, int x3, int x4); |
421 | 435 |
422 Isolate* isolate = CcTest::i_isolate(); | 436 Isolate* isolate = CcTest::i_isolate(); |
423 HandleScope scope(isolate); | 437 HandleScope scope(isolate); |
424 MacroAssembler assm(isolate, nullptr, 0, | 438 MacroAssembler assm(isolate, nullptr, 0, |
425 v8::internal::CodeObjectRequired::kYes); | 439 v8::internal::CodeObjectRequired::kYes); |
426 MacroAssembler* masm = &assm; | 440 MacroAssembler* masm = &assm; |
(...skipping 10 matching lines...) Expand all Loading... |
437 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | 451 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
438 | 452 |
439 F_CVT f = FUNCTION_CAST<F_CVT>(code->entry()); | 453 F_CVT f = FUNCTION_CAST<F_CVT>(code->entry()); |
440 | 454 |
441 return reinterpret_cast<RET_TYPE>( | 455 return reinterpret_cast<RET_TYPE>( |
442 CALL_GENERATED_CODE(isolate, f, x, 0, 0, 0, 0)); | 456 CALL_GENERATED_CODE(isolate, f, x, 0, 0, 0, 0)); |
443 } | 457 } |
444 | 458 |
445 TEST(cvt_s_w_Trunc_uw_s) { | 459 TEST(cvt_s_w_Trunc_uw_s) { |
446 CcTest::InitializeVM(); | 460 CcTest::InitializeVM(); |
447 FOR_UINT32_INPUTS(i) { | 461 FOR_UINT32_INPUTS(i, cvt_trunc_uint32_test_values) { |
448 uint32_t input = *i; | 462 uint32_t input = *i; |
449 CHECK_EQ(static_cast<float>(input), | 463 CHECK_EQ(static_cast<float>(input), |
450 run_Cvt<uint32_t>(input, [](MacroAssembler* masm) { | 464 run_Cvt<uint32_t>(input, [](MacroAssembler* masm) { |
451 __ cvt_s_w(f0, f4); | 465 __ cvt_s_w(f0, f4); |
452 __ Trunc_uw_s(f2, f0, f1); | 466 __ Trunc_uw_s(f2, f0, f1); |
453 })); | 467 })); |
454 } | 468 } |
455 } | 469 } |
456 | 470 |
457 TEST(cvt_d_w_Trunc_w_d) { | 471 TEST(cvt_d_w_Trunc_w_d) { |
458 CcTest::InitializeVM(); | 472 CcTest::InitializeVM(); |
459 FOR_INT32_INPUTS(i) { | 473 FOR_INT32_INPUTS(i, cvt_trunc_int32_test_values) { |
460 int32_t input = *i; | 474 int32_t input = *i; |
461 CHECK_EQ(static_cast<double>(input), | 475 CHECK_EQ(static_cast<double>(input), |
462 run_Cvt<int32_t>(input, [](MacroAssembler* masm) { | 476 run_Cvt<int32_t>(input, [](MacroAssembler* masm) { |
463 __ cvt_d_w(f0, f4); | 477 __ cvt_d_w(f0, f4); |
464 __ Trunc_w_d(f2, f0); | 478 __ Trunc_w_d(f2, f0); |
465 })); | 479 })); |
466 } | 480 } |
467 } | 481 } |
468 | 482 |
| 483 template <typename IN_TYPE, typename Func> |
| 484 bool run_Unaligned(char* memory_buffer, int32_t in_offset, int32_t out_offset, |
| 485 IN_TYPE value, Func GenerateUnalignedInstructionFunc) { |
| 486 typedef int32_t (*F_CVT)(char* x0, int x1, int x2, int x3, int x4); |
| 487 |
| 488 Isolate* isolate = CcTest::i_isolate(); |
| 489 HandleScope scope(isolate); |
| 490 MacroAssembler assm(isolate, nullptr, 0, |
| 491 v8::internal::CodeObjectRequired::kYes); |
| 492 MacroAssembler* masm = &assm; |
| 493 IN_TYPE res; |
| 494 |
| 495 GenerateUnalignedInstructionFunc(masm, in_offset, out_offset); |
| 496 __ jr(ra); |
| 497 __ nop(); |
| 498 |
| 499 CodeDesc desc; |
| 500 assm.GetCode(&desc); |
| 501 Handle<Code> code = isolate->factory()->NewCode( |
| 502 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 503 |
| 504 F_CVT f = FUNCTION_CAST<F_CVT>(code->entry()); |
| 505 |
| 506 MemCopy(memory_buffer + in_offset, &value, sizeof(IN_TYPE)); |
| 507 CALL_GENERATED_CODE(isolate, f, memory_buffer, 0, 0, 0, 0); |
| 508 MemCopy(&res, memory_buffer + out_offset, sizeof(IN_TYPE)); |
| 509 |
| 510 return res == value; |
| 511 } |
| 512 |
| 513 static const std::vector<uint64_t> unsigned_test_values() { |
| 514 static const uint64_t kValues[] = { |
| 515 0x2180f18a06384414, 0x000a714532102277, 0xbc1acccf180649f0, |
| 516 0x8000000080008000, 0x0000000000000001, 0xffffffffffffffff, |
| 517 }; |
| 518 return std::vector<uint64_t>(&kValues[0], &kValues[arraysize(kValues)]); |
| 519 } |
| 520 |
| 521 static const std::vector<int32_t> unsigned_test_offset() { |
| 522 static const int32_t kValues[] = {// value, offset |
| 523 -132 * KB, -21 * KB, 0, 19 * KB, 135 * KB}; |
| 524 return std::vector<int32_t>(&kValues[0], &kValues[arraysize(kValues)]); |
| 525 } |
| 526 |
| 527 static const std::vector<int32_t> unsigned_test_offset_increment() { |
| 528 static const int32_t kValues[] = {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5}; |
| 529 return std::vector<int32_t>(&kValues[0], &kValues[arraysize(kValues)]); |
| 530 } |
| 531 |
| 532 TEST(Ulh) { |
| 533 CcTest::InitializeVM(); |
| 534 |
| 535 static const int kBufferSize = 300 * KB; |
| 536 char memory_buffer[kBufferSize]; |
| 537 char* buffer_middle = memory_buffer + (kBufferSize / 2); |
| 538 |
| 539 FOR_UINT64_INPUTS(i, unsigned_test_values) { |
| 540 FOR_INT32_INPUTS2(j1, j2, unsigned_test_offset) { |
| 541 FOR_INT32_INPUTS2(k1, k2, unsigned_test_offset_increment) { |
| 542 uint16_t value = static_cast<uint64_t>(*i & 0xFFFF); |
| 543 int32_t in_offset = *j1 + *k1; |
| 544 int32_t out_offset = *j2 + *k2; |
| 545 |
| 546 CHECK_EQ(true, run_Unaligned<uint16_t>( |
| 547 buffer_middle, in_offset, out_offset, value, |
| 548 [](MacroAssembler* masm, int32_t in_offset, |
| 549 int32_t out_offset) { |
| 550 __ Ulh(v0, MemOperand(a0, in_offset)); |
| 551 __ Ush(v0, MemOperand(a0, out_offset), v0); |
| 552 })); |
| 553 CHECK_EQ(true, run_Unaligned<uint16_t>( |
| 554 buffer_middle, in_offset, out_offset, value, |
| 555 [](MacroAssembler* masm, int32_t in_offset, |
| 556 int32_t out_offset) { |
| 557 __ mov(t0, a0); |
| 558 __ Ulh(a0, MemOperand(a0, in_offset)); |
| 559 __ Ush(a0, MemOperand(t0, out_offset), v0); |
| 560 })); |
| 561 CHECK_EQ(true, run_Unaligned<uint16_t>( |
| 562 buffer_middle, in_offset, out_offset, value, |
| 563 [](MacroAssembler* masm, int32_t in_offset, |
| 564 int32_t out_offset) { |
| 565 __ mov(t0, a0); |
| 566 __ Ulhu(a0, MemOperand(a0, in_offset)); |
| 567 __ Ush(a0, MemOperand(t0, out_offset), t1); |
| 568 })); |
| 569 CHECK_EQ(true, run_Unaligned<uint16_t>( |
| 570 buffer_middle, in_offset, out_offset, value, |
| 571 [](MacroAssembler* masm, int32_t in_offset, |
| 572 int32_t out_offset) { |
| 573 __ Ulhu(v0, MemOperand(a0, in_offset)); |
| 574 __ Ush(v0, MemOperand(a0, out_offset), t1); |
| 575 })); |
| 576 } |
| 577 } |
| 578 } |
| 579 } |
| 580 |
| 581 TEST(Ulh_bitextension) { |
| 582 CcTest::InitializeVM(); |
| 583 |
| 584 static const int kBufferSize = 300 * KB; |
| 585 char memory_buffer[kBufferSize]; |
| 586 char* buffer_middle = memory_buffer + (kBufferSize / 2); |
| 587 |
| 588 FOR_UINT64_INPUTS(i, unsigned_test_values) { |
| 589 FOR_INT32_INPUTS2(j1, j2, unsigned_test_offset) { |
| 590 FOR_INT32_INPUTS2(k1, k2, unsigned_test_offset_increment) { |
| 591 uint16_t value = static_cast<uint64_t>(*i & 0xFFFF); |
| 592 int32_t in_offset = *j1 + *k1; |
| 593 int32_t out_offset = *j2 + *k2; |
| 594 |
| 595 CHECK_EQ(true, run_Unaligned<uint16_t>( |
| 596 buffer_middle, in_offset, out_offset, value, |
| 597 [](MacroAssembler* masm, int32_t in_offset, |
| 598 int32_t out_offset) { |
| 599 Label success, fail, end, different; |
| 600 __ Ulh(t0, MemOperand(a0, in_offset)); |
| 601 __ Ulhu(t1, MemOperand(a0, in_offset)); |
| 602 __ Branch(&different, ne, t0, Operand(t1)); |
| 603 |
| 604 // If signed and unsigned values are same, check |
| 605 // the upper bits to see if they are zero |
| 606 __ sra(t0, t0, 15); |
| 607 __ Branch(&success, eq, t0, Operand(zero_reg)); |
| 608 __ Branch(&fail); |
| 609 |
| 610 // If signed and unsigned values are different, |
| 611 // check that the upper bits are complementary |
| 612 __ bind(&different); |
| 613 __ sra(t1, t1, 15); |
| 614 __ Branch(&fail, ne, t1, Operand(1)); |
| 615 __ sra(t0, t0, 15); |
| 616 __ addiu(t0, t0, 1); |
| 617 __ Branch(&fail, ne, t0, Operand(zero_reg)); |
| 618 // Fall through to success |
| 619 |
| 620 __ bind(&success); |
| 621 __ Ulh(t0, MemOperand(a0, in_offset)); |
| 622 __ Ush(t0, MemOperand(a0, out_offset), v0); |
| 623 __ Branch(&end); |
| 624 __ bind(&fail); |
| 625 __ Ush(zero_reg, MemOperand(a0, out_offset), v0); |
| 626 __ bind(&end); |
| 627 })); |
| 628 } |
| 629 } |
| 630 } |
| 631 } |
| 632 |
| 633 TEST(Ulw) { |
| 634 CcTest::InitializeVM(); |
| 635 |
| 636 static const int kBufferSize = 300 * KB; |
| 637 char memory_buffer[kBufferSize]; |
| 638 char* buffer_middle = memory_buffer + (kBufferSize / 2); |
| 639 |
| 640 FOR_UINT64_INPUTS(i, unsigned_test_values) { |
| 641 FOR_INT32_INPUTS2(j1, j2, unsigned_test_offset) { |
| 642 FOR_INT32_INPUTS2(k1, k2, unsigned_test_offset_increment) { |
| 643 uint32_t value = static_cast<uint32_t>(*i & 0xFFFFFFFF); |
| 644 int32_t in_offset = *j1 + *k1; |
| 645 int32_t out_offset = *j2 + *k2; |
| 646 |
| 647 CHECK_EQ(true, run_Unaligned<uint32_t>( |
| 648 buffer_middle, in_offset, out_offset, value, |
| 649 [](MacroAssembler* masm, int32_t in_offset, |
| 650 int32_t out_offset) { |
| 651 __ Ulw(v0, MemOperand(a0, in_offset)); |
| 652 __ Usw(v0, MemOperand(a0, out_offset)); |
| 653 })); |
| 654 CHECK_EQ(true, |
| 655 run_Unaligned<uint32_t>( |
| 656 buffer_middle, in_offset, out_offset, (uint32_t)value, |
| 657 [](MacroAssembler* masm, int32_t in_offset, |
| 658 int32_t out_offset) { |
| 659 __ mov(t0, a0); |
| 660 __ Ulw(a0, MemOperand(a0, in_offset)); |
| 661 __ Usw(a0, MemOperand(t0, out_offset)); |
| 662 })); |
| 663 } |
| 664 } |
| 665 } |
| 666 } |
| 667 |
| 668 TEST(Ulwc1) { |
| 669 CcTest::InitializeVM(); |
| 670 |
| 671 static const int kBufferSize = 300 * KB; |
| 672 char memory_buffer[kBufferSize]; |
| 673 char* buffer_middle = memory_buffer + (kBufferSize / 2); |
| 674 |
| 675 FOR_UINT64_INPUTS(i, unsigned_test_values) { |
| 676 FOR_INT32_INPUTS2(j1, j2, unsigned_test_offset) { |
| 677 FOR_INT32_INPUTS2(k1, k2, unsigned_test_offset_increment) { |
| 678 float value = static_cast<float>(*i & 0xFFFFFFFF); |
| 679 int32_t in_offset = *j1 + *k1; |
| 680 int32_t out_offset = *j2 + *k2; |
| 681 |
| 682 CHECK_EQ(true, run_Unaligned<float>( |
| 683 buffer_middle, in_offset, out_offset, value, |
| 684 [](MacroAssembler* masm, int32_t in_offset, |
| 685 int32_t out_offset) { |
| 686 __ Ulwc1(f0, MemOperand(a0, in_offset), t0); |
| 687 __ Uswc1(f0, MemOperand(a0, out_offset), t0); |
| 688 })); |
| 689 } |
| 690 } |
| 691 } |
| 692 } |
| 693 |
| 694 TEST(Uldc1) { |
| 695 CcTest::InitializeVM(); |
| 696 |
| 697 static const int kBufferSize = 300 * KB; |
| 698 char memory_buffer[kBufferSize]; |
| 699 char* buffer_middle = memory_buffer + (kBufferSize / 2); |
| 700 |
| 701 FOR_UINT64_INPUTS(i, unsigned_test_values) { |
| 702 FOR_INT32_INPUTS2(j1, j2, unsigned_test_offset) { |
| 703 FOR_INT32_INPUTS2(k1, k2, unsigned_test_offset_increment) { |
| 704 double value = static_cast<double>(*i); |
| 705 int32_t in_offset = *j1 + *k1; |
| 706 int32_t out_offset = *j2 + *k2; |
| 707 |
| 708 CHECK_EQ(true, run_Unaligned<double>( |
| 709 buffer_middle, in_offset, out_offset, value, |
| 710 [](MacroAssembler* masm, int32_t in_offset, |
| 711 int32_t out_offset) { |
| 712 __ Uldc1(f0, MemOperand(a0, in_offset), t0); |
| 713 __ Usdc1(f0, MemOperand(a0, out_offset), t0); |
| 714 })); |
| 715 } |
| 716 } |
| 717 } |
| 718 } |
| 719 |
469 #undef __ | 720 #undef __ |
OLD | NEW |