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 5053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5064 if (num_instr > 0) { | 5064 if (num_instr > 0) { |
5065 CHECK_EQ(assm.InstructionsGeneratedSince(&code_start), num_instr); | 5065 CHECK_EQ(assm.InstructionsGeneratedSince(&code_start), num_instr); |
5066 } | 5066 } |
5067 __ jr(ra); | 5067 __ jr(ra); |
5068 __ nop(); | 5068 __ nop(); |
5069 | 5069 |
5070 CodeDesc desc; | 5070 CodeDesc desc; |
5071 assm.GetCode(isolate, &desc); | 5071 assm.GetCode(isolate, &desc); |
5072 Handle<Code> code = isolate->factory()->NewCode( | 5072 Handle<Code> code = isolate->factory()->NewCode( |
5073 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | 5073 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 5074 #ifdef OBJECT_PRINT |
| 5075 code->Print(std::cout); |
| 5076 #endif |
5074 F2 f = FUNCTION_CAST<F2>(code->entry()); | 5077 F2 f = FUNCTION_CAST<F2>(code->entry()); |
5075 | 5078 |
5076 uint64_t res = reinterpret_cast<uint64_t>( | 5079 uint64_t res = reinterpret_cast<uint64_t>( |
5077 CALL_GENERATED_CODE(isolate, f, 0, 0, 0, 0, 0)); | 5080 CALL_GENERATED_CODE(isolate, f, 0, 0, 0, 0, 0)); |
5078 | 5081 |
5079 return res; | 5082 return res; |
5080 } | 5083 } |
5081 | 5084 |
5082 | 5085 |
5083 TEST(li_macro) { | 5086 TEST(li_macro) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5116 // r2 - daddiu + dsrl32 | 5119 // r2 - daddiu + dsrl32 |
5117 // r6 - daddiu + dahi | 5120 // r6 - daddiu + dahi |
5118 {0x00000000fffffffe, 3, 2}, // max_uint32 - 1 | 5121 {0x00000000fffffffe, 3, 2}, // max_uint32 - 1 |
5119 // r2 - lui + ori + dsll | 5122 // r2 - lui + ori + dsll |
5120 // r6 - daddiu + dahi | 5123 // r6 - daddiu + dahi |
5121 {0x00ffff000000fffe, 3, 3}, | 5124 {0x00ffff000000fffe, 3, 3}, |
5122 // ori + dsll32 + ori | 5125 // ori + dsll32 + ori |
5123 {0x00000001fffffffe, 4, 2}, // max_uint32 << 1 | 5126 {0x00000001fffffffe, 4, 2}, // max_uint32 << 1 |
5124 // r2 - lui + ori + dsll + ori | 5127 // r2 - lui + ori + dsll + ori |
5125 // r6 - daddiu + dahi | 5128 // r6 - daddiu + dahi |
5126 {0x0000fffffffffffe, 5, 2}, // max_uint48 - 1 | 5129 {0x0000fffffffffffe, 4, 2}, // max_uint48 - 1 |
5127 // r2 - ori + dsll + ori + dsll + ori | 5130 // r2 - daddiu + dsll32 + ori + dsubu |
| 5131 // Loading imm directly would require ori + dsll + ori + dsll + ori. |
| 5132 // Optimized by loading -imm and using dsubu to get imm. |
5128 // r6 - daddiu + dati | 5133 // r6 - daddiu + dati |
5129 {0xffffffff00000000, 2, 2}, // max_uint32 << 32 | 5134 {0xffffffff00000000, 2, 2}, // max_uint32 << 32 |
5130 // r2 - daddiu + dsll32 | 5135 // r2 - daddiu + dsll32 |
5131 // r6 - ori + dahi | 5136 // r6 - ori + dahi |
5132 // We need ori to clear register before loading value using dahi. | 5137 // We need ori to clear register before loading value using dahi. |
5133 {0xffffffff80000000, 1, 1}, // min_int32 | 5138 {0xffffffff80000000, 1, 1}, // min_int32 |
5134 // The test case above generates lui instruction. | 5139 // The test case above generates lui instruction. |
5135 {0x0000000080000000, 2, 2}, // max_int32 + 1 | 5140 {0x0000000080000000, 2, 2}, // max_int32 + 1 |
5136 // r2 - ori + dsll | 5141 // r2 - ori + dsll |
5137 // r6 - lui + dahi | 5142 // r6 - lui + dahi |
5138 {0x0000800000000000, 2, 2}, | 5143 {0x0000800000000000, 2, 2}, |
5139 // ori + dsll32 | 5144 // ori + dsll32 |
5140 {0xffff800000000000, 2, 2}, | 5145 {0xffff800000000000, 2, 2}, |
5141 // r2 - daddiu + dsll32 | 5146 // r2 - daddiu + dsll32 |
5142 // r6 - ori + dahi | 5147 // r6 - ori + dahi |
5143 {0xffff80000000ffff, 3, 2}, | 5148 {0xffff80000000ffff, 3, 2}, |
5144 // r2 - daddiu + dsll32 + ori | 5149 // r2 - daddiu + dsll32 + ori |
5145 // r6 - ori + dahi | 5150 // r6 - ori + dahi |
5146 {0xffffff123000ffff, 3, 3}, | 5151 {0xffffff123000ffff, 3, 3}, |
5147 // daddiu + dsll + ori | 5152 // daddiu + dsll + ori |
5148 {0xffff00000000ffff, 3, 2}, | 5153 {0xffff00000000ffff, 3, 2}, |
5149 // r2 - daddiu + dsll32 + ori | 5154 // r2 - daddiu + dsll32 + ori |
5150 // r6 - ori + dati | 5155 // r6 - ori + dati |
5151 {0xffff8000ffff0000, 3, 2}, | 5156 {0xffff8000ffff0000, 3, 2}, |
5152 // r2 - lui + ori + dsll | 5157 // r2 - lui + ori + dsll |
5153 // r6 - lui + dahi | 5158 // r6 - lui + dahi |
| 5159 {0x0000ffffffff0000, 4, 2}, |
| 5160 // r2 - ori + dsll + ori + dsll |
| 5161 // r6 - lui + dati |
5154 {0x1234ffff80000000, 3, 2}, | 5162 {0x1234ffff80000000, 3, 2}, |
5155 // r2 - lui + ori + dsll | 5163 // r2 - lui + ori + dsll |
5156 // r6 - lui + dati | 5164 // r6 - lui + dati |
5157 {0x1234ffff80010000, 5, 2}, | 5165 {0x1234ffff80010000, 5, 2}, |
5158 // r2 - lui + ori + dsll + ori + dsll | 5166 // r2 - lui + ori + dsll + ori + dsll |
5159 // r6 - lui + dati | 5167 // r6 - lui + dati |
5160 {0xffff8000ffff8000, 2, 2}, | 5168 {0xffff8000ffff8000, 2, 2}, |
5161 // r2 - daddiu + dinsu | 5169 // r2 - daddiu + dinsu |
5162 // r6 - daddiu + dahi | 5170 // r6 - daddiu + dahi |
5163 {0xffff0000ffff8000, 5, 3}, | 5171 {0xffff0000ffff8000, 4, 3}, |
5164 // r2 - lui + dsll + ori + dsll + ori | 5172 // r2 - ori + dsll32 + ori + dsubu |
| 5173 // Loading imm directly would require lui + dsll + ori + dsll + ori. |
| 5174 // Optimized by loading -imm and using dsubu to get imm. |
5165 // r6 - daddiu + dahi + dati | 5175 // r6 - daddiu + dahi + dati |
5166 {0x8000000080000000, 2, 2}, | 5176 {0x8000000080000000, 2, 2}, |
5167 // lui + dinsu | 5177 // lui + dinsu |
5168 {0xabcd0000abcd0000, 2, 2}, | 5178 {0xabcd0000abcd0000, 2, 2}, |
5169 // lui + dinsu | 5179 // lui + dinsu |
5170 {0x8000800080008000, 3, 3}, | 5180 {0x8000800080008000, 3, 3}, |
5171 // lui + ori + dinsu | 5181 // lui + ori + dinsu |
5172 {0xabcd1234abcd1234, 3, 3}, | 5182 {0xabcd1234abcd1234, 3, 3}, |
5173 // The test case above generates lui + ori + dinsu instruction sequence. | 5183 // The test case above generates lui + ori + dinsu instruction sequence. |
5174 {0xffff800080008000, 4, 3}, | 5184 {0xffff800080008000, 4, 3}, |
5175 // r2 - lui + ori + dsll + ori | 5185 // r2 - lui + ori + dsll + ori |
5176 // r6 - lui + ori + dahi | 5186 // r6 - lui + ori + dahi |
5177 {0xffffabcd, 3, 2}, | 5187 {0xffffabcd, 3, 2}, |
5178 // r2 - ori + dsll + ori | 5188 // r2 - ori + dsll + ori |
5179 // r6 - daddiu + dahi | 5189 // r6 - daddiu + dahi |
5180 {0x1ffffabcd, 4, 2}, | 5190 {0x1ffffabcd, 4, 2}, |
5181 // r2 - lui + ori + dsll + ori | 5191 // r2 - lui + ori + dsll + ori |
5182 // r6 - daddiu + dahi | 5192 // r6 - daddiu + dahi |
5183 {0xffffffffabcd, 5, 2}, | 5193 {0xffffffffabcd, 4, 2}, |
5184 // r2 - ori + dsll + ori + dsll + ori | 5194 // r2 - daddiu + dsll32 + ori + dsubu |
| 5195 // Loading imm directly would require ori + dsll + ori + dsll + ori. |
| 5196 // Optimized by loading -imm and using dsubu to get imm. |
5185 // r6 - daddiu + dati | 5197 // r6 - daddiu + dati |
5186 {0x1ffffffffabcd, 6, 2}, | 5198 {0x1ffffffffabcd, 4, 2}, |
5187 // r2 - lui + ori + dsll + ori + dsll + ori | 5199 // r2 - daddiu + dsll32 + ori + dsubu |
| 5200 // Loading imm directly would require lui + ori + dsll + ori + dsll + ori. |
| 5201 // Optimized by loading -imm and using dsubu to get imm. |
5188 // r6 - daddiu + dati | 5202 // r6 - daddiu + dati |
5189 {0xffff7fff80010000, 5, 2}, | 5203 {0xffff7fff80010000, 5, 2}, |
5190 // r2 - lui + ori + dsll + ori + dsll | 5204 // r2 - lui + ori + dsll + ori + dsll |
5191 // r6 - lui + dahi | 5205 // r6 - lui + dahi |
5192 // Here lui sets high 32 bits to 1 so dahi can be used to get target | 5206 // Here lui sets high 32 bits to 1 so dahi can be used to get target |
5193 // value. | 5207 // value. |
5194 {0x00007fff7fff0000, 3, 2}, | 5208 {0x00007fff7fff0000, 3, 2}, |
5195 // r2 - lui + ori + dsll | 5209 // r2 - lui + ori + dsll |
5196 // r6 - lui + dahi | 5210 // r6 - lui + dahi |
5197 // High 32 bits are not set so dahi can be used to get target value. | 5211 // High 32 bits are not set so dahi can be used to get target value. |
5198 {0xffff7fff7fff0000, 5, 3}, | 5212 {0xffff7fff7fff0000, 5, 3}, |
5199 // r2 - lui + ori + dsll + ori + dsll | 5213 // r2 - lui + ori + dsll + ori + dsll |
5200 // r6 - lui + dahi + dati | 5214 // r6 - lui + dahi + dati |
5201 // High 32 bits are not set so just dahi can't be used to get target | 5215 // High 32 bits are not set so just dahi can't be used to get target |
5202 // value. | 5216 // value. |
5203 {0x00007fff80010000, 3, 3}, | 5217 {0x00007fff80010000, 3, 3}, |
5204 // r2 - lui + ori + dsll | 5218 // r2 - lui + ori + dsll |
5205 // r6 - lui + ori + dsll | 5219 // r6 - lui + ori + dsll |
5206 // High 32 bits are set so can't just use lui + dahi to get target value. | 5220 // High 32 bits are set so can't just use lui + dahi to get target value. |
5207 {0x1234abcd87654321, 6, 4}, | 5221 {0x1234abcd87654321, 6, 4}, |
5208 // The test case above generates: | 5222 // The test case above generates: |
5209 // r2 - lui + ori + dsll + ori + dsll + ori instruction sequence, | 5223 // r2 - lui + ori + dsll + ori + dsll + ori instruction sequence, |
5210 // r6 - lui + ori + dahi + dati. | 5224 // r6 - lui + ori + dahi + dati. |
5211 // Load using full instruction sequence. | 5225 // Load using full instruction sequence. |
| 5226 {0xffff0000ffffffff, 3, 3}, |
| 5227 // r2 - ori + dsll32 + nor |
| 5228 // Loading imm directly would require lui + dsll + ori + dsll + ori. |
| 5229 // Optimized by loading ~imm and using nor to get imm. Loading -imm would |
| 5230 // require one instruction more. |
| 5231 // r6 - daddiu + dahi + dati |
5212 }; | 5232 }; |
5213 | 5233 |
5214 size_t nr_test_cases = sizeof(tc) / sizeof(TestCase_li); | 5234 size_t nr_test_cases = sizeof(tc) / sizeof(TestCase_li); |
5215 for (size_t i = 0; i < nr_test_cases; ++i) { | 5235 for (size_t i = 0; i < nr_test_cases; ++i) { |
5216 if (kArchVariant == kMips64r2) { | 5236 if (kArchVariant == kMips64r2) { |
5217 CHECK_EQ(tc[i].imm, | 5237 CHECK_EQ(tc[i].imm, |
5218 run_li_macro(tc[i].imm, OPTIMIZE_SIZE, tc[i].r2_num_instr)); | 5238 run_li_macro(tc[i].imm, OPTIMIZE_SIZE, tc[i].r2_num_instr)); |
5219 } else { | 5239 } else { |
5220 CHECK_EQ(tc[i].imm, | 5240 CHECK_EQ(tc[i].imm, |
5221 run_li_macro(tc[i].imm, OPTIMIZE_SIZE, tc[i].r6_num_instr)); | 5241 run_li_macro(tc[i].imm, OPTIMIZE_SIZE, tc[i].r6_num_instr)); |
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6192 __ bind(&code_start); | 6212 __ bind(&code_start); |
6193 __ Subu(v0, zero_reg, Operand(imm)); | 6213 __ Subu(v0, zero_reg, Operand(imm)); |
6194 CHECK_EQ(assm.InstructionsGeneratedSince(&code_start), num_instr); | 6214 CHECK_EQ(assm.InstructionsGeneratedSince(&code_start), num_instr); |
6195 __ jr(ra); | 6215 __ jr(ra); |
6196 __ nop(); | 6216 __ nop(); |
6197 | 6217 |
6198 CodeDesc desc; | 6218 CodeDesc desc; |
6199 assm.GetCode(isolate, &desc); | 6219 assm.GetCode(isolate, &desc); |
6200 Handle<Code> code = isolate->factory()->NewCode( | 6220 Handle<Code> code = isolate->factory()->NewCode( |
6201 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | 6221 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 6222 #ifdef OBJECT_PRINT |
| 6223 code->Print(std::cout); |
| 6224 #endif |
6202 F2 f = FUNCTION_CAST<F2>(code->entry()); | 6225 F2 f = FUNCTION_CAST<F2>(code->entry()); |
6203 | 6226 |
6204 uint64_t res = reinterpret_cast<uint64_t>( | 6227 uint64_t res = reinterpret_cast<uint64_t>( |
6205 CALL_GENERATED_CODE(isolate, f, 0, 0, 0, 0, 0)); | 6228 CALL_GENERATED_CODE(isolate, f, 0, 0, 0, 0, 0)); |
6206 | 6229 |
6207 return res; | 6230 return res; |
6208 } | 6231 } |
6209 | 6232 |
6210 TEST(Subu) { | 6233 TEST(Subu) { |
6211 CcTest::InitializeVM(); | 6234 CcTest::InitializeVM(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6271 __ bind(&code_start); | 6294 __ bind(&code_start); |
6272 __ Dsubu(v0, zero_reg, Operand(imm)); | 6295 __ Dsubu(v0, zero_reg, Operand(imm)); |
6273 CHECK_EQ(assm.InstructionsGeneratedSince(&code_start), num_instr); | 6296 CHECK_EQ(assm.InstructionsGeneratedSince(&code_start), num_instr); |
6274 __ jr(ra); | 6297 __ jr(ra); |
6275 __ nop(); | 6298 __ nop(); |
6276 | 6299 |
6277 CodeDesc desc; | 6300 CodeDesc desc; |
6278 assm.GetCode(isolate, &desc); | 6301 assm.GetCode(isolate, &desc); |
6279 Handle<Code> code = isolate->factory()->NewCode( | 6302 Handle<Code> code = isolate->factory()->NewCode( |
6280 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | 6303 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 6304 #ifdef OBJECT_PRINT |
| 6305 code->Print(std::cout); |
| 6306 #endif |
6281 F2 f = FUNCTION_CAST<F2>(code->entry()); | 6307 F2 f = FUNCTION_CAST<F2>(code->entry()); |
6282 | 6308 |
6283 uint64_t res = reinterpret_cast<uint64_t>( | 6309 uint64_t res = reinterpret_cast<uint64_t>( |
6284 CALL_GENERATED_CODE(isolate, f, 0, 0, 0, 0, 0)); | 6310 CALL_GENERATED_CODE(isolate, f, 0, 0, 0, 0, 0)); |
6285 | 6311 |
6286 return res; | 6312 return res; |
6287 } | 6313 } |
6288 | 6314 |
6289 TEST(Dsubu) { | 6315 TEST(Dsubu) { |
6290 CcTest::InitializeVM(); | 6316 CcTest::InitializeVM(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6334 // bit register, Dsubu gives a different result here. | 6360 // bit register, Dsubu gives a different result here. |
6335 {0x7fffffffffffffff, 0x8000000000000001, 3}, // max_int64 | 6361 {0x7fffffffffffffff, 0x8000000000000001, 3}, // max_int64 |
6336 // r2 - Generates daddiu + dsrl + dsubu | 6362 // r2 - Generates daddiu + dsrl + dsubu |
6337 // r6 - Generates daddiu + dati + dsubu | 6363 // r6 - Generates daddiu + dati + dsubu |
6338 {0x8000000000000000, 0x8000000000000000, 3}, // min_int64 | 6364 {0x8000000000000000, 0x8000000000000000, 3}, // min_int64 |
6339 // The test case above generates: | 6365 // The test case above generates: |
6340 // r2 - daddiu + dsrl32 + dsubu instruction sequence, | 6366 // r2 - daddiu + dsrl32 + dsubu instruction sequence, |
6341 // r6 - ori + dati + dsubu. | 6367 // r6 - ori + dati + dsubu. |
6342 // The result of 0 - min_int64 eqauls max_int64 + 1, which wraps around to | 6368 // The result of 0 - min_int64 eqauls max_int64 + 1, which wraps around to |
6343 // min_int64 again. | 6369 // min_int64 again. |
| 6370 {0xffff0000ffffffff, 0x0000ffff00000001, 4}, |
| 6371 // The test case above generates: |
| 6372 // r2 - ori + dsrl32 + ori + daddu instruction sequence, |
| 6373 // r6 - daddiu + dahi + dati + dsubu. |
| 6374 // For r2 loading imm would take more instructions than loading -imm so we |
| 6375 // can load -imm and add with daddu. |
6344 }; | 6376 }; |
6345 | 6377 |
6346 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseDsubu); | 6378 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseDsubu); |
6347 for (size_t i = 0; i < nr_test_cases; ++i) { | 6379 for (size_t i = 0; i < nr_test_cases; ++i) { |
6348 CHECK_EQ(tc[i].expected_res, run_Dsubu(tc[i].imm, tc[i].num_instr)); | 6380 CHECK_EQ(tc[i].expected_res, run_Dsubu(tc[i].imm, tc[i].num_instr)); |
6349 } | 6381 } |
6350 } | 6382 } |
6351 | 6383 |
6352 uint64_t run_Dins(uint64_t imm, uint64_t source, uint16_t pos, uint16_t size) { | 6384 uint64_t run_Dins(uint64_t imm, uint64_t source, uint16_t pos, uint16_t size) { |
6353 Isolate* isolate = CcTest::i_isolate(); | 6385 Isolate* isolate = CcTest::i_isolate(); |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6955 }; | 6987 }; |
6956 | 6988 |
6957 for (size_t i = 0; i < sizeof(tc) / sizeof(TestCaseMsaI8); ++i) { | 6989 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); | 6990 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); | 6991 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); | 6992 run_msa_i8(SHF_W, tc[i].input_lo, tc[i].input_hi, tc[i].i8); |
6961 } | 6993 } |
6962 } | 6994 } |
6963 | 6995 |
6964 #undef __ | 6996 #undef __ |
OLD | NEW |