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

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: Review comments, rebase Created 3 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
« no previous file with comments | « test/cctest/test-assembler-mips.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 struct ExpResShf {
6722 uint8_t i8;
6723 uint64_t lo;
6724 uint64_t hi;
6725 };
6726
6727 void run_msa_i8(SecondaryField opcode, uint64_t ws_lo, uint64_t ws_hi,
6728 uint8_t i8) {
6729 Isolate* isolate = CcTest::i_isolate();
6730 HandleScope scope(isolate);
6731
6732 MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes);
6733 CpuFeatureScope fscope(&assm, MIPS_SIMD);
6734 msa_reg_t res;
6735 uint64_t wd_lo = 0xf35862e13e38f8b0;
6736 uint64_t wd_hi = 0x4f41ffdef2bfe636;
6737
6738 #define LOAD_W_REG(lo, hi, w_reg) \
6739 __ li(t0, lo); \
6740 __ li(t1, hi); \
6741 __ insert_d(w_reg, 0, t0); \
6742 __ insert_d(w_reg, 1, t1);
6743
6744 LOAD_W_REG(ws_lo, ws_hi, w0)
6745
6746 switch (opcode) {
6747 case ANDI_B:
6748 __ andi_b(w2, w0, i8);
6749 break;
6750 case ORI_B:
6751 __ ori_b(w2, w0, i8);
6752 break;
6753 case NORI_B:
6754 __ nori_b(w2, w0, i8);
6755 break;
6756 case XORI_B:
6757 __ xori_b(w2, w0, i8);
6758 break;
6759 case BMNZI_B:
6760 LOAD_W_REG(wd_lo, wd_hi, w2);
6761 __ bmnzi_b(w2, w0, i8);
6762 break;
6763 case BMZI_B:
6764 LOAD_W_REG(wd_lo, wd_hi, w2);
6765 __ bmzi_b(w2, w0, i8);
6766 break;
6767 case BSELI_B:
6768 LOAD_W_REG(wd_lo, wd_hi, w2);
6769 __ bseli_b(w2, w0, i8);
6770 break;
6771 case SHF_B:
6772 __ shf_b(w2, w0, i8);
6773 break;
6774 case SHF_H:
6775 __ shf_h(w2, w0, i8);
6776 break;
6777 case SHF_W:
6778 __ shf_w(w2, w0, i8);
6779 break;
6780 default:
6781 UNREACHABLE();
6782 }
6783
6784 __ copy_u_w(t2, w2, 0);
6785 __ sw(t2, MemOperand(a0, 0));
6786 __ copy_u_w(t2, w2, 1);
6787 __ sw(t2, MemOperand(a0, 4));
6788 __ copy_u_w(t2, w2, 2);
6789 __ sw(t2, MemOperand(a0, 8));
6790 __ copy_u_w(t2, w2, 3);
6791 __ sw(t2, MemOperand(a0, 12));
6792
6793 __ jr(ra);
6794 __ nop();
6795
6796 #undef LOAD_W_REG
6797
6798 CodeDesc desc;
6799 assm.GetCode(&desc);
6800 Handle<Code> code = isolate->factory()->NewCode(
6801 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
6802 #ifdef OBJECT_PRINT
6803 code->Print(std::cout);
6804 #endif
6805 F3 f = FUNCTION_CAST<F3>(code->entry());
6806
6807 (CALL_GENERATED_CODE(isolate, f, &res, 0, 0, 0, 0));
6808
6809 uint64_t mask = i8 * 0x0101010101010101ull;
6810 switch (opcode) {
6811 case ANDI_B:
6812 CHECK_EQ(ws_lo & mask, res.d[0]);
6813 CHECK_EQ(ws_hi & mask, res.d[1]);
6814 break;
6815 case ORI_B:
6816 CHECK_EQ(ws_lo | mask, res.d[0]);
6817 CHECK_EQ(ws_hi | mask, res.d[1]);
6818 break;
6819 case NORI_B:
6820 CHECK_EQ(~(ws_lo | mask), res.d[0]);
6821 CHECK_EQ(~(ws_hi | mask), res.d[1]);
6822 break;
6823 case XORI_B:
6824 CHECK_EQ(ws_lo ^ mask, res.d[0]);
6825 CHECK_EQ(ws_hi ^ mask, res.d[1]);
6826 break;
6827 case BMNZI_B:
6828 CHECK_EQ((ws_lo & mask) | (wd_lo & ~mask), res.d[0]);
6829 CHECK_EQ((ws_hi & mask) | (wd_hi & ~mask), res.d[1]);
6830 break;
6831 case BMZI_B:
6832 CHECK_EQ((ws_lo & ~mask) | (wd_lo & mask), res.d[0]);
6833 CHECK_EQ((ws_hi & ~mask) | (wd_hi & mask), res.d[1]);
6834 break;
6835 case BSELI_B:
6836 CHECK_EQ((ws_lo & ~wd_lo) | (mask & wd_lo), res.d[0]);
6837 CHECK_EQ((ws_hi & ~wd_hi) | (mask & wd_hi), res.d[1]);
6838 break;
6839 case SHF_B: {
6840 struct ExpResShf exp_b[] = {
6841 // i8, exp_lo, exp_hi
6842 {0xffu, 0x11111111b9b9b9b9, 0xf7f7f7f7c8c8c8c8},
6843 {0x0u, 0x62626262dfdfdfdf, 0xd6d6d6d6c8c8c8c8},
6844 {0xe4u, 0xf35862e13e38f8b0, 0x4f41ffdef2bfe636},
6845 {0x1bu, 0x1b756911c3d9a7b9, 0xae94a5f79c8aefc8},
6846 {0xb1u, 0x662b6253e8c4df12, 0x0d3ad6803f8bc88b},
6847 {0x4eu, 0x62e1f358f8b03e38, 0xffde4f41e636f2bf},
6848 {0x27u, 0x1b697511c3a7d9b9, 0xaea594f79cef8ac8}};
6849 for (size_t i = 0; i < sizeof(exp_b) / sizeof(ExpResShf); ++i) {
6850 if (exp_b[i].i8 == i8) {
6851 CHECK_EQ(exp_b[i].lo, res.d[0]);
6852 CHECK_EQ(exp_b[i].hi, res.d[1]);
6853 }
6854 }
6855 } break;
6856 case SHF_H: {
6857 struct ExpResShf exp_h[] = {
6858 // i8, exp_lo, exp_hi
6859 {0xffu, 0x1169116911691169, 0xf7a5f7a5f7a5f7a5},
6860 {0x0u, 0x12df12df12df12df, 0x8bc88bc88bc88bc8},
6861 {0xe4u, 0xf35862e13e38f8b0, 0x4f41ffdef2bfe636},
6862 {0x1bu, 0xd9c3b9a7751b1169, 0x8a9cc8ef94aef7a5},
6863 {0xb1u, 0x53622b6612dfc4e8, 0x80d63a0d8bc88b3f},
6864 {0x4eu, 0x3e38f8b0f35862e1, 0xf2bfe6364f41ffde},
6865 {0x27u, 0xd9c3751bb9a71169, 0x8a9c94aec8eff7a5}};
6866 for (size_t i = 0; i < sizeof(exp_h) / sizeof(ExpResShf); ++i) {
6867 if (exp_h[i].i8 == i8) {
6868 CHECK_EQ(exp_h[i].lo, res.d[0]);
6869 CHECK_EQ(exp_h[i].hi, res.d[1]);
6870 }
6871 }
6872 } break;
6873 case SHF_W: {
6874 struct ExpResShf exp_w[] = {
6875 // i8, exp_lo, exp_hi
6876 {0xffu, 0xf7a594aef7a594ae, 0xf7a594aef7a594ae},
6877 {0x0u, 0xc4e812dfc4e812df, 0xc4e812dfc4e812df},
6878 {0xe4u, 0xf35862e13e38f8b0, 0x4f41ffdef2bfe636},
6879 {0x1bu, 0xc8ef8a9cf7a594ae, 0xb9a7d9c31169751b},
6880 {0xb1u, 0xc4e812df2b665362, 0x8b3f8bc83a0d80d6},
6881 {0x4eu, 0x4f41ffdef2bfe636, 0xf35862e13e38f8b0},
6882 {0x27u, 0x1169751bf7a594ae, 0xb9a7d9c3c8ef8a9c}};
6883 for (size_t i = 0; i < sizeof(exp_w) / sizeof(ExpResShf); ++i) {
6884 if (exp_w[i].i8 == i8) {
6885 CHECK_EQ(exp_w[i].lo, res.d[0]);
6886 CHECK_EQ(exp_w[i].hi, res.d[1]);
6887 }
6888 }
6889 } break;
6890 default:
6891 UNREACHABLE();
6892 }
6893 }
6894
6895 struct TestCaseMsaI8 {
6896 uint64_t input_lo;
6897 uint64_t input_hi;
6898 uint8_t i8;
6899 };
6900
6901 TEST(MSA_andi_ori_nori_xori) {
6902 if ((kArchVariant != kMips64r6) || !CpuFeatures::IsSupported(MIPS_SIMD))
6903 return;
6904
6905 CcTest::InitializeVM();
6906
6907 struct TestCaseMsaI8 tc[] = {// input_lo, input_hi, i8
6908 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0xffu},
6909 {0x2b665362c4e812df, 0x3a0d80d68b3f8bc8, 0x0u},
6910 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0x3bu},
6911 {0x2b665362c4e812df, 0x3a0d80d68b3f8bc8, 0xd9u}};
6912
6913 for (size_t i = 0; i < sizeof(tc) / sizeof(TestCaseMsaI8); ++i) {
6914 run_msa_i8(ANDI_B, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6915 run_msa_i8(ORI_B, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6916 run_msa_i8(NORI_B, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6917 run_msa_i8(XORI_B, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6918 }
6919 }
6920
6921 TEST(MSA_bmnzi_bmzi_bseli) {
6922 if ((kArchVariant != kMips64r6) || !CpuFeatures::IsSupported(MIPS_SIMD))
6923 return;
6924
6925 CcTest::InitializeVM();
6926
6927 struct TestCaseMsaI8 tc[] = {// input_lo, input_hi, i8
6928 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0xffu},
6929 {0x2b665362c4e812df, 0x3a0d80d68b3f8bc8, 0x0u},
6930 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0x3bu},
6931 {0x2b665362c4e812df, 0x3a0d80d68b3f8bc8, 0xd9u}};
6932
6933 for (size_t i = 0; i < sizeof(tc) / sizeof(TestCaseMsaI8); ++i) {
6934 run_msa_i8(BMNZI_B, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6935 run_msa_i8(BMZI_B, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6936 run_msa_i8(BSELI_B, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6937 }
6938 }
6939
6940 TEST(MSA_shf) {
6941 if ((kArchVariant != kMips64r6) || !CpuFeatures::IsSupported(MIPS_SIMD))
6942 return;
6943
6944 CcTest::InitializeVM();
6945
6946 struct TestCaseMsaI8 tc[] = {
6947 // input_lo, input_hi, i8
6948 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0xffu}, // 3333
6949 {0x2b665362c4e812df, 0x3a0d80d68b3f8bc8, 0x0u}, // 0000
6950 {0xf35862e13e38f8b0, 0x4f41ffdef2bfe636, 0xe4u}, // 3210
6951 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0x1bu}, // 0123
6952 {0x2b665362c4e812df, 0x3a0d80d68b3f8bc8, 0xb1u}, // 2301
6953 {0xf35862e13e38f8b0, 0x4f41ffdef2bfe636, 0x4eu}, // 1032
6954 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0x27u} // 0213
6955 };
6956
6957 for (size_t i = 0; i < sizeof(tc) / sizeof(TestCaseMsaI8); ++i) {
6958 run_msa_i8(SHF_B, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6959 run_msa_i8(SHF_H, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6960 run_msa_i8(SHF_W, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6961 }
6962 }
6963
6594 #undef __ 6964 #undef __
OLDNEW
« no previous file with comments | « test/cctest/test-assembler-mips.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698