OLD | NEW |
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 Loading... |
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 struct ExpResShf { |
| 5891 uint8_t i8; |
| 5892 uint64_t lo; |
| 5893 uint64_t hi; |
| 5894 }; |
| 5895 |
| 5896 void run_msa_i8(SecondaryField opcode, uint64_t ws_lo, uint64_t ws_hi, |
| 5897 uint8_t i8) { |
| 5898 Isolate* isolate = CcTest::i_isolate(); |
| 5899 HandleScope scope(isolate); |
| 5900 |
| 5901 MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); |
| 5902 CpuFeatureScope fscope(&assm, MIPS_SIMD); |
| 5903 msa_reg_t res; |
| 5904 uint64_t wd_lo = 0xf35862e13e38f8b0; |
| 5905 uint64_t wd_hi = 0x4f41ffdef2bfe636; |
| 5906 |
| 5907 #define LOAD_W_REG(lo, hi, w_reg) \ |
| 5908 __ li(t0, static_cast<uint32_t>(lo & 0xffffffff)); \ |
| 5909 __ li(t1, static_cast<uint32_t>((lo >> 32) & 0xffffffff)); \ |
| 5910 __ insert_w(w_reg, 0, t0); \ |
| 5911 __ insert_w(w_reg, 1, t1); \ |
| 5912 __ li(t0, static_cast<uint32_t>(hi & 0xffffffff)); \ |
| 5913 __ li(t1, static_cast<uint32_t>((hi >> 32) & 0xffffffff)); \ |
| 5914 __ insert_w(w_reg, 2, t0); \ |
| 5915 __ insert_w(w_reg, 3, t1); |
| 5916 |
| 5917 LOAD_W_REG(ws_lo, ws_hi, w0) |
| 5918 |
| 5919 switch (opcode) { |
| 5920 case ANDI_B: |
| 5921 __ andi_b(w2, w0, i8); |
| 5922 break; |
| 5923 case ORI_B: |
| 5924 __ ori_b(w2, w0, i8); |
| 5925 break; |
| 5926 case NORI_B: |
| 5927 __ nori_b(w2, w0, i8); |
| 5928 break; |
| 5929 case XORI_B: |
| 5930 __ xori_b(w2, w0, i8); |
| 5931 break; |
| 5932 case BMNZI_B: |
| 5933 LOAD_W_REG(wd_lo, wd_hi, w2); |
| 5934 __ bmnzi_b(w2, w0, i8); |
| 5935 break; |
| 5936 case BMZI_B: |
| 5937 LOAD_W_REG(wd_lo, wd_hi, w2); |
| 5938 __ bmzi_b(w2, w0, i8); |
| 5939 break; |
| 5940 case BSELI_B: |
| 5941 LOAD_W_REG(wd_lo, wd_hi, w2); |
| 5942 __ bseli_b(w2, w0, i8); |
| 5943 break; |
| 5944 case SHF_B: |
| 5945 __ shf_b(w2, w0, i8); |
| 5946 break; |
| 5947 case SHF_H: |
| 5948 __ shf_h(w2, w0, i8); |
| 5949 break; |
| 5950 case SHF_W: |
| 5951 __ shf_w(w2, w0, i8); |
| 5952 break; |
| 5953 default: |
| 5954 UNREACHABLE(); |
| 5955 } |
| 5956 |
| 5957 __ copy_u_w(t2, w2, 0); |
| 5958 __ sw(t2, MemOperand(a0, 0)); |
| 5959 __ copy_u_w(t2, w2, 1); |
| 5960 __ sw(t2, MemOperand(a0, 4)); |
| 5961 __ copy_u_w(t2, w2, 2); |
| 5962 __ sw(t2, MemOperand(a0, 8)); |
| 5963 __ copy_u_w(t2, w2, 3); |
| 5964 __ sw(t2, MemOperand(a0, 12)); |
| 5965 |
| 5966 __ jr(ra); |
| 5967 __ nop(); |
| 5968 |
| 5969 #undef LOAD_W_REG |
| 5970 |
| 5971 CodeDesc desc; |
| 5972 assm.GetCode(&desc); |
| 5973 Handle<Code> code = isolate->factory()->NewCode( |
| 5974 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 5975 #ifdef OBJECT_PRINT |
| 5976 code->Print(std::cout); |
| 5977 #endif |
| 5978 F3 f = FUNCTION_CAST<F3>(code->entry()); |
| 5979 |
| 5980 (CALL_GENERATED_CODE(isolate, f, &res, 0, 0, 0, 0)); |
| 5981 |
| 5982 uint64_t mask = i8 * 0x0101010101010101ull; |
| 5983 switch (opcode) { |
| 5984 case ANDI_B: |
| 5985 CHECK_EQ(ws_lo & mask, res.d[0]); |
| 5986 CHECK_EQ(ws_hi & mask, res.d[1]); |
| 5987 break; |
| 5988 case ORI_B: |
| 5989 CHECK_EQ(ws_lo | mask, res.d[0]); |
| 5990 CHECK_EQ(ws_hi | mask, res.d[1]); |
| 5991 break; |
| 5992 case NORI_B: |
| 5993 CHECK_EQ(~(ws_lo | mask), res.d[0]); |
| 5994 CHECK_EQ(~(ws_hi | mask), res.d[1]); |
| 5995 break; |
| 5996 case XORI_B: |
| 5997 CHECK_EQ(ws_lo ^ mask, res.d[0]); |
| 5998 CHECK_EQ(ws_hi ^ mask, res.d[1]); |
| 5999 break; |
| 6000 case BMNZI_B: |
| 6001 CHECK_EQ((ws_lo & mask) | (wd_lo & ~mask), res.d[0]); |
| 6002 CHECK_EQ((ws_hi & mask) | (wd_hi & ~mask), res.d[1]); |
| 6003 break; |
| 6004 case BMZI_B: |
| 6005 CHECK_EQ((ws_lo & ~mask) | (wd_lo & mask), res.d[0]); |
| 6006 CHECK_EQ((ws_hi & ~mask) | (wd_hi & mask), res.d[1]); |
| 6007 break; |
| 6008 case BSELI_B: |
| 6009 CHECK_EQ((ws_lo & ~wd_lo) | (mask & wd_lo), res.d[0]); |
| 6010 CHECK_EQ((ws_hi & ~wd_hi) | (mask & wd_hi), res.d[1]); |
| 6011 break; |
| 6012 case SHF_B: { |
| 6013 struct ExpResShf exp_b[] = { |
| 6014 // i8, exp_lo, exp_hi |
| 6015 {0xffu, 0x11111111b9b9b9b9, 0xf7f7f7f7c8c8c8c8}, |
| 6016 {0x0u, 0x62626262dfdfdfdf, 0xd6d6d6d6c8c8c8c8}, |
| 6017 {0xe4u, 0xf35862e13e38f8b0, 0x4f41ffdef2bfe636}, |
| 6018 {0x1bu, 0x1b756911c3d9a7b9, 0xae94a5f79c8aefc8}, |
| 6019 {0xb1u, 0x662b6253e8c4df12, 0x0d3ad6803f8bc88b}, |
| 6020 {0x4eu, 0x62e1f358f8b03e38, 0xffde4f41e636f2bf}, |
| 6021 {0x27u, 0x1b697511c3a7d9b9, 0xaea594f79cef8ac8}}; |
| 6022 for (size_t i = 0; i < sizeof(exp_b) / sizeof(ExpResShf); ++i) { |
| 6023 if (exp_b[i].i8 == i8) { |
| 6024 CHECK_EQ(exp_b[i].lo, res.d[0]); |
| 6025 CHECK_EQ(exp_b[i].hi, res.d[1]); |
| 6026 } |
| 6027 } |
| 6028 } break; |
| 6029 case SHF_H: { |
| 6030 struct ExpResShf exp_h[] = { |
| 6031 // i8, exp_lo, exp_hi |
| 6032 {0xffu, 0x1169116911691169, 0xf7a5f7a5f7a5f7a5}, |
| 6033 {0x0u, 0x12df12df12df12df, 0x8bc88bc88bc88bc8}, |
| 6034 {0xe4u, 0xf35862e13e38f8b0, 0x4f41ffdef2bfe636}, |
| 6035 {0x1bu, 0xd9c3b9a7751b1169, 0x8a9cc8ef94aef7a5}, |
| 6036 {0xb1u, 0x53622b6612dfc4e8, 0x80d63a0d8bc88b3f}, |
| 6037 {0x4eu, 0x3e38f8b0f35862e1, 0xf2bfe6364f41ffde}, |
| 6038 {0x27u, 0xd9c3751bb9a71169, 0x8a9c94aec8eff7a5}}; |
| 6039 for (size_t i = 0; i < sizeof(exp_h) / sizeof(ExpResShf); ++i) { |
| 6040 if (exp_h[i].i8 == i8) { |
| 6041 CHECK_EQ(exp_h[i].lo, res.d[0]); |
| 6042 CHECK_EQ(exp_h[i].hi, res.d[1]); |
| 6043 } |
| 6044 } |
| 6045 } break; |
| 6046 case SHF_W: { |
| 6047 struct ExpResShf exp_w[] = { |
| 6048 // i8, exp_lo, exp_hi |
| 6049 {0xffu, 0xf7a594aef7a594ae, 0xf7a594aef7a594ae}, |
| 6050 {0x0u, 0xc4e812dfc4e812df, 0xc4e812dfc4e812df}, |
| 6051 {0xe4u, 0xf35862e13e38f8b0, 0x4f41ffdef2bfe636}, |
| 6052 {0x1bu, 0xc8ef8a9cf7a594ae, 0xb9a7d9c31169751b}, |
| 6053 {0xb1u, 0xc4e812df2b665362, 0x8b3f8bc83a0d80d6}, |
| 6054 {0x4eu, 0x4f41ffdef2bfe636, 0xf35862e13e38f8b0}, |
| 6055 {0x27u, 0x1169751bf7a594ae, 0xb9a7d9c3c8ef8a9c}}; |
| 6056 for (size_t i = 0; i < sizeof(exp_w) / sizeof(ExpResShf); ++i) { |
| 6057 if (exp_w[i].i8 == i8) { |
| 6058 CHECK_EQ(exp_w[i].lo, res.d[0]); |
| 6059 CHECK_EQ(exp_w[i].hi, res.d[1]); |
| 6060 } |
| 6061 } |
| 6062 } break; |
| 6063 default: |
| 6064 UNREACHABLE(); |
| 6065 } |
| 6066 } |
| 6067 |
| 6068 struct TestCaseMsaI8 { |
| 6069 uint64_t input_lo; |
| 6070 uint64_t input_hi; |
| 6071 uint8_t i8; |
| 6072 }; |
| 6073 |
| 6074 TEST(MSA_andi_ori_nori_xori) { |
| 6075 if (!IsMipsArchVariant(kMips32r6) || !CpuFeatures::IsSupported(MIPS_SIMD)) |
| 6076 return; |
| 6077 |
| 6078 CcTest::InitializeVM(); |
| 6079 |
| 6080 struct TestCaseMsaI8 tc[] = {// input_lo, input_hi, i8 |
| 6081 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0xffu}, |
| 6082 {0x2b665362c4e812df, 0x3a0d80d68b3f8bc8, 0x0u}, |
| 6083 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0x3bu}, |
| 6084 {0x2b665362c4e812df, 0x3a0d80d68b3f8bc8, 0xd9u}}; |
| 6085 |
| 6086 for (size_t i = 0; i < sizeof(tc) / sizeof(TestCaseMsaI8); ++i) { |
| 6087 run_msa_i8(ANDI_B, tc[i].input_lo, tc[i].input_hi, tc[i].i8); |
| 6088 run_msa_i8(ORI_B, tc[i].input_lo, tc[i].input_hi, tc[i].i8); |
| 6089 run_msa_i8(NORI_B, tc[i].input_lo, tc[i].input_hi, tc[i].i8); |
| 6090 run_msa_i8(XORI_B, tc[i].input_lo, tc[i].input_hi, tc[i].i8); |
| 6091 } |
| 6092 } |
| 6093 |
| 6094 TEST(MSA_bmnzi_bmzi_bseli) { |
| 6095 if (!IsMipsArchVariant(kMips32r6) || !CpuFeatures::IsSupported(MIPS_SIMD)) |
| 6096 return; |
| 6097 |
| 6098 CcTest::InitializeVM(); |
| 6099 |
| 6100 struct TestCaseMsaI8 tc[] = {// input_lo, input_hi, i8 |
| 6101 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0xffu}, |
| 6102 {0x2b665362c4e812df, 0x3a0d80d68b3f8bc8, 0x0u}, |
| 6103 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0x3bu}, |
| 6104 {0x2b665362c4e812df, 0x3a0d80d68b3f8bc8, 0xd9u}}; |
| 6105 |
| 6106 for (size_t i = 0; i < sizeof(tc) / sizeof(TestCaseMsaI8); ++i) { |
| 6107 run_msa_i8(BMNZI_B, tc[i].input_lo, tc[i].input_hi, tc[i].i8); |
| 6108 run_msa_i8(BMZI_B, tc[i].input_lo, tc[i].input_hi, tc[i].i8); |
| 6109 run_msa_i8(BSELI_B, tc[i].input_lo, tc[i].input_hi, tc[i].i8); |
| 6110 } |
| 6111 } |
| 6112 |
| 6113 TEST(MSA_shf) { |
| 6114 if (!IsMipsArchVariant(kMips32r6) || !CpuFeatures::IsSupported(MIPS_SIMD)) |
| 6115 return; |
| 6116 |
| 6117 CcTest::InitializeVM(); |
| 6118 |
| 6119 struct TestCaseMsaI8 tc[] = { |
| 6120 // input_lo, input_hi, i8 |
| 6121 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0xffu}, // 3333 |
| 6122 {0x2b665362c4e812df, 0x3a0d80d68b3f8bc8, 0x0u}, // 0000 |
| 6123 {0xf35862e13e38f8b0, 0x4f41ffdef2bfe636, 0xe4u}, // 3210 |
| 6124 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0x1bu}, // 0123 |
| 6125 {0x2b665362c4e812df, 0x3a0d80d68b3f8bc8, 0xb1u}, // 2301 |
| 6126 {0xf35862e13e38f8b0, 0x4f41ffdef2bfe636, 0x4eu}, // 1032 |
| 6127 {0x1169751bb9a7d9c3, 0xf7a594aec8ef8a9c, 0x27u} // 0213 |
| 6128 }; |
| 6129 |
| 6130 for (size_t i = 0; i < sizeof(tc) / sizeof(TestCaseMsaI8); ++i) { |
| 6131 run_msa_i8(SHF_B, tc[i].input_lo, tc[i].input_hi, tc[i].i8); |
| 6132 run_msa_i8(SHF_H, tc[i].input_lo, tc[i].input_hi, tc[i].i8); |
| 6133 run_msa_i8(SHF_W, tc[i].input_lo, tc[i].input_hi, tc[i].i8); |
| 6134 } |
| 6135 } |
| 6136 |
5778 #undef __ | 6137 #undef __ |
OLD | NEW |