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

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

Issue 2908753002: MIPS[64]: Implement insert.df and I8 instructions in simulator (Closed)
Patch Set: 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
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 5757 matching lines...) Expand 10 before | Expand all | Expand 10 after
5768 #endif 5768 #endif
5769 F4 f = FUNCTION_CAST<F4>(code->entry()); 5769 F4 f = FUNCTION_CAST<F4>(code->entry());
5770 5770
5771 Object* dummy = CALL_GENERATED_CODE(isolate, f, &t[0], &t[1], 0, 0, 0); 5771 Object* dummy = CALL_GENERATED_CODE(isolate, f, &t[0], &t[1], 0, 0, 0);
5772 USE(dummy); 5772 USE(dummy);
5773 5773
5774 CHECK_EQ(0x5555555555555555, t[0].d0); 5774 CHECK_EQ(0x5555555555555555, t[0].d0);
5775 CHECK_EQ(0x5555555555555555, t[1].d0); 5775 CHECK_EQ(0x5555555555555555, t[1].d0);
5776 } 5776 }
5777 5777
5778 typedef union {
5779 uint8_t b[16];
5780 uint16_t h[8];
5781 uint32_t w[4];
5782 uint64_t d[2];
5783 } msa_reg_t;
5784
5785 template <typename T>
5786 void run_msa_insert(int32_t rs_value, int n, msa_reg_t* w) {
5787 Isolate* isolate = CcTest::i_isolate();
5788 HandleScope scope(isolate);
5789
5790 MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes);
5791 CpuFeatureScope fscope(&assm, MIPS_SIMD);
5792
5793 __ li(t0, -1);
5794 __ li(t1, rs_value);
5795 __ fill_w(w0, t0);
5796
5797 if (std::is_same<T, int8_t>::value) {
5798 DCHECK(n < 16);
5799 __ insert_b(w0, n, t1);
5800 } else if (std::is_same<T, int16_t>::value) {
5801 DCHECK(n < 8);
5802 __ insert_h(w0, n, t1);
5803 } else if (std::is_same<T, int32_t>::value) {
5804 DCHECK(n < 4);
5805 __ insert_w(w0, n, t1);
5806 } else {
5807 UNREACHABLE();
5808 }
5809
5810 __ copy_u_w(t2, w0, 0);
5811 __ sw(t2, MemOperand(a0, 0));
5812 __ copy_u_w(t2, w0, 1);
5813 __ sw(t2, MemOperand(a0, 4));
5814 __ copy_u_w(t2, w0, 2);
5815 __ sw(t2, MemOperand(a0, 8));
5816 __ copy_u_w(t2, w0, 3);
5817 __ sw(t2, MemOperand(a0, 12));
5818
5819 __ jr(ra);
5820 __ nop();
5821
5822 CodeDesc desc;
5823 assm.GetCode(&desc);
5824 Handle<Code> code = isolate->factory()->NewCode(
5825 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
5826 #ifdef OBJECT_PRINT
5827 code->Print(std::cout);
5828 #endif
5829 F3 f = FUNCTION_CAST<F3>(code->entry());
5830
5831 (CALL_GENERATED_CODE(isolate, f, w, 0, 0, 0, 0));
5832 }
5833
5834 TEST(MSA_insert) {
5835 if (!IsMipsArchVariant(kMips32r6) || !CpuFeatures::IsSupported(MIPS_SIMD))
5836 return;
5837
5838 CcTest::InitializeVM();
5839
5840 struct TestCaseInsert {
5841 uint32_t input;
5842 int n;
5843 uint64_t exp_res_lo;
5844 uint64_t exp_res_hi;
5845 };
5846
5847 struct TestCaseInsert tc_b[] = {
5848 // input, n, exp_res_lo, exp_res_hi
5849 {0xa2, 13, 0xffffffffffffffffu, 0xffffa2ffffffffffu},
5850 {0x73, 10, 0xffffffffffffffffu, 0xffffffffff73ffffu},
5851 {0x3494, 5, 0xffff94ffffffffffu, 0xffffffffffffffffu},
5852 {0xa6b8, 1, 0xffffffffffffb8ffu, 0xffffffffffffffffu}};
5853
5854 for (size_t i = 0; i < sizeof(tc_b) / sizeof(TestCaseInsert); ++i) {
5855 msa_reg_t res;
5856 run_msa_insert<int8_t>(tc_b[i].input, tc_b[i].n, &res);
5857 CHECK_EQ(tc_b[i].exp_res_lo, res.d[0]);
5858 CHECK_EQ(tc_b[i].exp_res_hi, res.d[1]);
5859 }
5860
5861 struct TestCaseInsert tc_h[] = {
5862 // input, n, exp_res_lo, exp_res_hi
5863 {0x85a2, 7, 0xffffffffffffffffu, 0x85a2ffffffffffffu},
5864 {0xe873, 5, 0xffffffffffffffffu, 0xffffffffe873ffffu},
5865 {0x3494, 3, 0x3494ffffffffffffu, 0xffffffffffffffffu},
5866 {0xa6b8, 1, 0xffffffffa6b8ffffu, 0xffffffffffffffffu}};
5867
5868 for (size_t i = 0; i < sizeof(tc_h) / sizeof(TestCaseInsert); ++i) {
5869 msa_reg_t res;
5870 run_msa_insert<int16_t>(tc_h[i].input, tc_h[i].n, &res);
5871 CHECK_EQ(tc_h[i].exp_res_lo, res.d[0]);
5872 CHECK_EQ(tc_h[i].exp_res_hi, res.d[1]);
5873 }
5874
5875 struct TestCaseInsert tc_w[] = {
5876 // input, n, exp_res_lo, exp_res_hi
5877 {0xd2f085a2u, 3, 0xffffffffffffffffu, 0xd2f085a2ffffffffu},
5878 {0x4567e873u, 2, 0xffffffffffffffffu, 0xffffffff4567e873u},
5879 {0xacdb3494u, 1, 0xacdb3494ffffffffu, 0xffffffffffffffffu},
5880 {0x89aba6b8u, 0, 0xffffffff89aba6b8u, 0xffffffffffffffffu}};
5881
5882 for (size_t i = 0; i < sizeof(tc_w) / sizeof(TestCaseInsert); ++i) {
5883 msa_reg_t res;
5884 run_msa_insert<int32_t>(tc_w[i].input, tc_w[i].n, &res);
5885 CHECK_EQ(tc_w[i].exp_res_lo, res.d[0]);
5886 CHECK_EQ(tc_w[i].exp_res_hi, res.d[1]);
5887 }
5888 }
5889
5890 enum MsaI8Opcode {
Ilija.Pavlovic1 2017/05/29 07:31:21 Should this be moved in constants-mips.h?
dusan.simicic 2017/05/29 16:32:15 We already have similar constants in constants-mip
5891 kANDI,
5892 kORI,
5893 kNORI,
5894 kXORI,
5895 kBMNZI,
5896 kBMZI,
5897 kBSELI,
5898 kSHF_B,
5899 kSHF_H,
5900 kSHF_W
5901 };
5902
5903 struct ExpResShf {
5904 uint8_t i8;
5905 uint64_t lo;
5906 uint64_t hi;
5907 };
5908
5909 void run_msa_i8(int opcode, uint64_t ws_lo, uint64_t ws_hi, uint8_t i8) {
5910 Isolate* isolate = CcTest::i_isolate();
5911 HandleScope scope(isolate);
5912
5913 MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes);
5914 CpuFeatureScope fscope(&assm, MIPS_SIMD);
5915 msa_reg_t res;
5916 uint64_t wd_lo = 0xf35862e13e38f8b0;
5917 uint64_t wd_hi = 0x4f41ffdef2bfe636;
5918
5919 #define LOAD_W_REG(lo, hi, w_reg) \
5920 __ li(t0, static_cast<uint32_t>(lo & 0xffffffff)); \
5921 __ li(t1, static_cast<uint32_t>((lo >> 32) & 0xffffffff)); \
5922 __ insert_w(w_reg, 0, t0); \
5923 __ insert_w(w_reg, 1, t1); \
5924 __ li(t0, static_cast<uint32_t>(hi & 0xffffffff)); \
5925 __ li(t1, static_cast<uint32_t>((hi >> 32) & 0xffffffff)); \
5926 __ insert_w(w_reg, 2, t0); \
5927 __ insert_w(w_reg, 3, t1);
5928
5929 LOAD_W_REG(ws_lo, ws_hi, w0)
5930
5931 switch (opcode) {
5932 case kANDI:
5933 __ andi_b(w2, w0, i8);
5934 break;
5935 case kORI:
5936 __ ori_b(w2, w0, i8);
5937 break;
5938 case kNORI:
5939 __ nori_b(w2, w0, i8);
5940 break;
5941 case kXORI:
5942 __ xori_b(w2, w0, i8);
5943 break;
5944 case kBMNZI:
5945 LOAD_W_REG(wd_lo, wd_hi, w2);
5946 __ bmnzi_b(w2, w0, i8);
5947 break;
5948 case kBMZI:
5949 LOAD_W_REG(wd_lo, wd_hi, w2);
5950 __ bmzi_b(w2, w0, i8);
5951 break;
5952 case kBSELI:
5953 LOAD_W_REG(wd_lo, wd_hi, w2);
5954 __ bseli_b(w2, w0, i8);
5955 break;
5956 case kSHF_B:
5957 __ shf_b(w2, w0, i8);
5958 break;
5959 case kSHF_H:
5960 __ shf_h(w2, w0, i8);
5961 break;
5962 case kSHF_W:
5963 __ shf_w(w2, w0, i8);
5964 break;
5965 default:
5966 UNREACHABLE();
5967 }
5968
5969 __ copy_u_w(t2, w2, 0);
5970 __ sw(t2, MemOperand(a0, 0));
5971 __ copy_u_w(t2, w2, 1);
5972 __ sw(t2, MemOperand(a0, 4));
5973 __ copy_u_w(t2, w2, 2);
5974 __ sw(t2, MemOperand(a0, 8));
5975 __ copy_u_w(t2, w2, 3);
5976 __ sw(t2, MemOperand(a0, 12));
5977
5978 __ jr(ra);
5979 __ nop();
5980
5981 #undef LOAD_W_REG
5982
5983 CodeDesc desc;
5984 assm.GetCode(&desc);
5985 Handle<Code> code = isolate->factory()->NewCode(
5986 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
5987 #ifdef OBJECT_PRINT
5988 code->Print(std::cout);
5989 #endif
5990 F3 f = FUNCTION_CAST<F3>(code->entry());
5991
5992 (CALL_GENERATED_CODE(isolate, f, &res, 0, 0, 0, 0));
5993
5994 uint64_t mask = i8 * 0x0101010101010101ull;
5995 switch (opcode) {
5996 case kANDI:
5997 CHECK_EQ(ws_lo & mask, res.d[0]);
5998 CHECK_EQ(ws_hi & mask, res.d[1]);
5999 break;
6000 case kORI:
6001 CHECK_EQ(ws_lo | mask, res.d[0]);
6002 CHECK_EQ(ws_hi | mask, res.d[1]);
6003 break;
6004 case kNORI:
6005 CHECK_EQ(~(ws_lo | mask), res.d[0]);
6006 CHECK_EQ(~(ws_hi | mask), res.d[1]);
6007 break;
6008 case kXORI:
6009 CHECK_EQ(ws_lo ^ mask, res.d[0]);
6010 CHECK_EQ(ws_hi ^ mask, res.d[1]);
6011 break;
6012 case kBMNZI:
6013 CHECK_EQ((ws_lo & mask) | (wd_lo & ~mask), res.d[0]);
6014 CHECK_EQ((ws_hi & mask) | (wd_hi & ~mask), res.d[1]);
6015 break;
6016 case kBMZI:
6017 CHECK_EQ((ws_lo & ~mask) | (wd_lo & mask), res.d[0]);
6018 CHECK_EQ((ws_hi & ~mask) | (wd_hi & mask), res.d[1]);
6019 break;
6020 case kBSELI:
6021 CHECK_EQ((ws_lo & ~wd_lo) | (mask & wd_lo), res.d[0]);
6022 CHECK_EQ((ws_hi & ~wd_hi) | (mask & wd_hi), res.d[1]);
6023 break;
6024 case kSHF_B: {
6025 struct ExpResShf exp_b[] = {
6026 // i8, exp_lo, exp_hi
6027 {0xffu, 0x11111111b9b9b9b9, 0xf7f7f7f7c8c8c8c8},
6028 {0x0u, 0x62626262dfdfdfdf, 0xd6d6d6d6c8c8c8c8},
6029 {0xe4u, 0xf35862e13e38f8b0, 0x4f41ffdef2bfe636},
6030 {0x1bu, 0x1b756911c3d9a7b9, 0xae94a5f79c8aefc8},
6031 {0xb1u, 0x662b6253e8c4df12, 0x0d3ad6803f8bc88b},
6032 {0x4eu, 0x62e1f358f8b03e38, 0xffde4f41e636f2bf},
6033 {0x27u, 0x1b697511c3a7d9b9, 0xaea594f79cef8ac8}};
6034 for (size_t i = 0; i < sizeof(exp_b) / sizeof(ExpResShf); ++i) {
6035 if (exp_b[i].i8 == i8) {
6036 CHECK_EQ(exp_b[i].lo, res.d[0]);
6037 CHECK_EQ(exp_b[i].hi, res.d[1]);
6038 }
6039 }
6040 } break;
6041 case kSHF_H: {
6042 struct ExpResShf exp_h[] = {
6043 // i8, exp_lo, exp_hi
6044 {0xffu, 0x1169116911691169, 0xf7a5f7a5f7a5f7a5},
6045 {0x0u, 0x12df12df12df12df, 0x8bc88bc88bc88bc8},
6046 {0xe4u, 0xf35862e13e38f8b0, 0x4f41ffdef2bfe636},
6047 {0x1bu, 0xd9c3b9a7751b1169, 0x8a9cc8ef94aef7a5},
6048 {0xb1u, 0x53622b6612dfc4e8, 0x80d63a0d8bc88b3f},
6049 {0x4eu, 0x3e38f8b0f35862e1, 0xf2bfe6364f41ffde},
6050 {0x27u, 0xd9c3751bb9a71169, 0x8a9c94aec8eff7a5}};
6051 for (size_t i = 0; i < sizeof(exp_h) / sizeof(ExpResShf); ++i) {
6052 if (exp_h[i].i8 == i8) {
6053 CHECK_EQ(exp_h[i].lo, res.d[0]);
6054 CHECK_EQ(exp_h[i].hi, res.d[1]);
6055 }
6056 }
6057 } break;
6058 case kSHF_W: {
6059 struct ExpResShf exp_w[] = {
6060 // i8, exp_lo, exp_hi
6061 {0xffu, 0xf7a594aef7a594ae, 0xf7a594aef7a594ae},
6062 {0x0u, 0xc4e812dfc4e812df, 0xc4e812dfc4e812df},
6063 {0xe4u, 0xf35862e13e38f8b0, 0x4f41ffdef2bfe636},
6064 {0x1bu, 0xc8ef8a9cf7a594ae, 0xb9a7d9c31169751b},
6065 {0xb1u, 0xc4e812df2b665362, 0x8b3f8bc83a0d80d6},
6066 {0x4eu, 0x4f41ffdef2bfe636, 0xf35862e13e38f8b0},
6067 {0x27u, 0x1169751bf7a594ae, 0xb9a7d9c3c8ef8a9c}};
6068 for (size_t i = 0; i < sizeof(exp_w) / sizeof(ExpResShf); ++i) {
6069 if (exp_w[i].i8 == i8) {
6070 CHECK_EQ(exp_w[i].lo, res.d[0]);
6071 CHECK_EQ(exp_w[i].hi, res.d[1]);
6072 }
6073 }
6074 } break;
6075 default:
6076 UNREACHABLE();
6077 }
6078 }
6079
6080 struct TestCaseMsaI8 {
6081 uint64_t input_lo;
6082 uint64_t input_hi;
6083 uint8_t i8;
6084 };
6085
6086 TEST(MSA_andi_ori_nori_xori) {
6087 if (!IsMipsArchVariant(kMips32r6) || !CpuFeatures::IsSupported(MIPS_SIMD))
6088 return;
6089
6090 CcTest::InitializeVM();
6091
6092 struct TestCaseMsaI8 tc[] = {// input_lo, input_hi, i8
6093 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0xffu},
6094 {0x2b665362c4e812df, 0x3a0d80d68b3f8bc8, 0x0u},
6095 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0x3bu},
6096 {0x2b665362c4e812df, 0x3a0d80d68b3f8bc8, 0xd9u}};
6097
6098 for (size_t i = 0; i < sizeof(tc) / sizeof(TestCaseMsaI8); ++i) {
6099 run_msa_i8(kANDI, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6100 run_msa_i8(kORI, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6101 run_msa_i8(kNORI, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6102 run_msa_i8(kXORI, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6103 }
6104 }
6105
6106 TEST(MSA_bmnzi_bmzi_bseli) {
6107 if (!IsMipsArchVariant(kMips32r6) || !CpuFeatures::IsSupported(MIPS_SIMD))
6108 return;
6109
6110 CcTest::InitializeVM();
6111
6112 struct TestCaseMsaI8 tc[] = {// input_lo, input_hi, i8
6113 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0xffu},
6114 {0x2b665362c4e812df, 0x3a0d80d68b3f8bc8, 0x0u},
6115 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0x3bu},
6116 {0x2b665362c4e812df, 0x3a0d80d68b3f8bc8, 0xd9u}};
6117
6118 for (size_t i = 0; i < sizeof(tc) / sizeof(TestCaseMsaI8); ++i) {
6119 run_msa_i8(kBMNZI, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6120 run_msa_i8(kBMZI, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6121 run_msa_i8(kBSELI, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6122 }
6123 }
6124
6125 TEST(MSA_shf) {
6126 if (!IsMipsArchVariant(kMips32r6) || !CpuFeatures::IsSupported(MIPS_SIMD))
6127 return;
6128
6129 CcTest::InitializeVM();
6130
6131 struct TestCaseMsaI8 tc[] = {
6132 // input_lo, input_hi, i8
6133 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0xffu}, // 3333
6134 {0x2b665362c4e812df, 0x3a0d80d68b3f8bc8, 0x0u}, // 0000
6135 {0xf35862e13e38f8b0, 0x4f41ffdef2bfe636, 0xe4u}, // 3210
6136 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0x1bu}, // 0123
6137 {0x2b665362c4e812df, 0x3a0d80d68b3f8bc8, 0xb1u}, // 2301
6138 {0xf35862e13e38f8b0, 0x4f41ffdef2bfe636, 0x4eu}, // 1032
6139 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0x27u} // 0213
6140 };
6141
6142 for (size_t i = 0; i < sizeof(tc) / sizeof(TestCaseMsaI8); ++i) {
6143 run_msa_i8(kSHF_B, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6144 run_msa_i8(kSHF_H, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6145 run_msa_i8(kSHF_W, tc[i].input_lo, tc[i].input_hi, tc[i].i8);
6146 }
6147 }
6148
5778 #undef __ 6149 #undef __
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698