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 <limits> | 5 #include <limits> |
6 | 6 |
7 #include "test/unittests/compiler/instruction-selector-unittest.h" | 7 #include "test/unittests/compiler/instruction-selector-unittest.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 1374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1385 // Comparisons. | 1385 // Comparisons. |
1386 | 1386 |
1387 | 1387 |
1388 namespace { | 1388 namespace { |
1389 | 1389 |
1390 struct Comparison { | 1390 struct Comparison { |
1391 Constructor constructor; | 1391 Constructor constructor; |
1392 const char* constructor_name; | 1392 const char* constructor_name; |
1393 FlagsCondition flags_condition; | 1393 FlagsCondition flags_condition; |
1394 FlagsCondition negated_flags_condition; | 1394 FlagsCondition negated_flags_condition; |
| 1395 FlagsCondition commuted_flags_condition; |
1395 }; | 1396 }; |
1396 | 1397 |
1397 | 1398 |
1398 std::ostream& operator<<(std::ostream& os, const Comparison& cmp) { | 1399 std::ostream& operator<<(std::ostream& os, const Comparison& cmp) { |
1399 return os << cmp.constructor_name; | 1400 return os << cmp.constructor_name; |
1400 } | 1401 } |
1401 | 1402 |
1402 | 1403 |
1403 const Comparison kComparisons[] = { | 1404 const Comparison kComparisons[] = { |
1404 {&RawMachineAssembler::Word32Equal, "Word32Equal", kEqual, kNotEqual}, | 1405 {&RawMachineAssembler::Word32Equal, "Word32Equal", kEqual, kNotEqual, |
| 1406 kEqual}, |
1405 {&RawMachineAssembler::Int32LessThan, "Int32LessThan", kSignedLessThan, | 1407 {&RawMachineAssembler::Int32LessThan, "Int32LessThan", kSignedLessThan, |
1406 kSignedGreaterThanOrEqual}, | 1408 kSignedGreaterThanOrEqual, kSignedGreaterThan}, |
1407 {&RawMachineAssembler::Int32LessThanOrEqual, "Int32LessThanOrEqual", | 1409 {&RawMachineAssembler::Int32LessThanOrEqual, "Int32LessThanOrEqual", |
1408 kSignedLessThanOrEqual, kSignedGreaterThan}, | 1410 kSignedLessThanOrEqual, kSignedGreaterThan, kSignedGreaterThanOrEqual}, |
1409 {&RawMachineAssembler::Uint32LessThan, "Uint32LessThan", kUnsignedLessThan, | 1411 {&RawMachineAssembler::Uint32LessThan, "Uint32LessThan", kUnsignedLessThan, |
1410 kUnsignedGreaterThanOrEqual}, | 1412 kUnsignedGreaterThanOrEqual, kUnsignedGreaterThan}, |
1411 {&RawMachineAssembler::Uint32LessThanOrEqual, "Uint32LessThanOrEqual", | 1413 {&RawMachineAssembler::Uint32LessThanOrEqual, "Uint32LessThanOrEqual", |
1412 kUnsignedLessThanOrEqual, kUnsignedGreaterThan}}; | 1414 kUnsignedLessThanOrEqual, kUnsignedGreaterThan, |
| 1415 kUnsignedGreaterThanOrEqual}}; |
1413 | 1416 |
1414 } // namespace | 1417 } // namespace |
1415 | 1418 |
1416 | 1419 |
1417 typedef InstructionSelectorTestWithParam<Comparison> | 1420 typedef InstructionSelectorTestWithParam<Comparison> |
1418 InstructionSelectorComparisonTest; | 1421 InstructionSelectorComparisonTest; |
1419 | 1422 |
1420 | 1423 |
1421 TEST_P(InstructionSelectorComparisonTest, Parameters) { | 1424 TEST_P(InstructionSelectorComparisonTest, Parameters) { |
1422 const Comparison& cmp = GetParam(); | 1425 const Comparison& cmp = GetParam(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1488 ::testing::ValuesIn(kComparisons)); | 1491 ::testing::ValuesIn(kComparisons)); |
1489 | 1492 |
1490 | 1493 |
1491 // ----------------------------------------------------------------------------- | 1494 // ----------------------------------------------------------------------------- |
1492 // Floating point comparisons. | 1495 // Floating point comparisons. |
1493 | 1496 |
1494 | 1497 |
1495 namespace { | 1498 namespace { |
1496 | 1499 |
1497 const Comparison kF32Comparisons[] = { | 1500 const Comparison kF32Comparisons[] = { |
1498 {&RawMachineAssembler::Float32Equal, "Float32Equal", kEqual, kNotEqual}, | 1501 {&RawMachineAssembler::Float32Equal, "Float32Equal", kEqual, kNotEqual, |
| 1502 kEqual}, |
1499 {&RawMachineAssembler::Float32LessThan, "Float32LessThan", | 1503 {&RawMachineAssembler::Float32LessThan, "Float32LessThan", |
1500 kUnsignedLessThan, kUnsignedGreaterThanOrEqual}, | 1504 kFloatLessThan, kFloatGreaterThanOrEqualOrUnordered, kFloatGreaterThan}, |
1501 {&RawMachineAssembler::Float32LessThanOrEqual, "Float32LessThanOrEqual", | 1505 {&RawMachineAssembler::Float32LessThanOrEqual, "Float32LessThanOrEqual", |
1502 kUnsignedLessThanOrEqual, kUnsignedGreaterThan}}; | 1506 kFloatLessThanOrEqual, kFloatGreaterThanOrUnordered, |
| 1507 kFloatGreaterThanOrEqual}}; |
1503 | 1508 |
1504 } // namespace | 1509 } // namespace |
1505 | 1510 |
1506 typedef InstructionSelectorTestWithParam<Comparison> | 1511 typedef InstructionSelectorTestWithParam<Comparison> |
1507 InstructionSelectorF32ComparisonTest; | 1512 InstructionSelectorF32ComparisonTest; |
1508 | 1513 |
1509 | 1514 |
1510 TEST_P(InstructionSelectorF32ComparisonTest, WithParameters) { | 1515 TEST_P(InstructionSelectorF32ComparisonTest, WithParameters) { |
1511 const Comparison& cmp = GetParam(); | 1516 const Comparison& cmp = GetParam(); |
1512 StreamBuilder m(this, kMachInt32, kMachFloat32, kMachFloat32); | 1517 StreamBuilder m(this, kMachInt32, kMachFloat32, kMachFloat32); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1544 ASSERT_EQ(1U, s.size()); | 1549 ASSERT_EQ(1U, s.size()); |
1545 EXPECT_EQ(kArmVcmpF32, s[0]->arch_opcode()); | 1550 EXPECT_EQ(kArmVcmpF32, s[0]->arch_opcode()); |
1546 ASSERT_EQ(2U, s[0]->InputCount()); | 1551 ASSERT_EQ(2U, s[0]->InputCount()); |
1547 EXPECT_TRUE(s[0]->InputAt(1)->IsImmediate()); | 1552 EXPECT_TRUE(s[0]->InputAt(1)->IsImmediate()); |
1548 ASSERT_EQ(1U, s[0]->OutputCount()); | 1553 ASSERT_EQ(1U, s[0]->OutputCount()); |
1549 EXPECT_EQ(kFlags_set, s[0]->flags_mode()); | 1554 EXPECT_EQ(kFlags_set, s[0]->flags_mode()); |
1550 EXPECT_EQ(cmp.flags_condition, s[0]->flags_condition()); | 1555 EXPECT_EQ(cmp.flags_condition, s[0]->flags_condition()); |
1551 } | 1556 } |
1552 | 1557 |
1553 | 1558 |
| 1559 TEST_P(InstructionSelectorF32ComparisonTest, WithImmediateZeroOnLeft) { |
| 1560 const Comparison& cmp = GetParam(); |
| 1561 StreamBuilder m(this, kMachInt32, kMachFloat32); |
| 1562 m.Return((m.*cmp.constructor)(m.Float32Constant(0.0f), m.Parameter(0))); |
| 1563 Stream const s = m.Build(); |
| 1564 ASSERT_EQ(1U, s.size()); |
| 1565 EXPECT_EQ(kArmVcmpF32, s[0]->arch_opcode()); |
| 1566 ASSERT_EQ(2U, s[0]->InputCount()); |
| 1567 EXPECT_TRUE(s[0]->InputAt(1)->IsImmediate()); |
| 1568 ASSERT_EQ(1U, s[0]->OutputCount()); |
| 1569 EXPECT_EQ(kFlags_set, s[0]->flags_mode()); |
| 1570 EXPECT_EQ(cmp.commuted_flags_condition, s[0]->flags_condition()); |
| 1571 } |
| 1572 |
| 1573 |
1554 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, | 1574 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, |
1555 InstructionSelectorF32ComparisonTest, | 1575 InstructionSelectorF32ComparisonTest, |
1556 ::testing::ValuesIn(kF32Comparisons)); | 1576 ::testing::ValuesIn(kF32Comparisons)); |
1557 | 1577 |
1558 | 1578 |
1559 TEST_F(InstructionSelectorTest, Float32EqualWithImmediateZeroOnLeft) { | |
1560 StreamBuilder m(this, kMachInt32, kMachFloat32); | |
1561 m.Return(m.Float32Equal(m.Float32Constant(0.0f), m.Parameter(0))); | |
1562 Stream s = m.Build(); | |
1563 ASSERT_EQ(1U, s.size()); | |
1564 EXPECT_EQ(kArmVcmpF32, s[0]->arch_opcode()); | |
1565 EXPECT_EQ(2U, s[0]->InputCount()); | |
1566 EXPECT_TRUE(s[0]->InputAt(1)->IsImmediate()); | |
1567 EXPECT_EQ(1U, s[0]->OutputCount()); | |
1568 EXPECT_EQ(kFlags_set, s[0]->flags_mode()); | |
1569 EXPECT_EQ(kEqual, s[0]->flags_condition()); | |
1570 } | |
1571 | |
1572 | |
1573 namespace { | 1579 namespace { |
1574 | 1580 |
1575 const Comparison kF64Comparisons[] = { | 1581 const Comparison kF64Comparisons[] = { |
1576 {&RawMachineAssembler::Float64Equal, "Float64Equal", kEqual, kNotEqual}, | 1582 {&RawMachineAssembler::Float64Equal, "Float64Equal", kEqual, kNotEqual, |
| 1583 kEqual}, |
1577 {&RawMachineAssembler::Float64LessThan, "Float64LessThan", | 1584 {&RawMachineAssembler::Float64LessThan, "Float64LessThan", |
1578 kUnsignedLessThan, kUnsignedGreaterThanOrEqual}, | 1585 kFloatLessThan, kFloatGreaterThanOrEqualOrUnordered, kFloatGreaterThan}, |
1579 {&RawMachineAssembler::Float64LessThanOrEqual, "Float64LessThanOrEqual", | 1586 {&RawMachineAssembler::Float64LessThanOrEqual, "Float64LessThanOrEqual", |
1580 kUnsignedLessThanOrEqual, kUnsignedGreaterThan}}; | 1587 kFloatLessThanOrEqual, kFloatGreaterThanOrUnordered, |
| 1588 kFloatGreaterThanOrEqual}}; |
1581 | 1589 |
1582 } // namespace | 1590 } // namespace |
1583 | 1591 |
1584 typedef InstructionSelectorTestWithParam<Comparison> | 1592 typedef InstructionSelectorTestWithParam<Comparison> |
1585 InstructionSelectorF64ComparisonTest; | 1593 InstructionSelectorF64ComparisonTest; |
1586 | 1594 |
1587 | 1595 |
1588 TEST_P(InstructionSelectorF64ComparisonTest, WithParameters) { | 1596 TEST_P(InstructionSelectorF64ComparisonTest, WithParameters) { |
1589 const Comparison& cmp = GetParam(); | 1597 const Comparison& cmp = GetParam(); |
1590 StreamBuilder m(this, kMachInt32, kMachFloat64, kMachFloat64); | 1598 StreamBuilder m(this, kMachInt32, kMachFloat64, kMachFloat64); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1622 ASSERT_EQ(1U, s.size()); | 1630 ASSERT_EQ(1U, s.size()); |
1623 EXPECT_EQ(kArmVcmpF64, s[0]->arch_opcode()); | 1631 EXPECT_EQ(kArmVcmpF64, s[0]->arch_opcode()); |
1624 ASSERT_EQ(2U, s[0]->InputCount()); | 1632 ASSERT_EQ(2U, s[0]->InputCount()); |
1625 EXPECT_TRUE(s[0]->InputAt(1)->IsImmediate()); | 1633 EXPECT_TRUE(s[0]->InputAt(1)->IsImmediate()); |
1626 ASSERT_EQ(1U, s[0]->OutputCount()); | 1634 ASSERT_EQ(1U, s[0]->OutputCount()); |
1627 EXPECT_EQ(kFlags_set, s[0]->flags_mode()); | 1635 EXPECT_EQ(kFlags_set, s[0]->flags_mode()); |
1628 EXPECT_EQ(cmp.flags_condition, s[0]->flags_condition()); | 1636 EXPECT_EQ(cmp.flags_condition, s[0]->flags_condition()); |
1629 } | 1637 } |
1630 | 1638 |
1631 | 1639 |
| 1640 TEST_P(InstructionSelectorF64ComparisonTest, WithImmediateZeroOnLeft) { |
| 1641 const Comparison& cmp = GetParam(); |
| 1642 StreamBuilder m(this, kMachInt32, kMachFloat64); |
| 1643 m.Return((m.*cmp.constructor)(m.Float64Constant(0.0), m.Parameter(0))); |
| 1644 Stream const s = m.Build(); |
| 1645 ASSERT_EQ(1U, s.size()); |
| 1646 EXPECT_EQ(kArmVcmpF64, s[0]->arch_opcode()); |
| 1647 ASSERT_EQ(2U, s[0]->InputCount()); |
| 1648 EXPECT_TRUE(s[0]->InputAt(1)->IsImmediate()); |
| 1649 ASSERT_EQ(1U, s[0]->OutputCount()); |
| 1650 EXPECT_EQ(kFlags_set, s[0]->flags_mode()); |
| 1651 EXPECT_EQ(cmp.commuted_flags_condition, s[0]->flags_condition()); |
| 1652 } |
| 1653 |
| 1654 |
1632 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, | 1655 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, |
1633 InstructionSelectorF64ComparisonTest, | 1656 InstructionSelectorF64ComparisonTest, |
1634 ::testing::ValuesIn(kF64Comparisons)); | 1657 ::testing::ValuesIn(kF64Comparisons)); |
1635 | 1658 |
1636 | 1659 |
1637 TEST_F(InstructionSelectorTest, Float64EqualWithImmediateZeroOnLeft) { | |
1638 StreamBuilder m(this, kMachInt32, kMachFloat64); | |
1639 m.Return(m.Float64Equal(m.Float64Constant(0.0), m.Parameter(0))); | |
1640 Stream s = m.Build(); | |
1641 ASSERT_EQ(1U, s.size()); | |
1642 EXPECT_EQ(kArmVcmpF64, s[0]->arch_opcode()); | |
1643 EXPECT_EQ(2U, s[0]->InputCount()); | |
1644 EXPECT_TRUE(s[0]->InputAt(1)->IsImmediate()); | |
1645 EXPECT_EQ(1U, s[0]->OutputCount()); | |
1646 EXPECT_EQ(kFlags_set, s[0]->flags_mode()); | |
1647 EXPECT_EQ(kEqual, s[0]->flags_condition()); | |
1648 } | |
1649 | |
1650 | |
1651 // ----------------------------------------------------------------------------- | 1660 // ----------------------------------------------------------------------------- |
1652 // Floating point arithmetic. | 1661 // Floating point arithmetic. |
1653 | 1662 |
1654 | 1663 |
1655 typedef InstructionSelectorTestWithParam<FAI> InstructionSelectorFAITest; | 1664 typedef InstructionSelectorTestWithParam<FAI> InstructionSelectorFAITest; |
1656 | 1665 |
1657 | 1666 |
1658 TEST_P(InstructionSelectorFAITest, Parameters) { | 1667 TEST_P(InstructionSelectorFAITest, Parameters) { |
1659 const FAI& fai = GetParam(); | 1668 const FAI& fai = GetParam(); |
1660 StreamBuilder m(this, fai.machine_type, fai.machine_type, fai.machine_type); | 1669 StreamBuilder m(this, fai.machine_type, fai.machine_type, fai.machine_type); |
(...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2770 EXPECT_EQ(kArmClz, s[0]->arch_opcode()); | 2779 EXPECT_EQ(kArmClz, s[0]->arch_opcode()); |
2771 ASSERT_EQ(1U, s[0]->InputCount()); | 2780 ASSERT_EQ(1U, s[0]->InputCount()); |
2772 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); | 2781 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); |
2773 ASSERT_EQ(1U, s[0]->OutputCount()); | 2782 ASSERT_EQ(1U, s[0]->OutputCount()); |
2774 EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output())); | 2783 EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output())); |
2775 } | 2784 } |
2776 | 2785 |
2777 } // namespace compiler | 2786 } // namespace compiler |
2778 } // namespace internal | 2787 } // namespace internal |
2779 } // namespace v8 | 2788 } // namespace v8 |
OLD | NEW |