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

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

Issue 2908753002: MIPS[64]: Implement insert.df and I8 instructions in simulator (Closed)
Patch Set: Created 3 years, 7 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 6573 matching lines...) Expand 10 before | Expand all | Expand 10 after
6584 #endif 6584 #endif
6585 F5 f = FUNCTION_CAST<F5>(code->entry()); 6585 F5 f = FUNCTION_CAST<F5>(code->entry());
6586 6586
6587 Object* dummy = CALL_GENERATED_CODE(isolate, f, &t[0], &t[1], 0, 0, 0); 6587 Object* dummy = CALL_GENERATED_CODE(isolate, f, &t[0], &t[1], 0, 0, 0);
6588 USE(dummy); 6588 USE(dummy);
6589 6589
6590 CHECK_EQ(0x5555555555555555, t[0].d0); 6590 CHECK_EQ(0x5555555555555555, t[0].d0);
6591 CHECK_EQ(0x5555555555555555, t[1].d0); 6591 CHECK_EQ(0x5555555555555555, t[1].d0);
6592 } 6592 }
6593 6593
6594 typedef union {
6595 uint8_t b[16];
6596 uint16_t h[8];
6597 uint32_t w[4];
6598 uint64_t d[2];
6599 } msa_reg_t;
6600
6601 template <typename T>
6602 void run_msa_insert(int64_t rs_value, int n, msa_reg_t* w) {
6603 Isolate* isolate = CcTest::i_isolate();
6604 HandleScope scope(isolate);
6605
6606 MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes);
6607 CpuFeatureScope fscope(&assm, MIPS_SIMD);
6608
6609 __ li(t0, -1);
6610 __ li(t1, rs_value);
6611 __ fill_w(w0, t0);
6612
6613 if (std::is_same<T, int8_t>::value) {
6614 DCHECK(n < 16);
6615 __ insert_b(w0, n, t1);
6616 } else if (std::is_same<T, int16_t>::value) {
6617 DCHECK(n < 8);
6618 __ insert_h(w0, n, t1);
6619 } else if (std::is_same<T, int32_t>::value) {
6620 DCHECK(n < 4);
6621 __ insert_w(w0, n, t1);
6622 } else if (std::is_same<T, int64_t>::value) {
6623 DCHECK(n < 2);
6624 __ insert_d(w0, n, t1);
6625 } else {
6626 UNREACHABLE();
6627 }
6628
6629 __ copy_u_w(t2, w0, 0);
6630 __ sw(t2, MemOperand(a0, 0));
6631 __ copy_u_w(t2, w0, 1);
6632 __ sw(t2, MemOperand(a0, 4));
6633 __ copy_u_w(t2, w0, 2);
6634 __ sw(t2, MemOperand(a0, 8));
6635 __ copy_u_w(t2, w0, 3);
6636 __ sw(t2, MemOperand(a0, 12));
6637
6638 __ jr(ra);
6639 __ nop();
6640
6641 CodeDesc desc;
6642 assm.GetCode(&desc);
6643 Handle<Code> code = isolate->factory()->NewCode(
6644 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
6645 #ifdef OBJECT_PRINT
6646 code->Print(std::cout);
6647 #endif
6648 F3 f = FUNCTION_CAST<F3>(code->entry());
6649
6650 (CALL_GENERATED_CODE(isolate, f, w, 0, 0, 0, 0));
6651 }
6652
6653 TEST(MSA_insert) {
6654 if ((kArchVariant != kMips64r6) || !CpuFeatures::IsSupported(MIPS_SIMD))
6655 return;
6656
6657 CcTest::InitializeVM();
6658
6659 struct TestCaseInsert {
6660 uint64_t input;
6661 int n;
6662 uint64_t exp_res_lo;
6663 uint64_t exp_res_hi;
6664 };
6665
6666 struct TestCaseInsert tc_b[] = {
6667 // input, n, exp_res_lo, exp_res_hi
6668 {0xa2, 13, 0xffffffffffffffffu, 0xffffa2ffffffffffu},
6669 {0x73, 10, 0xffffffffffffffffu, 0xffffffffff73ffffu},
6670 {0x3494, 5, 0xffff94ffffffffffu, 0xffffffffffffffffu},
6671 {0xa6b8, 1, 0xffffffffffffb8ffu, 0xffffffffffffffffu}};
6672
6673 for (size_t i = 0; i < sizeof(tc_b) / sizeof(TestCaseInsert); ++i) {
6674 msa_reg_t res;
6675 run_msa_insert<int8_t>(tc_b[i].input, tc_b[i].n, &res);
6676 CHECK_EQ(tc_b[i].exp_res_lo, res.d[0]);
6677 CHECK_EQ(tc_b[i].exp_res_hi, res.d[1]);
6678 }
6679
6680 struct TestCaseInsert tc_h[] = {
6681 // input, n, exp_res_lo, exp_res_hi
6682 {0x85a2, 7, 0xffffffffffffffffu, 0x85a2ffffffffffffu},
6683 {0xe873, 5, 0xffffffffffffffffu, 0xffffffffe873ffffu},
6684 {0x3494, 3, 0x3494ffffffffffffu, 0xffffffffffffffffu},
6685 {0xa6b8, 1, 0xffffffffa6b8ffffu, 0xffffffffffffffffu}};
6686
6687 for (size_t i = 0; i < sizeof(tc_h) / sizeof(TestCaseInsert); ++i) {
6688 msa_reg_t res;
6689 run_msa_insert<int16_t>(tc_h[i].input, tc_h[i].n, &res);
6690 CHECK_EQ(tc_h[i].exp_res_lo, res.d[0]);
6691 CHECK_EQ(tc_h[i].exp_res_hi, res.d[1]);
6692 }
6693
6694 struct TestCaseInsert tc_w[] = {
6695 // input, n, exp_res_lo, exp_res_hi
6696 {0xd2f085a2u, 3, 0xffffffffffffffffu, 0xd2f085a2ffffffffu},
6697 {0x4567e873u, 2, 0xffffffffffffffffu, 0xffffffff4567e873u},
6698 {0xacdb3494u, 1, 0xacdb3494ffffffffu, 0xffffffffffffffffu},
6699 {0x89aba6b8u, 0, 0xffffffff89aba6b8u, 0xffffffffffffffffu}};
6700
6701 for (size_t i = 0; i < sizeof(tc_w) / sizeof(TestCaseInsert); ++i) {
6702 msa_reg_t res;
6703 run_msa_insert<int32_t>(tc_w[i].input, tc_w[i].n, &res);
6704 CHECK_EQ(tc_w[i].exp_res_lo, res.d[0]);
6705 CHECK_EQ(tc_w[i].exp_res_hi, res.d[1]);
6706 }
6707
6708 struct TestCaseInsert tc_d[] = {
6709 // input, n, exp_res_lo, exp_res_hi
6710 {0xf35862e13e38f8b0, 1, 0xffffffffffffffffu, 0xf35862e13e38f8b0},
6711 {0x4f41ffdef2bfe636, 0, 0x4f41ffdef2bfe636, 0xffffffffffffffffu}};
6712
6713 for (size_t i = 0; i < sizeof(tc_d) / sizeof(TestCaseInsert); ++i) {
6714 msa_reg_t res;
6715 run_msa_insert<int64_t>(tc_d[i].input, tc_d[i].n, &res);
6716 CHECK_EQ(tc_d[i].exp_res_lo, res.d[0]);
6717 CHECK_EQ(tc_d[i].exp_res_hi, res.d[1]);
6718 }
6719 }
6720
6721 enum MsaI8Opcode {
6722 kANDI,
Ilija.Pavlovic1 2017/05/29 07:31:21 Move in constants-mips64.h?
dusan.simicic 2017/05/29 16:32:15 Same as for mips32.
6723 kORI,
6724 kNORI,
6725 kXORI,
6726 kBMNZI,
6727 kBMZI,
6728 kBSELI,
6729 kSHF_B,
6730 kSHF_H,
6731 kSHF_W
6732 };
6733
6734 struct ExpResShf {
6735 uint8_t i8;
6736 uint64_t lo;
6737 uint64_t hi;
6738 };
6739
6740 void run_msa_i8(int opcode, uint64_t ws_lo, uint64_t ws_hi, uint8_t i8) {
6741 Isolate* isolate = CcTest::i_isolate();
6742 HandleScope scope(isolate);
6743
6744 MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes);
6745 CpuFeatureScope fscope(&assm, MIPS_SIMD);
6746 msa_reg_t res;
6747 uint64_t wd_lo = 0xf35862e13e38f8b0;
6748 uint64_t wd_hi = 0x4f41ffdef2bfe636;
6749
6750 #define LOAD_W_REG(lo, hi, w_reg) \
6751 __ li(t0, lo); \
6752 __ li(t1, hi); \
6753 __ insert_d(w_reg, 0, t0); \
6754 __ insert_d(w_reg, 1, t1);
6755
6756 LOAD_W_REG(ws_lo, ws_hi, w0)
6757
6758 switch (opcode) {
6759 case kANDI:
6760 __ andi_b(w2, w0, i8);
6761 break;
6762 case kORI:
6763 __ ori_b(w2, w0, i8);
6764 break;
6765 case kNORI:
6766 __ nori_b(w2, w0, i8);
6767 break;
6768 case kXORI:
6769 __ xori_b(w2, w0, i8);
6770 break;
6771 case kBMNZI:
6772 LOAD_W_REG(wd_lo, wd_hi, w2);
6773 __ bmnzi_b(w2, w0, i8);
6774 break;
6775 case kBMZI:
6776 LOAD_W_REG(wd_lo, wd_hi, w2);
6777 __ bmzi_b(w2, w0, i8);
6778 break;
6779 case kBSELI:
6780 LOAD_W_REG(wd_lo, wd_hi, w2);
6781 __ bseli_b(w2, w0, i8);
6782 break;
6783 case kSHF_B:
6784 __ shf_b(w2, w0, i8);
6785 break;
6786 case kSHF_H:
6787 __ shf_h(w2, w0, i8);
6788 break;
6789 case kSHF_W:
6790 __ shf_w(w2, w0, i8);
6791 break;
6792 default:
6793 UNREACHABLE();
6794 }
6795
6796 __ copy_u_w(t2, w2, 0);
6797 __ sw(t2, MemOperand(a0, 0));
6798 __ copy_u_w(t2, w2, 1);
6799 __ sw(t2, MemOperand(a0, 4));
6800 __ copy_u_w(t2, w2, 2);
6801 __ sw(t2, MemOperand(a0, 8));
6802 __ copy_u_w(t2, w2, 3);
6803 __ sw(t2, MemOperand(a0, 12));
6804
6805 __ jr(ra);
6806 __ nop();
6807
6808 #undef LOAD_W_REG
6809
6810 CodeDesc desc;
6811 assm.GetCode(&desc);
6812 Handle<Code> code = isolate->factory()->NewCode(
6813 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
6814 #ifdef OBJECT_PRINT
6815 code->Print(std::cout);
6816 #endif
6817 F3 f = FUNCTION_CAST<F3>(code->entry());
6818
6819 (CALL_GENERATED_CODE(isolate, f, &res, 0, 0, 0, 0));
6820
6821 uint64_t mask = i8 * 0x0101010101010101ull;
6822 switch (opcode) {
6823 case kANDI:
6824 CHECK_EQ(ws_lo & mask, res.d[0]);
6825 CHECK_EQ(ws_hi & mask, res.d[1]);
6826 break;
6827 case kORI:
6828 CHECK_EQ(ws_lo | mask, res.d[0]);
6829 CHECK_EQ(ws_hi | mask, res.d[1]);
6830 break;
6831 case kNORI:
6832 CHECK_EQ(~(ws_lo | mask), res.d[0]);
6833 CHECK_EQ(~(ws_hi | mask), res.d[1]);
6834 break;
6835 case kXORI:
6836 CHECK_EQ(ws_lo ^ mask, res.d[0]);
6837 CHECK_EQ(ws_hi ^ mask, res.d[1]);
6838 break;
6839 case kBMNZI:
6840 CHECK_EQ((ws_lo & mask) | (wd_lo & ~mask), res.d[0]);
6841 CHECK_EQ((ws_hi & mask) | (wd_hi & ~mask), res.d[1]);
6842 break;
6843 case kBMZI:
6844 CHECK_EQ((ws_lo & ~mask) | (wd_lo & mask), res.d[0]);
6845 CHECK_EQ((ws_hi & ~mask) | (wd_hi & mask), res.d[1]);
6846 break;
6847 case kBSELI:
6848 CHECK_EQ((ws_lo & ~wd_lo) | (mask & wd_lo), res.d[0]);
6849 CHECK_EQ((ws_hi & ~wd_hi) | (mask & wd_hi), res.d[1]);
6850 break;
6851 case kSHF_B: {
6852 struct ExpResShf exp_b[] = {
6853 // i8, exp_lo, exp_hi
6854 {0xffu, 0x11111111b9b9b9b9, 0xf7f7f7f7c8c8c8c8},
6855 {0x0u, 0x62626262dfdfdfdf, 0xd6d6d6d6c8c8c8c8},
6856 {0xe4u, 0xf35862e13e38f8b0, 0x4f41ffdef2bfe636},
6857 {0x1bu, 0x1b756911c3d9a7b9, 0xae94a5f79c8aefc8},
6858 {0xb1u, 0x662b6253e8c4df12, 0x0d3ad6803f8bc88b},
6859 {0x4eu, 0x62e1f358f8b03e38, 0xffde4f41e636f2bf},
6860 {0x27u, 0x1b697511c3a7d9b9, 0xaea594f79cef8ac8}};
6861 for (size_t i = 0; i < sizeof(exp_b) / sizeof(ExpResShf); ++i) {
6862 if (exp_b[i].i8 == i8) {
6863 CHECK_EQ(exp_b[i].lo, res.d[0]);
6864 CHECK_EQ(exp_b[i].hi, res.d[1]);
6865 }
6866 }
6867 } break;
6868 case kSHF_H: {
6869 struct ExpResShf exp_h[] = {
6870 // i8, exp_lo, exp_hi
6871 {0xffu, 0x1169116911691169, 0xf7a5f7a5f7a5f7a5},
6872 {0x0u, 0x12df12df12df12df, 0x8bc88bc88bc88bc8},
6873 {0xe4u, 0xf35862e13e38f8b0, 0x4f41ffdef2bfe636},
6874 {0x1bu, 0xd9c3b9a7751b1169, 0x8a9cc8ef94aef7a5},
6875 {0xb1u, 0x53622b6612dfc4e8, 0x80d63a0d8bc88b3f},
6876 {0x4eu, 0x3e38f8b0f35862e1, 0xf2bfe6364f41ffde},
6877 {0x27u, 0xd9c3751bb9a71169, 0x8a9c94aec8eff7a5}};
6878 for (size_t i = 0; i < sizeof(exp_h) / sizeof(ExpResShf); ++i) {
6879 if (exp_h[i].i8 == i8) {
6880 CHECK_EQ(exp_h[i].lo, res.d[0]);
6881 CHECK_EQ(exp_h[i].hi, res.d[1]);
6882 }
6883 }
6884 } break;
6885 case kSHF_W: {
6886 struct ExpResShf exp_w[] = {
6887 // i8, exp_lo, exp_hi
6888 {0xffu, 0xf7a594aef7a594ae, 0xf7a594aef7a594ae},
6889 {0x0u, 0xc4e812dfc4e812df, 0xc4e812dfc4e812df},
6890 {0xe4u, 0xf35862e13e38f8b0, 0x4f41ffdef2bfe636},
6891 {0x1bu, 0xc8ef8a9cf7a594ae, 0xb9a7d9c31169751b},
6892 {0xb1u, 0xc4e812df2b665362, 0x8b3f8bc83a0d80d6},
6893 {0x4eu, 0x4f41ffdef2bfe636, 0xf35862e13e38f8b0},
6894 {0x27u, 0x1169751bf7a594ae, 0xb9a7d9c3c8ef8a9c}};
6895 for (size_t i = 0; i < sizeof(exp_w) / sizeof(ExpResShf); ++i) {
6896 if (exp_w[i].i8 == i8) {
6897 CHECK_EQ(exp_w[i].lo, res.d[0]);
6898 CHECK_EQ(exp_w[i].hi, res.d[1]);
6899 }
6900 }
6901 } break;
6902 default:
6903 UNREACHABLE();
6904 }
6905 }
6906
6907 struct TestCaseMsaI8 {
6908 uint64_t input_lo;
6909 uint64_t input_hi;
6910 uint8_t i8;
6911 };
6912
6913 TEST(MSA_andi_ori_nori_xori) {
6914 if ((kArchVariant != kMips64r6) || !CpuFeatures::IsSupported(MIPS_SIMD))
6915 return;
6916
6917 CcTest::InitializeVM();
6918
6919 struct TestCaseMsaI8 tc[] = {// input_lo, input_hi, i8
6920 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0xffu},
6921 {0x2b665362c4e812df, 0x3a0d80d68b3f8bc8, 0x0u},
6922 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0x3bu},
6923 {0x2b665362c4e812df, 0x3a0d80d68b3f8bc8, 0xd9u}};
6924
6925 for (size_t i = 0; i < sizeof(tc) / sizeof(TestCaseMsaI8); ++i) {
6926 run_msa_i8(kANDI, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6927 run_msa_i8(kORI, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6928 run_msa_i8(kNORI, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6929 run_msa_i8(kXORI, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6930 }
6931 }
6932
6933 TEST(MSA_bmnzi_bmzi_bseli) {
6934 if ((kArchVariant != kMips64r6) || !CpuFeatures::IsSupported(MIPS_SIMD))
6935 return;
6936
6937 CcTest::InitializeVM();
6938
6939 struct TestCaseMsaI8 tc[] = {// input_lo, input_hi, i8
6940 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0xffu},
6941 {0x2b665362c4e812df, 0x3a0d80d68b3f8bc8, 0x0u},
6942 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0x3bu},
6943 {0x2b665362c4e812df, 0x3a0d80d68b3f8bc8, 0xd9u}};
6944
6945 for (size_t i = 0; i < sizeof(tc) / sizeof(TestCaseMsaI8); ++i) {
6946 run_msa_i8(kBMNZI, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6947 run_msa_i8(kBMZI, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6948 run_msa_i8(kBSELI, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6949 }
6950 }
6951
6952 TEST(MSA_shf) {
6953 if ((kArchVariant != kMips64r6) || !CpuFeatures::IsSupported(MIPS_SIMD))
6954 return;
6955
6956 CcTest::InitializeVM();
6957
6958 struct TestCaseMsaI8 tc[] = {
6959 // input_lo, input_hi, i8
6960 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0xffu}, // 3333
6961 {0x2b665362c4e812df, 0x3a0d80d68b3f8bc8, 0x0u}, // 0000
6962 {0xf35862e13e38f8b0, 0x4f41ffdef2bfe636, 0xe4u}, // 3210
6963 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0x1bu}, // 0123
6964 {0x2b665362c4e812df, 0x3a0d80d68b3f8bc8, 0xb1u}, // 2301
6965 {0xf35862e13e38f8b0, 0x4f41ffdef2bfe636, 0x4eu}, // 1032
6966 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0x27u} // 0213
6967 };
6968
6969 for (size_t i = 0; i < sizeof(tc) / sizeof(TestCaseMsaI8); ++i) {
6970 run_msa_i8(kSHF_B, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6971 run_msa_i8(kSHF_H, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6972 run_msa_i8(kSHF_W, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6973 }
6974 }
6975
6594 #undef __ 6976 #undef __
OLDNEW
« test/cctest/test-assembler-mips.cc ('K') | « test/cctest/test-assembler-mips.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698