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

Side by Side Diff: src/compiler/ia32/instruction-selector-ia32-unittest.cc

Issue 616833002: [turbofan] ia32 lea multiplication matching (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « src/compiler/ia32/instruction-selector-ia32.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/compiler/instruction-selector-unittest.h" 5 #include "src/compiler/instruction-selector-unittest.h"
6 6
7 namespace v8 { 7 namespace v8 {
8 namespace internal { 8 namespace internal {
9 namespace compiler { 9 namespace compiler {
10 10
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 Node* base = base_reg; 371 Node* base = base_reg;
372 Node* index = m->Int32Add(m->Int32Mul(index_reg, scales[i]), non_zero); 372 Node* index = m->Int32Add(m->Int32Mul(index_reg, scales[i]), non_zero);
373 Run(base, index, expected[i]); 373 Run(base, index, expected[i]);
374 } 374 }
375 } 375 }
376 376
377 377
378 TEST_F(AddressingModeUnitTest, AddressingMode_M1) { 378 TEST_F(AddressingModeUnitTest, AddressingMode_M1) {
379 Node* base = null_ptr; 379 Node* base = null_ptr;
380 Node* index = index_reg; 380 Node* index = index_reg;
381 Run(base, index, kMode_MR); 381 Run(base, index, kMode_M1);
382 } 382 }
383 383
384 384
385 TEST_F(AddressingModeUnitTest, AddressingMode_MN) { 385 TEST_F(AddressingModeUnitTest, AddressingMode_MN) {
386 AddressingMode expected[] = {kMode_MR, kMode_M2, kMode_M4, kMode_M8}; 386 AddressingMode expected[] = {kMode_M1, kMode_M2, kMode_M4, kMode_M8};
387 for (size_t i = 0; i < arraysize(scales); ++i) { 387 for (size_t i = 0; i < arraysize(scales); ++i) {
388 Reset(); 388 Reset();
389 Node* base = null_ptr; 389 Node* base = null_ptr;
390 Node* index = m->Int32Mul(index_reg, scales[i]); 390 Node* index = m->Int32Mul(index_reg, scales[i]);
391 Run(base, index, expected[i]); 391 Run(base, index, expected[i]);
392 } 392 }
393 } 393 }
394 394
395 395
396 TEST_F(AddressingModeUnitTest, AddressingMode_M1I) { 396 TEST_F(AddressingModeUnitTest, AddressingMode_M1I) {
397 Node* base = null_ptr; 397 Node* base = null_ptr;
398 Node* index = m->Int32Add(index_reg, non_zero); 398 Node* index = m->Int32Add(index_reg, non_zero);
399 Run(base, index, kMode_MRI); 399 Run(base, index, kMode_M1I);
400 } 400 }
401 401
402 402
403 TEST_F(AddressingModeUnitTest, AddressingMode_MNI) { 403 TEST_F(AddressingModeUnitTest, AddressingMode_MNI) {
404 AddressingMode expected[] = {kMode_MRI, kMode_M2I, kMode_M4I, kMode_M8I}; 404 AddressingMode expected[] = {kMode_M1I, kMode_M2I, kMode_M4I, kMode_M8I};
405 for (size_t i = 0; i < arraysize(scales); ++i) { 405 for (size_t i = 0; i < arraysize(scales); ++i) {
406 Reset(); 406 Reset();
407 Node* base = null_ptr; 407 Node* base = null_ptr;
408 Node* index = m->Int32Add(m->Int32Mul(index_reg, scales[i]), non_zero); 408 Node* index = m->Int32Add(m->Int32Mul(index_reg, scales[i]), non_zero);
409 Run(base, index, expected[i]); 409 Run(base, index, expected[i]);
410 } 410 }
411 } 411 }
412 412
413 413
414 TEST_F(AddressingModeUnitTest, AddressingMode_MI) { 414 TEST_F(AddressingModeUnitTest, AddressingMode_MI) {
415 Node* bases[] = {null_ptr, non_zero}; 415 Node* bases[] = {null_ptr, non_zero};
416 Node* indices[] = {zero, non_zero}; 416 Node* indices[] = {zero, non_zero};
417 for (size_t i = 0; i < arraysize(bases); ++i) { 417 for (size_t i = 0; i < arraysize(bases); ++i) {
418 for (size_t j = 0; j < arraysize(indices); ++j) { 418 for (size_t j = 0; j < arraysize(indices); ++j) {
419 Reset(); 419 Reset();
420 Node* base = bases[i]; 420 Node* base = bases[i];
421 Node* index = indices[j]; 421 Node* index = indices[j];
422 Run(base, index, kMode_MI); 422 Run(base, index, kMode_MI);
423 } 423 }
424 } 424 }
425 } 425 }
426 426
427
428 // -----------------------------------------------------------------------------
429 // Multiplication.
430
431 namespace {
432
433 struct MultParam {
434 int value;
435 bool lea_expected;
436 AddressingMode addressing_mode;
437 };
438
439
440 std::ostream& operator<<(std::ostream& os, const MultParam& m) {
441 OStringStream ost;
442 ost << m.value << "." << m.lea_expected << "." << m.addressing_mode;
443 return os << ost.c_str();
444 }
445
446
447 const MultParam kMultParams[] = {{-1, false, kMode_None},
448 {0, false, kMode_None},
449 {1, true, kMode_M1},
450 {2, true, kMode_M2},
451 {3, true, kMode_MR2},
452 {4, true, kMode_M4},
453 {5, true, kMode_MR4},
454 {6, false, kMode_None},
455 {7, false, kMode_None},
456 {8, true, kMode_M8},
457 {9, true, kMode_MR8},
458 {10, false, kMode_None},
459 {11, false, kMode_None}};
460
461 } // namespace
462
463
464 typedef InstructionSelectorTestWithParam<MultParam> InstructionSelectorMultTest;
465
466
467 static unsigned InputCountForLea(AddressingMode mode) {
468 switch (mode) {
469 case kMode_MR1:
470 case kMode_MR2:
471 case kMode_MR4:
472 case kMode_MR8:
473 return 2U;
474 case kMode_M1:
475 case kMode_M2:
476 case kMode_M4:
477 case kMode_M8:
478 return 1U;
479 default:
480 UNREACHABLE();
481 return 0U;
482 }
483 }
484
485
486 TEST_P(InstructionSelectorMultTest, Mult32) {
487 const MultParam m_param = GetParam();
488 StreamBuilder m(this, kMachInt32, kMachInt32);
489 Node* param = m.Parameter(0);
490 Node* mult = m.Int32Mul(param, m.Int32Constant(m_param.value));
491 m.Return(mult);
492 Stream s = m.Build();
493 ASSERT_EQ(1U, s.size());
494 EXPECT_EQ(m_param.addressing_mode, s[0]->addressing_mode());
495 if (m_param.lea_expected) {
496 EXPECT_EQ(kIA32Lea, s[0]->arch_opcode());
497 ASSERT_EQ(InputCountForLea(s[0]->addressing_mode()), s[0]->InputCount());
498 } else {
499 EXPECT_EQ(kIA32Lea, s[0]->arch_opcode());
500 ASSERT_EQ(2U, s[0]->InputCount());
501 }
502 EXPECT_EQ(param->id(), s.ToVreg(s[0]->InputAt(0)));
503 }
504
427 } // namespace compiler 505 } // namespace compiler
428 } // namespace internal 506 } // namespace internal
429 } // namespace v8 507 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/ia32/instruction-selector-ia32.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698