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 1354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1365 m.Return(m.TruncateFloat64ToFloat32(m.Parameter(0))); | 1365 m.Return(m.TruncateFloat64ToFloat32(m.Parameter(0))); |
1366 Stream s = m.Build(); | 1366 Stream s = m.Build(); |
1367 ASSERT_EQ(1U, s.size()); | 1367 ASSERT_EQ(1U, s.size()); |
1368 EXPECT_EQ(kArmVcvtF32F64, s[0]->arch_opcode()); | 1368 EXPECT_EQ(kArmVcvtF32F64, s[0]->arch_opcode()); |
1369 EXPECT_EQ(1U, s[0]->InputCount()); | 1369 EXPECT_EQ(1U, s[0]->InputCount()); |
1370 EXPECT_EQ(1U, s[0]->OutputCount()); | 1370 EXPECT_EQ(1U, s[0]->OutputCount()); |
1371 } | 1371 } |
1372 | 1372 |
1373 | 1373 |
1374 // ----------------------------------------------------------------------------- | 1374 // ----------------------------------------------------------------------------- |
| 1375 // Comparisons. |
| 1376 |
| 1377 |
| 1378 namespace { |
| 1379 |
| 1380 struct Comparison { |
| 1381 Constructor constructor; |
| 1382 const char* constructor_name; |
| 1383 FlagsCondition flags_condition; |
| 1384 FlagsCondition negated_flags_condition; |
| 1385 }; |
| 1386 |
| 1387 |
| 1388 std::ostream& operator<<(std::ostream& os, const Comparison& cmp) { |
| 1389 return os << cmp.constructor_name; |
| 1390 } |
| 1391 |
| 1392 |
| 1393 const Comparison kComparisons[] = { |
| 1394 {&RawMachineAssembler::Word32Equal, "Word32Equal", kEqual, kNotEqual}, |
| 1395 {&RawMachineAssembler::Int32LessThan, "Int32LessThan", kSignedLessThan, |
| 1396 kSignedGreaterThanOrEqual}, |
| 1397 {&RawMachineAssembler::Int32LessThanOrEqual, "Int32LessThanOrEqual", |
| 1398 kSignedLessThanOrEqual, kSignedGreaterThan}, |
| 1399 {&RawMachineAssembler::Uint32LessThan, "Uint32LessThan", kUnsignedLessThan, |
| 1400 kUnsignedGreaterThanOrEqual}, |
| 1401 {&RawMachineAssembler::Uint32LessThanOrEqual, "Uint32LessThanOrEqual", |
| 1402 kUnsignedLessThanOrEqual, kUnsignedGreaterThan}}; |
| 1403 |
| 1404 } // namespace |
| 1405 |
| 1406 |
| 1407 typedef InstructionSelectorTestWithParam<Comparison> |
| 1408 InstructionSelectorComparisonTest; |
| 1409 |
| 1410 |
| 1411 TEST_P(InstructionSelectorComparisonTest, Parameters) { |
| 1412 const Comparison& cmp = GetParam(); |
| 1413 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); |
| 1414 Node* const p0 = m.Parameter(0); |
| 1415 Node* const p1 = m.Parameter(1); |
| 1416 Node* const r = (m.*cmp.constructor)(p0, p1); |
| 1417 m.Return(r); |
| 1418 Stream const s = m.Build(); |
| 1419 ASSERT_EQ(1U, s.size()); |
| 1420 EXPECT_EQ(kArmCmp, s[0]->arch_opcode()); |
| 1421 EXPECT_EQ(kMode_Operand2_R, s[0]->addressing_mode()); |
| 1422 ASSERT_EQ(2U, s[0]->InputCount()); |
| 1423 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); |
| 1424 EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1))); |
| 1425 ASSERT_EQ(1U, s[0]->OutputCount()); |
| 1426 EXPECT_EQ(s.ToVreg(r), s.ToVreg(s[0]->OutputAt(0))); |
| 1427 EXPECT_EQ(kFlags_set, s[0]->flags_mode()); |
| 1428 EXPECT_EQ(cmp.flags_condition, s[0]->flags_condition()); |
| 1429 } |
| 1430 |
| 1431 |
| 1432 TEST_P(InstructionSelectorComparisonTest, Word32EqualWithZero) { |
| 1433 { |
| 1434 const Comparison& cmp = GetParam(); |
| 1435 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); |
| 1436 Node* const p0 = m.Parameter(0); |
| 1437 Node* const p1 = m.Parameter(1); |
| 1438 Node* const r = |
| 1439 m.Word32Equal((m.*cmp.constructor)(p0, p1), m.Int32Constant(0)); |
| 1440 m.Return(r); |
| 1441 Stream const s = m.Build(); |
| 1442 ASSERT_EQ(1U, s.size()); |
| 1443 EXPECT_EQ(kArmCmp, s[0]->arch_opcode()); |
| 1444 EXPECT_EQ(kMode_Operand2_R, s[0]->addressing_mode()); |
| 1445 ASSERT_EQ(2U, s[0]->InputCount()); |
| 1446 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); |
| 1447 EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1))); |
| 1448 ASSERT_EQ(1U, s[0]->OutputCount()); |
| 1449 EXPECT_EQ(s.ToVreg(r), s.ToVreg(s[0]->OutputAt(0))); |
| 1450 EXPECT_EQ(kFlags_set, s[0]->flags_mode()); |
| 1451 EXPECT_EQ(cmp.negated_flags_condition, s[0]->flags_condition()); |
| 1452 } |
| 1453 { |
| 1454 const Comparison& cmp = GetParam(); |
| 1455 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); |
| 1456 Node* const p0 = m.Parameter(0); |
| 1457 Node* const p1 = m.Parameter(1); |
| 1458 Node* const r = |
| 1459 m.Word32Equal(m.Int32Constant(0), (m.*cmp.constructor)(p0, p1)); |
| 1460 m.Return(r); |
| 1461 Stream const s = m.Build(); |
| 1462 ASSERT_EQ(1U, s.size()); |
| 1463 EXPECT_EQ(kArmCmp, s[0]->arch_opcode()); |
| 1464 EXPECT_EQ(kMode_Operand2_R, s[0]->addressing_mode()); |
| 1465 ASSERT_EQ(2U, s[0]->InputCount()); |
| 1466 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); |
| 1467 EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1))); |
| 1468 ASSERT_EQ(1U, s[0]->OutputCount()); |
| 1469 EXPECT_EQ(s.ToVreg(r), s.ToVreg(s[0]->OutputAt(0))); |
| 1470 EXPECT_EQ(kFlags_set, s[0]->flags_mode()); |
| 1471 EXPECT_EQ(cmp.negated_flags_condition, s[0]->flags_condition()); |
| 1472 } |
| 1473 } |
| 1474 |
| 1475 |
| 1476 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, |
| 1477 InstructionSelectorComparisonTest, |
| 1478 ::testing::ValuesIn(kComparisons)); |
| 1479 |
| 1480 |
| 1481 // ----------------------------------------------------------------------------- |
1375 // Miscellaneous. | 1482 // Miscellaneous. |
1376 | 1483 |
1377 | 1484 |
1378 TEST_F(InstructionSelectorTest, Int32AddWithInt32Mul) { | 1485 TEST_F(InstructionSelectorTest, Int32AddWithInt32Mul) { |
1379 { | 1486 { |
1380 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32, kMachInt32); | 1487 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32, kMachInt32); |
1381 Node* const p0 = m.Parameter(0); | 1488 Node* const p0 = m.Parameter(0); |
1382 Node* const p1 = m.Parameter(1); | 1489 Node* const p1 = m.Parameter(1); |
1383 Node* const p2 = m.Parameter(2); | 1490 Node* const p2 = m.Parameter(2); |
1384 Node* const n = m.Int32Add(p0, m.Int32Mul(p1, p2)); | 1491 Node* const n = m.Int32Add(p0, m.Int32Mul(p1, p2)); |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1994 ASSERT_EQ(3U, s[0]->InputCount()); | 2101 ASSERT_EQ(3U, s[0]->InputCount()); |
1995 EXPECT_EQ(lsb, s.ToInt32(s[0]->InputAt(1))); | 2102 EXPECT_EQ(lsb, s.ToInt32(s[0]->InputAt(1))); |
1996 EXPECT_EQ(width, s.ToInt32(s[0]->InputAt(2))); | 2103 EXPECT_EQ(width, s.ToInt32(s[0]->InputAt(2))); |
1997 } | 2104 } |
1998 } | 2105 } |
1999 } | 2106 } |
2000 | 2107 |
2001 } // namespace compiler | 2108 } // namespace compiler |
2002 } // namespace internal | 2109 } // namespace internal |
2003 } // namespace v8 | 2110 } // namespace v8 |
OLD | NEW |