| OLD | NEW |
| 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 "test/unittests/compiler/instruction-selector-unittest.h" | 5 #include "test/unittests/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 1351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1362 } | 1362 } |
| 1363 | 1363 |
| 1364 | 1364 |
| 1365 // ----------------------------------------------------------------------------- | 1365 // ----------------------------------------------------------------------------- |
| 1366 // Miscellaneous. | 1366 // Miscellaneous. |
| 1367 | 1367 |
| 1368 | 1368 |
| 1369 TEST_F(InstructionSelectorTest, Int32AddWithInt32Mul) { | 1369 TEST_F(InstructionSelectorTest, Int32AddWithInt32Mul) { |
| 1370 { | 1370 { |
| 1371 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32, kMachInt32); | 1371 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32, kMachInt32); |
| 1372 m.Return( | 1372 Node* const p0 = m.Parameter(0); |
| 1373 m.Int32Add(m.Parameter(0), m.Int32Mul(m.Parameter(1), m.Parameter(2)))); | 1373 Node* const p1 = m.Parameter(1); |
| 1374 Node* const p2 = m.Parameter(2); |
| 1375 Node* const n = m.Int32Add(p0, m.Int32Mul(p1, p2)); |
| 1376 m.Return(n); |
| 1374 Stream s = m.Build(); | 1377 Stream s = m.Build(); |
| 1375 ASSERT_EQ(1U, s.size()); | 1378 ASSERT_EQ(1U, s.size()); |
| 1376 EXPECT_EQ(kArmMla, s[0]->arch_opcode()); | 1379 EXPECT_EQ(kArmMla, s[0]->arch_opcode()); |
| 1377 EXPECT_EQ(3U, s[0]->InputCount()); | 1380 ASSERT_EQ(3U, s[0]->InputCount()); |
| 1378 EXPECT_EQ(1U, s[0]->OutputCount()); | 1381 EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(0))); |
| 1382 EXPECT_EQ(s.ToVreg(p2), s.ToVreg(s[0]->InputAt(1))); |
| 1383 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(2))); |
| 1384 ASSERT_EQ(1U, s[0]->OutputCount()); |
| 1385 EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output())); |
| 1379 } | 1386 } |
| 1380 { | 1387 { |
| 1381 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32, kMachInt32); | 1388 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32, kMachInt32); |
| 1382 m.Return( | 1389 Node* const p0 = m.Parameter(0); |
| 1383 m.Int32Add(m.Int32Mul(m.Parameter(1), m.Parameter(2)), m.Parameter(0))); | 1390 Node* const p1 = m.Parameter(1); |
| 1391 Node* const p2 = m.Parameter(2); |
| 1392 Node* const n = m.Int32Add(m.Int32Mul(p1, p2), p0); |
| 1393 m.Return(n); |
| 1384 Stream s = m.Build(); | 1394 Stream s = m.Build(); |
| 1385 ASSERT_EQ(1U, s.size()); | 1395 ASSERT_EQ(1U, s.size()); |
| 1386 EXPECT_EQ(kArmMla, s[0]->arch_opcode()); | 1396 EXPECT_EQ(kArmMla, s[0]->arch_opcode()); |
| 1387 EXPECT_EQ(3U, s[0]->InputCount()); | 1397 ASSERT_EQ(3U, s[0]->InputCount()); |
| 1388 EXPECT_EQ(1U, s[0]->OutputCount()); | 1398 EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(0))); |
| 1399 EXPECT_EQ(s.ToVreg(p2), s.ToVreg(s[0]->InputAt(1))); |
| 1400 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(2))); |
| 1401 ASSERT_EQ(1U, s[0]->OutputCount()); |
| 1402 EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output())); |
| 1389 } | 1403 } |
| 1390 } | 1404 } |
| 1391 | 1405 |
| 1392 | 1406 |
| 1407 TEST_F(InstructionSelectorTest, Int32AddWithInt32MulHigh) { |
| 1408 { |
| 1409 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32, kMachInt32); |
| 1410 Node* const p0 = m.Parameter(0); |
| 1411 Node* const p1 = m.Parameter(1); |
| 1412 Node* const p2 = m.Parameter(2); |
| 1413 Node* const n = m.Int32Add(p0, m.Int32MulHigh(p1, p2)); |
| 1414 m.Return(n); |
| 1415 Stream s = m.Build(); |
| 1416 ASSERT_EQ(1U, s.size()); |
| 1417 EXPECT_EQ(kArmSmmla, s[0]->arch_opcode()); |
| 1418 ASSERT_EQ(3U, s[0]->InputCount()); |
| 1419 EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(0))); |
| 1420 EXPECT_EQ(s.ToVreg(p2), s.ToVreg(s[0]->InputAt(1))); |
| 1421 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(2))); |
| 1422 ASSERT_EQ(1U, s[0]->OutputCount()); |
| 1423 EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output())); |
| 1424 } |
| 1425 { |
| 1426 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32, kMachInt32); |
| 1427 Node* const p0 = m.Parameter(0); |
| 1428 Node* const p1 = m.Parameter(1); |
| 1429 Node* const p2 = m.Parameter(2); |
| 1430 Node* const n = m.Int32Add(m.Int32MulHigh(p1, p2), p0); |
| 1431 m.Return(n); |
| 1432 Stream s = m.Build(); |
| 1433 ASSERT_EQ(1U, s.size()); |
| 1434 EXPECT_EQ(kArmSmmla, s[0]->arch_opcode()); |
| 1435 ASSERT_EQ(3U, s[0]->InputCount()); |
| 1436 EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(0))); |
| 1437 EXPECT_EQ(s.ToVreg(p2), s.ToVreg(s[0]->InputAt(1))); |
| 1438 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(2))); |
| 1439 ASSERT_EQ(1U, s[0]->OutputCount()); |
| 1440 EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output())); |
| 1441 } |
| 1442 } |
| 1443 |
| 1444 |
| 1445 TEST_F(InstructionSelectorTest, Int32SubWithInt32Mul) { |
| 1446 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32, kMachInt32); |
| 1447 m.Return( |
| 1448 m.Int32Sub(m.Parameter(0), m.Int32Mul(m.Parameter(1), m.Parameter(2)))); |
| 1449 Stream s = m.Build(); |
| 1450 ASSERT_EQ(2U, s.size()); |
| 1451 EXPECT_EQ(kArmMul, s[0]->arch_opcode()); |
| 1452 ASSERT_EQ(1U, s[0]->OutputCount()); |
| 1453 EXPECT_EQ(kArmSub, s[1]->arch_opcode()); |
| 1454 ASSERT_EQ(2U, s[1]->InputCount()); |
| 1455 EXPECT_EQ(s.ToVreg(s[0]->Output()), s.ToVreg(s[1]->InputAt(1))); |
| 1456 } |
| 1457 |
| 1458 |
| 1459 TEST_F(InstructionSelectorTest, Int32SubWithInt32MulForMLS) { |
| 1460 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32, kMachInt32); |
| 1461 m.Return( |
| 1462 m.Int32Sub(m.Parameter(0), m.Int32Mul(m.Parameter(1), m.Parameter(2)))); |
| 1463 Stream s = m.Build(MLS); |
| 1464 ASSERT_EQ(1U, s.size()); |
| 1465 EXPECT_EQ(kArmMls, s[0]->arch_opcode()); |
| 1466 EXPECT_EQ(1U, s[0]->OutputCount()); |
| 1467 EXPECT_EQ(3U, s[0]->InputCount()); |
| 1468 } |
| 1469 |
| 1470 |
| 1393 TEST_F(InstructionSelectorTest, Int32DivWithParameters) { | 1471 TEST_F(InstructionSelectorTest, Int32DivWithParameters) { |
| 1394 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); | 1472 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); |
| 1395 m.Return(m.Int32Div(m.Parameter(0), m.Parameter(1))); | 1473 m.Return(m.Int32Div(m.Parameter(0), m.Parameter(1))); |
| 1396 Stream s = m.Build(); | 1474 Stream s = m.Build(); |
| 1397 ASSERT_EQ(4U, s.size()); | 1475 ASSERT_EQ(4U, s.size()); |
| 1398 EXPECT_EQ(kArmVcvtF64S32, s[0]->arch_opcode()); | 1476 EXPECT_EQ(kArmVcvtF64S32, s[0]->arch_opcode()); |
| 1399 ASSERT_EQ(1U, s[0]->OutputCount()); | 1477 ASSERT_EQ(1U, s[0]->OutputCount()); |
| 1400 EXPECT_EQ(kArmVcvtF64S32, s[1]->arch_opcode()); | 1478 EXPECT_EQ(kArmVcvtF64S32, s[1]->arch_opcode()); |
| 1401 ASSERT_EQ(1U, s[1]->OutputCount()); | 1479 ASSERT_EQ(1U, s[1]->OutputCount()); |
| 1402 EXPECT_EQ(kArmVdivF64, s[2]->arch_opcode()); | 1480 EXPECT_EQ(kArmVdivF64, s[2]->arch_opcode()); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1547 EXPECT_EQ(kArmRsb, s[0]->arch_opcode()); | 1625 EXPECT_EQ(kArmRsb, s[0]->arch_opcode()); |
| 1548 EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode()); | 1626 EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode()); |
| 1549 ASSERT_EQ(3U, s[0]->InputCount()); | 1627 ASSERT_EQ(3U, s[0]->InputCount()); |
| 1550 EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1))); | 1628 EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1))); |
| 1551 EXPECT_EQ(k, s.ToInt32(s[0]->InputAt(2))); | 1629 EXPECT_EQ(k, s.ToInt32(s[0]->InputAt(2))); |
| 1552 EXPECT_EQ(1U, s[0]->OutputCount()); | 1630 EXPECT_EQ(1U, s[0]->OutputCount()); |
| 1553 } | 1631 } |
| 1554 } | 1632 } |
| 1555 | 1633 |
| 1556 | 1634 |
| 1557 TEST_F(InstructionSelectorTest, Int32SubWithInt32Mul) { | 1635 TEST_F(InstructionSelectorTest, Int32MulHighWithParameters) { |
| 1558 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32, kMachInt32); | 1636 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); |
| 1559 m.Return( | 1637 Node* const p0 = m.Parameter(0); |
| 1560 m.Int32Sub(m.Parameter(0), m.Int32Mul(m.Parameter(1), m.Parameter(2)))); | 1638 Node* const p1 = m.Parameter(1); |
| 1639 Node* const n = m.Int32MulHigh(p0, p1); |
| 1640 m.Return(n); |
| 1561 Stream s = m.Build(); | 1641 Stream s = m.Build(); |
| 1562 ASSERT_EQ(2U, s.size()); | 1642 ASSERT_EQ(1U, s.size()); |
| 1563 EXPECT_EQ(kArmMul, s[0]->arch_opcode()); | 1643 EXPECT_EQ(kArmSmmul, s[0]->arch_opcode()); |
| 1644 ASSERT_EQ(2U, s[0]->InputCount()); |
| 1645 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); |
| 1646 EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1))); |
| 1564 ASSERT_EQ(1U, s[0]->OutputCount()); | 1647 ASSERT_EQ(1U, s[0]->OutputCount()); |
| 1565 EXPECT_EQ(kArmSub, s[1]->arch_opcode()); | 1648 EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output())); |
| 1566 ASSERT_EQ(2U, s[1]->InputCount()); | |
| 1567 EXPECT_EQ(s.ToVreg(s[0]->Output()), s.ToVreg(s[1]->InputAt(1))); | |
| 1568 } | 1649 } |
| 1569 | 1650 |
| 1570 | 1651 |
| 1571 TEST_F(InstructionSelectorTest, Int32SubWithInt32MulForMLS) { | |
| 1572 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32, kMachInt32); | |
| 1573 m.Return( | |
| 1574 m.Int32Sub(m.Parameter(0), m.Int32Mul(m.Parameter(1), m.Parameter(2)))); | |
| 1575 Stream s = m.Build(MLS); | |
| 1576 ASSERT_EQ(1U, s.size()); | |
| 1577 EXPECT_EQ(kArmMls, s[0]->arch_opcode()); | |
| 1578 EXPECT_EQ(1U, s[0]->OutputCount()); | |
| 1579 EXPECT_EQ(3U, s[0]->InputCount()); | |
| 1580 } | |
| 1581 | |
| 1582 | |
| 1583 TEST_F(InstructionSelectorTest, Uint32DivWithParameters) { | 1652 TEST_F(InstructionSelectorTest, Uint32DivWithParameters) { |
| 1584 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); | 1653 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); |
| 1585 m.Return(m.Uint32Div(m.Parameter(0), m.Parameter(1))); | 1654 m.Return(m.Uint32Div(m.Parameter(0), m.Parameter(1))); |
| 1586 Stream s = m.Build(); | 1655 Stream s = m.Build(); |
| 1587 ASSERT_EQ(4U, s.size()); | 1656 ASSERT_EQ(4U, s.size()); |
| 1588 EXPECT_EQ(kArmVcvtF64U32, s[0]->arch_opcode()); | 1657 EXPECT_EQ(kArmVcvtF64U32, s[0]->arch_opcode()); |
| 1589 ASSERT_EQ(1U, s[0]->OutputCount()); | 1658 ASSERT_EQ(1U, s[0]->OutputCount()); |
| 1590 EXPECT_EQ(kArmVcvtF64U32, s[1]->arch_opcode()); | 1659 EXPECT_EQ(kArmVcvtF64U32, s[1]->arch_opcode()); |
| 1591 ASSERT_EQ(1U, s[1]->OutputCount()); | 1660 ASSERT_EQ(1U, s[1]->OutputCount()); |
| 1592 EXPECT_EQ(kArmVdivF64, s[2]->arch_opcode()); | 1661 EXPECT_EQ(kArmVdivF64, s[2]->arch_opcode()); |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1916 ASSERT_EQ(3U, s[0]->InputCount()); | 1985 ASSERT_EQ(3U, s[0]->InputCount()); |
| 1917 EXPECT_EQ(lsb, s.ToInt32(s[0]->InputAt(1))); | 1986 EXPECT_EQ(lsb, s.ToInt32(s[0]->InputAt(1))); |
| 1918 EXPECT_EQ(width, s.ToInt32(s[0]->InputAt(2))); | 1987 EXPECT_EQ(width, s.ToInt32(s[0]->InputAt(2))); |
| 1919 } | 1988 } |
| 1920 } | 1989 } |
| 1921 } | 1990 } |
| 1922 | 1991 |
| 1923 } // namespace compiler | 1992 } // namespace compiler |
| 1924 } // namespace internal | 1993 } // namespace internal |
| 1925 } // namespace v8 | 1994 } // namespace v8 |
| OLD | NEW |