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 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1191 bool (InstructionSelectorTest::Stream::*val_predicate)( | 1191 bool (InstructionSelectorTest::Stream::*val_predicate)( |
1192 const InstructionOperand*) const; | 1192 const InstructionOperand*) const; |
1193 const int32_t immediates[5]; | 1193 const int32_t immediates[5]; |
1194 }; | 1194 }; |
1195 | 1195 |
1196 | 1196 |
1197 std::ostream& operator<<(std::ostream& os, const MemoryAccessImm1& acc) { | 1197 std::ostream& operator<<(std::ostream& os, const MemoryAccessImm1& acc) { |
1198 return os << acc.type; | 1198 return os << acc.type; |
1199 } | 1199 } |
1200 | 1200 |
| 1201 struct MemoryAccessImm2 { |
| 1202 MachineType type; |
| 1203 ArchOpcode store_opcode; |
| 1204 ArchOpcode store_opcode_unaligned; |
| 1205 bool (InstructionSelectorTest::Stream::*val_predicate)( |
| 1206 const InstructionOperand*) const; |
| 1207 const int32_t immediates[40]; |
| 1208 }; |
| 1209 |
| 1210 std::ostream& operator<<(std::ostream& os, const MemoryAccessImm2& acc) { |
| 1211 return os << acc.type; |
| 1212 } |
1201 | 1213 |
1202 // ---------------------------------------------------------------------------- | 1214 // ---------------------------------------------------------------------------- |
1203 // Loads and stores immediate values | 1215 // Loads and stores immediate values |
1204 // ---------------------------------------------------------------------------- | 1216 // ---------------------------------------------------------------------------- |
1205 | 1217 |
1206 | 1218 |
1207 const MemoryAccessImm kMemoryAccessesImm[] = { | 1219 const MemoryAccessImm kMemoryAccessesImm[] = { |
1208 {MachineType::Int8(), | 1220 {MachineType::Int8(), |
1209 kMips64Lb, | 1221 kMips64Lb, |
1210 kMips64Sb, | 1222 kMips64Sb, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1298 kMips64Ldc1, | 1310 kMips64Ldc1, |
1299 kMips64Sdc1, | 1311 kMips64Sdc1, |
1300 &InstructionSelectorTest::Stream::IsDouble, | 1312 &InstructionSelectorTest::Stream::IsDouble, |
1301 {-65000, -55000, 32777, 55000, 65000}}, | 1313 {-65000, -55000, 32777, 55000, 65000}}, |
1302 {MachineType::Int64(), | 1314 {MachineType::Int64(), |
1303 kMips64Ld, | 1315 kMips64Ld, |
1304 kMips64Sd, | 1316 kMips64Sd, |
1305 &InstructionSelectorTest::Stream::IsInteger, | 1317 &InstructionSelectorTest::Stream::IsInteger, |
1306 {-65000, -55000, 32777, 55000, 65000}}}; | 1318 {-65000, -55000, 32777, 55000, 65000}}}; |
1307 | 1319 |
| 1320 const MemoryAccessImm2 kMemoryAccessesImmUnaligned[] = { |
| 1321 {MachineType::Int16(), |
| 1322 kMips64Ush, |
| 1323 kMips64Sh, |
| 1324 &InstructionSelectorTest::Stream::IsInteger, |
| 1325 {-4095, -3340, -3231, -3224, -3088, -1758, -1203, -123, -117, -91, |
| 1326 -89, -87, -86, -82, -44, -23, -3, 0, 7, 10, |
| 1327 39, 52, 69, 71, 91, 92, 107, 109, 115, 124, |
| 1328 286, 655, 1362, 1569, 2587, 3067, 3096, 3462, 3510, 4095}}, |
| 1329 {MachineType::Int32(), |
| 1330 kMips64Usw, |
| 1331 kMips64Sw, |
| 1332 &InstructionSelectorTest::Stream::IsInteger, |
| 1333 {-4095, -3340, -3231, -3224, -3088, -1758, -1203, -123, -117, -91, |
| 1334 -89, -87, -86, -82, -44, -23, -3, 0, 7, 10, |
| 1335 39, 52, 69, 71, 91, 92, 107, 109, 115, 124, |
| 1336 286, 655, 1362, 1569, 2587, 3067, 3096, 3462, 3510, 4095}}, |
| 1337 {MachineType::Int64(), |
| 1338 kMips64Usd, |
| 1339 kMips64Sd, |
| 1340 &InstructionSelectorTest::Stream::IsInteger, |
| 1341 {-4095, -3340, -3231, -3224, -3088, -1758, -1203, -123, -117, -91, |
| 1342 -89, -87, -86, -82, -44, -23, -3, 0, 7, 10, |
| 1343 39, 52, 69, 71, 91, 92, 107, 109, 115, 124, |
| 1344 286, 655, 1362, 1569, 2587, 3067, 3096, 3462, 3510, 4095}}, |
| 1345 {MachineType::Float32(), |
| 1346 kMips64Uswc1, |
| 1347 kMips64Swc1, |
| 1348 &InstructionSelectorTest::Stream::IsDouble, |
| 1349 {-4095, -3340, -3231, -3224, -3088, -1758, -1203, -123, -117, -91, |
| 1350 -89, -87, -86, -82, -44, -23, -3, 0, 7, 10, |
| 1351 39, 52, 69, 71, 91, 92, 107, 109, 115, 124, |
| 1352 286, 655, 1362, 1569, 2587, 3067, 3096, 3462, 3510, 4095}}, |
| 1353 {MachineType::Float64(), |
| 1354 kMips64Usdc1, |
| 1355 kMips64Sdc1, |
| 1356 &InstructionSelectorTest::Stream::IsDouble, |
| 1357 {-4095, -3340, -3231, -3224, -3088, -1758, -1203, -123, -117, -91, |
| 1358 -89, -87, -86, -82, -44, -23, -3, 0, 7, 10, |
| 1359 39, 52, 69, 71, 91, 92, 107, 109, 115, 124, |
| 1360 286, 655, 1362, 1569, 2587, 3067, 3096, 3462, 3510, 4095}}}; |
| 1361 |
1308 } // namespace | 1362 } // namespace |
1309 | 1363 |
1310 | 1364 |
1311 typedef InstructionSelectorTestWithParam<MemoryAccess> | 1365 typedef InstructionSelectorTestWithParam<MemoryAccess> |
1312 InstructionSelectorMemoryAccessTest; | 1366 InstructionSelectorMemoryAccessTest; |
1313 | 1367 |
1314 TEST_P(InstructionSelectorMemoryAccessTest, LoadWithParameters) { | 1368 TEST_P(InstructionSelectorMemoryAccessTest, LoadWithParameters) { |
1315 const MemoryAccess memacc = GetParam(); | 1369 const MemoryAccess memacc = GetParam(); |
1316 StreamBuilder m(this, memacc.type, MachineType::Pointer(), | 1370 StreamBuilder m(this, memacc.type, MachineType::Pointer(), |
1317 MachineType::Int32()); | 1371 MachineType::Int32()); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1384 ASSERT_EQ(1U, s.size()); | 1438 ASSERT_EQ(1U, s.size()); |
1385 EXPECT_EQ(memacc.store_opcode, s[0]->arch_opcode()); | 1439 EXPECT_EQ(memacc.store_opcode, s[0]->arch_opcode()); |
1386 EXPECT_EQ(kMode_MRI, s[0]->addressing_mode()); | 1440 EXPECT_EQ(kMode_MRI, s[0]->addressing_mode()); |
1387 ASSERT_EQ(3U, s[0]->InputCount()); | 1441 ASSERT_EQ(3U, s[0]->InputCount()); |
1388 ASSERT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind()); | 1442 ASSERT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind()); |
1389 EXPECT_EQ(index, s.ToInt32(s[0]->InputAt(1))); | 1443 EXPECT_EQ(index, s.ToInt32(s[0]->InputAt(1))); |
1390 EXPECT_EQ(0U, s[0]->OutputCount()); | 1444 EXPECT_EQ(0U, s[0]->OutputCount()); |
1391 } | 1445 } |
1392 } | 1446 } |
1393 | 1447 |
| 1448 TEST_P(InstructionSelectorMemoryAccessImmTest, StoreZero) { |
| 1449 const MemoryAccessImm memacc = GetParam(); |
| 1450 TRACED_FOREACH(int32_t, index, memacc.immediates) { |
| 1451 StreamBuilder m(this, MachineType::Int32(), MachineType::Pointer()); |
| 1452 m.Store(memacc.type.representation(), m.Parameter(0), |
| 1453 m.Int32Constant(index), m.Int32Constant(0), kNoWriteBarrier); |
| 1454 m.Return(m.Int32Constant(0)); |
| 1455 Stream s = m.Build(); |
| 1456 ASSERT_EQ(1U, s.size()); |
| 1457 EXPECT_EQ(memacc.store_opcode, s[0]->arch_opcode()); |
| 1458 EXPECT_EQ(kMode_MRI, s[0]->addressing_mode()); |
| 1459 ASSERT_EQ(3U, s[0]->InputCount()); |
| 1460 ASSERT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind()); |
| 1461 EXPECT_EQ(index, s.ToInt32(s[0]->InputAt(1))); |
| 1462 ASSERT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(2)->kind()); |
| 1463 EXPECT_EQ(0, s.ToInt64(s[0]->InputAt(2))); |
| 1464 EXPECT_EQ(0U, s[0]->OutputCount()); |
| 1465 } |
| 1466 } |
| 1467 |
1394 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, | 1468 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, |
1395 InstructionSelectorMemoryAccessImmTest, | 1469 InstructionSelectorMemoryAccessImmTest, |
1396 ::testing::ValuesIn(kMemoryAccessesImm)); | 1470 ::testing::ValuesIn(kMemoryAccessesImm)); |
1397 | 1471 |
| 1472 typedef InstructionSelectorTestWithParam<MemoryAccessImm2> |
| 1473 InstructionSelectorMemoryAccessUnalignedImmTest; |
| 1474 |
| 1475 TEST_P(InstructionSelectorMemoryAccessUnalignedImmTest, StoreZero) { |
| 1476 const MemoryAccessImm2 memacc = GetParam(); |
| 1477 TRACED_FOREACH(int32_t, index, memacc.immediates) { |
| 1478 StreamBuilder m(this, MachineType::Int32(), MachineType::Pointer()); |
| 1479 bool unaligned_store_supported = m.machine()->UnalignedStoreSupported( |
| 1480 MachineType::TypeForRepresentation(memacc.type.representation()), 1); |
| 1481 m.UnalignedStore(memacc.type.representation(), m.Parameter(0), |
| 1482 m.Int32Constant(index), m.Int32Constant(0)); |
| 1483 m.Return(m.Int32Constant(0)); |
| 1484 Stream s = m.Build(); |
| 1485 ASSERT_EQ(1U, s.size()); |
| 1486 EXPECT_EQ(unaligned_store_supported ? memacc.store_opcode_unaligned |
| 1487 : memacc.store_opcode, |
| 1488 s[0]->arch_opcode()); |
| 1489 EXPECT_EQ(kMode_MRI, s[0]->addressing_mode()); |
| 1490 ASSERT_EQ(3U, s[0]->InputCount()); |
| 1491 ASSERT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind()); |
| 1492 EXPECT_EQ(index, s.ToInt32(s[0]->InputAt(1))); |
| 1493 ASSERT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(2)->kind()); |
| 1494 EXPECT_EQ(0, s.ToInt64(s[0]->InputAt(2))); |
| 1495 EXPECT_EQ(0U, s[0]->OutputCount()); |
| 1496 } |
| 1497 } |
| 1498 |
| 1499 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, |
| 1500 InstructionSelectorMemoryAccessUnalignedImmTest, |
| 1501 ::testing::ValuesIn(kMemoryAccessesImmUnaligned)); |
1398 | 1502 |
1399 // ---------------------------------------------------------------------------- | 1503 // ---------------------------------------------------------------------------- |
1400 // Load/store offsets more than 16 bits. | 1504 // Load/store offsets more than 16 bits. |
1401 // ---------------------------------------------------------------------------- | 1505 // ---------------------------------------------------------------------------- |
1402 | 1506 |
1403 | 1507 |
1404 typedef InstructionSelectorTestWithParam<MemoryAccessImm1> | 1508 typedef InstructionSelectorTestWithParam<MemoryAccessImm1> |
1405 InstructionSelectorMemoryAccessImmMoreThan16bitTest; | 1509 InstructionSelectorMemoryAccessImmMoreThan16bitTest; |
1406 | 1510 |
1407 TEST_P(InstructionSelectorMemoryAccessImmMoreThan16bitTest, | 1511 TEST_P(InstructionSelectorMemoryAccessImmMoreThan16bitTest, |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1821 #endif | 1925 #endif |
1822 | 1926 |
1823 ASSERT_EQ(1U, s[0]->OutputCount()); | 1927 ASSERT_EQ(1U, s[0]->OutputCount()); |
1824 } | 1928 } |
1825 } | 1929 } |
1826 } | 1930 } |
1827 | 1931 |
1828 } // namespace compiler | 1932 } // namespace compiler |
1829 } // namespace internal | 1933 } // namespace internal |
1830 } // namespace v8 | 1934 } // namespace v8 |
OLD | NEW |