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

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

Issue 2909913002: MIPS64: Add optimizations to li and Dsubu macro. (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 5053 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(&desc); 5071 assm.GetCode(&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
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
(...skipping 15 matching lines...) Expand all
5153 // r6 - lui + dahi 5158 // r6 - lui + dahi
5154 {0x1234ffff80000000, 3, 2}, 5159 {0x1234ffff80000000, 3, 2},
5155 // r2 - lui + ori + dsll 5160 // r2 - lui + ori + dsll
5156 // r6 - lui + dati 5161 // r6 - lui + dati
5157 {0x1234ffff80010000, 5, 2}, 5162 {0x1234ffff80010000, 5, 2},
5158 // r2 - lui + ori + dsll + ori + dsll 5163 // r2 - lui + ori + dsll + ori + dsll
5159 // r6 - lui + dati 5164 // r6 - lui + dati
5160 {0xffff8000ffff8000, 2, 2}, 5165 {0xffff8000ffff8000, 2, 2},
5161 // r2 - daddiu + dinsu 5166 // r2 - daddiu + dinsu
5162 // r6 - daddiu + dahi 5167 // r6 - daddiu + dahi
5163 {0xffff0000ffff8000, 5, 3}, 5168 {0xffff0000ffff8000, 4, 3},
5164 // r2 - lui + dsll + ori + dsll + ori 5169 // r2 - ori + dsll32 + ori + dsubu
5170 // Loading imm directly would require lui + dsll + ori + dsll + ori.
5171 // Optimized by loading -imm and using dsubu to get imm.
5165 // r6 - daddiu + dahi + dati 5172 // r6 - daddiu + dahi + dati
5166 {0x8000000080000000, 2, 2}, 5173 {0x8000000080000000, 2, 2},
5167 // lui + dinsu 5174 // lui + dinsu
5168 {0xabcd0000abcd0000, 2, 2}, 5175 {0xabcd0000abcd0000, 2, 2},
5169 // lui + dinsu 5176 // lui + dinsu
5170 {0x8000800080008000, 3, 3}, 5177 {0x8000800080008000, 3, 3},
5171 // lui + ori + dinsu 5178 // lui + ori + dinsu
5172 {0xabcd1234abcd1234, 3, 3}, 5179 {0xabcd1234abcd1234, 3, 3},
5173 // The test case above generates lui + ori + dinsu instruction sequence. 5180 // The test case above generates lui + ori + dinsu instruction sequence.
5174 {0xffff800080008000, 4, 3}, 5181 {0xffff800080008000, 4, 3},
5175 // r2 - lui + ori + dsll + ori 5182 // r2 - lui + ori + dsll + ori
5176 // r6 - lui + ori + dahi 5183 // r6 - lui + ori + dahi
5177 {0xffffabcd, 3, 2}, 5184 {0xffffabcd, 3, 2},
5178 // r2 - ori + dsll + ori 5185 // r2 - ori + dsll + ori
5179 // r6 - daddiu + dahi 5186 // r6 - daddiu + dahi
5180 {0x1ffffabcd, 4, 2}, 5187 {0x1ffffabcd, 4, 2},
5181 // r2 - lui + ori + dsll + ori 5188 // r2 - lui + ori + dsll + ori
5182 // r6 - daddiu + dahi 5189 // r6 - daddiu + dahi
5183 {0xffffffffabcd, 5, 2}, 5190 {0xffffffffabcd, 4, 2},
5184 // r2 - ori + dsll + ori + dsll + ori 5191 // r2 - daddiu + dsll32 + ori + dsubu
5192 // Loading imm directly would require ori + dsll + ori + dsll + ori.
5193 // Optimized by loading -imm and using dsubu to get imm.
5185 // r6 - daddiu + dati 5194 // r6 - daddiu + dati
5186 {0x1ffffffffabcd, 6, 2}, 5195 {0x1ffffffffabcd, 4, 2},
5187 // r2 - lui + ori + dsll + ori + dsll + ori 5196 // r2 - daddiu + dsll32 + ori + dsubu
5197 // Loading imm directly would require lui + ori + dsll + ori + dsll + ori.
5198 // Optimized by loading -imm and using dsubu to get imm.
5188 // r6 - daddiu + dati 5199 // r6 - daddiu + dati
5189 {0xffff7fff80010000, 5, 2}, 5200 {0xffff7fff80010000, 5, 2},
5190 // r2 - lui + ori + dsll + ori + dsll 5201 // r2 - lui + ori + dsll + ori + dsll
5191 // r6 - lui + dahi 5202 // r6 - lui + dahi
5192 // Here lui sets high 32 bits to 1 so dahi can be used to get target 5203 // Here lui sets high 32 bits to 1 so dahi can be used to get target
5193 // value. 5204 // value.
5194 {0x00007fff7fff0000, 3, 2}, 5205 {0x00007fff7fff0000, 3, 2},
5195 // r2 - lui + ori + dsll 5206 // r2 - lui + ori + dsll
5196 // r6 - lui + dahi 5207 // r6 - lui + dahi
5197 // High 32 bits are not set so dahi can be used to get target value. 5208 // High 32 bits are not set so dahi can be used to get target value.
5198 {0xffff7fff7fff0000, 5, 3}, 5209 {0xffff7fff7fff0000, 5, 3},
5199 // r2 - lui + ori + dsll + ori + dsll 5210 // r2 - lui + ori + dsll + ori + dsll
5200 // r6 - lui + dahi + dati 5211 // r6 - lui + dahi + dati
5201 // High 32 bits are not set so just dahi can't be used to get target 5212 // High 32 bits are not set so just dahi can't be used to get target
5202 // value. 5213 // value.
5203 {0x00007fff80010000, 3, 3}, 5214 {0x00007fff80010000, 3, 3},
5204 // r2 - lui + ori + dsll 5215 // r2 - lui + ori + dsll
5205 // r6 - lui + ori + dsll 5216 // r6 - lui + ori + dsll
5206 // High 32 bits are set so can't just use lui + dahi to get target value. 5217 // High 32 bits are set so can't just use lui + dahi to get target value.
5207 {0x1234abcd87654321, 6, 4}, 5218 {0x1234abcd87654321, 6, 4},
5208 // The test case above generates: 5219 // The test case above generates:
5209 // r2 - lui + ori + dsll + ori + dsll + ori instruction sequence, 5220 // r2 - lui + ori + dsll + ori + dsll + ori instruction sequence,
5210 // r6 - lui + ori + dahi + dati. 5221 // r6 - lui + ori + dahi + dati.
5211 // Load using full instruction sequence. 5222 // Load using full instruction sequence.
5223 {0xffff0000ffffffff, 3, 3},
5224 // r2 - ori + dsll32 + nor
5225 // Loading imm directly would require lui + dsll + ori + dsll + ori.
5226 // Optimized by loading ~imm and using nor to get imm. Loading -imm would
5227 // require one instruction more.
5228 // r6 - daddiu + dahi + dati
5212 }; 5229 };
5213 5230
5214 size_t nr_test_cases = sizeof(tc) / sizeof(TestCase_li); 5231 size_t nr_test_cases = sizeof(tc) / sizeof(TestCase_li);
5215 for (size_t i = 0; i < nr_test_cases; ++i) { 5232 for (size_t i = 0; i < nr_test_cases; ++i) {
5216 if (kArchVariant == kMips64r2) { 5233 if (kArchVariant == kMips64r2) {
5217 CHECK_EQ(tc[i].imm, 5234 CHECK_EQ(tc[i].imm,
5218 run_li_macro(tc[i].imm, OPTIMIZE_SIZE, tc[i].r2_num_instr)); 5235 run_li_macro(tc[i].imm, OPTIMIZE_SIZE, tc[i].r2_num_instr));
5219 } else { 5236 } else {
5220 CHECK_EQ(tc[i].imm, 5237 CHECK_EQ(tc[i].imm,
5221 run_li_macro(tc[i].imm, OPTIMIZE_SIZE, tc[i].r6_num_instr)); 5238 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
6192 __ bind(&code_start); 6209 __ bind(&code_start);
6193 __ Subu(v0, zero_reg, Operand(imm)); 6210 __ Subu(v0, zero_reg, Operand(imm));
6194 CHECK_EQ(assm.InstructionsGeneratedSince(&code_start), num_instr); 6211 CHECK_EQ(assm.InstructionsGeneratedSince(&code_start), num_instr);
6195 __ jr(ra); 6212 __ jr(ra);
6196 __ nop(); 6213 __ nop();
6197 6214
6198 CodeDesc desc; 6215 CodeDesc desc;
6199 assm.GetCode(&desc); 6216 assm.GetCode(&desc);
6200 Handle<Code> code = isolate->factory()->NewCode( 6217 Handle<Code> code = isolate->factory()->NewCode(
6201 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); 6218 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
6219 #ifdef OBJECT_PRINT
6220 code->Print(std::cout);
6221 #endif
6202 F2 f = FUNCTION_CAST<F2>(code->entry()); 6222 F2 f = FUNCTION_CAST<F2>(code->entry());
6203 6223
6204 uint64_t res = reinterpret_cast<uint64_t>( 6224 uint64_t res = reinterpret_cast<uint64_t>(
6205 CALL_GENERATED_CODE(isolate, f, 0, 0, 0, 0, 0)); 6225 CALL_GENERATED_CODE(isolate, f, 0, 0, 0, 0, 0));
6206 6226
6207 return res; 6227 return res;
6208 } 6228 }
6209 6229
6210 TEST(Subu) { 6230 TEST(Subu) {
6211 CcTest::InitializeVM(); 6231 CcTest::InitializeVM();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
6271 __ bind(&code_start); 6291 __ bind(&code_start);
6272 __ Dsubu(v0, zero_reg, Operand(imm)); 6292 __ Dsubu(v0, zero_reg, Operand(imm));
6273 CHECK_EQ(assm.InstructionsGeneratedSince(&code_start), num_instr); 6293 CHECK_EQ(assm.InstructionsGeneratedSince(&code_start), num_instr);
6274 __ jr(ra); 6294 __ jr(ra);
6275 __ nop(); 6295 __ nop();
6276 6296
6277 CodeDesc desc; 6297 CodeDesc desc;
6278 assm.GetCode(&desc); 6298 assm.GetCode(&desc);
6279 Handle<Code> code = isolate->factory()->NewCode( 6299 Handle<Code> code = isolate->factory()->NewCode(
6280 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); 6300 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
6301 #ifdef OBJECT_PRINT
6302 code->Print(std::cout);
6303 #endif
6281 F2 f = FUNCTION_CAST<F2>(code->entry()); 6304 F2 f = FUNCTION_CAST<F2>(code->entry());
6282 6305
6283 uint64_t res = reinterpret_cast<uint64_t>( 6306 uint64_t res = reinterpret_cast<uint64_t>(
6284 CALL_GENERATED_CODE(isolate, f, 0, 0, 0, 0, 0)); 6307 CALL_GENERATED_CODE(isolate, f, 0, 0, 0, 0, 0));
6285 6308
6286 return res; 6309 return res;
6287 } 6310 }
6288 6311
6289 TEST(Dsubu) { 6312 TEST(Dsubu) {
6290 CcTest::InitializeVM(); 6313 CcTest::InitializeVM();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
6334 // bit register, Dsubu gives a different result here. 6357 // bit register, Dsubu gives a different result here.
6335 {0x7fffffffffffffff, 0x8000000000000001, 3}, // max_int64 6358 {0x7fffffffffffffff, 0x8000000000000001, 3}, // max_int64
6336 // r2 - Generates daddiu + dsrl + dsubu 6359 // r2 - Generates daddiu + dsrl + dsubu
6337 // r6 - Generates daddiu + dati + dsubu 6360 // r6 - Generates daddiu + dati + dsubu
6338 {0x8000000000000000, 0x8000000000000000, 3}, // min_int64 6361 {0x8000000000000000, 0x8000000000000000, 3}, // min_int64
6339 // The test case above generates: 6362 // The test case above generates:
6340 // r2 - daddiu + dsrl32 + dsubu instruction sequence, 6363 // r2 - daddiu + dsrl32 + dsubu instruction sequence,
6341 // r6 - ori + dati + dsubu. 6364 // r6 - ori + dati + dsubu.
6342 // The result of 0 - min_int64 eqauls max_int64 + 1, which wraps around to 6365 // The result of 0 - min_int64 eqauls max_int64 + 1, which wraps around to
6343 // min_int64 again. 6366 // min_int64 again.
6367 {0xffff0000ffffffff, 0x0000ffff00000001, 4},
6368 // The test case above generates:
6369 // r2 - ori + dsrl32 + ori + daddu instruction sequence,
6370 // r6 - daddiu + dahi + dati + dsubu.
6371 // For r2 loading imm would take more instructions than loading -imm so we
6372 // can load -imm and add with daddu.
6344 }; 6373 };
6345 6374
6346 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseDsubu); 6375 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseDsubu);
6347 for (size_t i = 0; i < nr_test_cases; ++i) { 6376 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)); 6377 CHECK_EQ(tc[i].expected_res, run_Dsubu(tc[i].imm, tc[i].num_instr));
6349 } 6378 }
6350 } 6379 }
6351 6380
6352 uint64_t run_Dins(uint64_t imm, uint64_t source, uint16_t pos, uint16_t size) { 6381 uint64_t run_Dins(uint64_t imm, uint64_t source, uint16_t pos, uint16_t size) {
6353 Isolate* isolate = CcTest::i_isolate(); 6382 Isolate* isolate = CcTest::i_isolate();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
6402 }; 6431 };
6403 6432
6404 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseDins); 6433 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseDins);
6405 for (size_t i = 0; i < nr_test_cases; ++i) { 6434 for (size_t i = 0; i < nr_test_cases; ++i) {
6406 CHECK_EQ(tc[i].expected_res, 6435 CHECK_EQ(tc[i].expected_res,
6407 run_Dins(tc[i].imm, tc[i].source, tc[i].pos, tc[i].size)); 6436 run_Dins(tc[i].imm, tc[i].source, tc[i].pos, tc[i].size));
6408 } 6437 }
6409 } 6438 }
6410 6439
6411 #undef __ 6440 #undef __
OLDNEW
« src/mips64/macro-assembler-mips64.cc ('K') | « src/mips64/macro-assembler-mips64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698