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 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1171 Stream s = m.Build(); | 1171 Stream s = m.Build(); |
1172 ASSERT_EQ(1U, s.size()); | 1172 ASSERT_EQ(1U, s.size()); |
1173 EXPECT_EQ(kArm64TestAndBranch32, s[0]->arch_opcode()); | 1173 EXPECT_EQ(kArm64TestAndBranch32, s[0]->arch_opcode()); |
1174 EXPECT_EQ(kEqual, s[0]->flags_condition()); | 1174 EXPECT_EQ(kEqual, s[0]->flags_condition()); |
1175 EXPECT_EQ(4U, s[0]->InputCount()); | 1175 EXPECT_EQ(4U, s[0]->InputCount()); |
1176 EXPECT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind()); | 1176 EXPECT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind()); |
1177 EXPECT_EQ(bit, s.ToInt32(s[0]->InputAt(1))); | 1177 EXPECT_EQ(bit, s.ToInt32(s[0]->InputAt(1))); |
1178 } | 1178 } |
1179 } | 1179 } |
1180 | 1180 |
1181 | |
1182 TEST_F(InstructionSelectorTest, Word32AndBranchWithOneBitMaskOnLeft) { | 1181 TEST_F(InstructionSelectorTest, Word32AndBranchWithOneBitMaskOnLeft) { |
1183 TRACED_FORRANGE(int, bit, 0, 31) { | 1182 TRACED_FORRANGE(int, bit, 0, 31) { |
1184 uint32_t mask = 1 << bit; | 1183 uint32_t mask = 1 << bit; |
1185 StreamBuilder m(this, MachineType::Int32(), MachineType::Int32()); | 1184 StreamBuilder m(this, MachineType::Int32(), MachineType::Int32()); |
1186 RawMachineLabel a, b; | 1185 RawMachineLabel a, b; |
1187 m.Branch(m.Word32And(m.Int32Constant(mask), m.Parameter(0)), &a, &b); | 1186 m.Branch(m.Word32And(m.Int32Constant(mask), m.Parameter(0)), &a, &b); |
1188 m.Bind(&a); | 1187 m.Bind(&a); |
1189 m.Return(m.Int32Constant(1)); | 1188 m.Return(m.Int32Constant(1)); |
1190 m.Bind(&b); | 1189 m.Bind(&b); |
1191 m.Return(m.Int32Constant(0)); | 1190 m.Return(m.Int32Constant(0)); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 Stream s = m.Build(); | 1253 Stream s = m.Build(); |
1255 ASSERT_EQ(1U, s.size()); | 1254 ASSERT_EQ(1U, s.size()); |
1256 EXPECT_EQ(kArm64TestAndBranch, s[0]->arch_opcode()); | 1255 EXPECT_EQ(kArm64TestAndBranch, s[0]->arch_opcode()); |
1257 EXPECT_EQ(kNotEqual, s[0]->flags_condition()); | 1256 EXPECT_EQ(kNotEqual, s[0]->flags_condition()); |
1258 EXPECT_EQ(4U, s[0]->InputCount()); | 1257 EXPECT_EQ(4U, s[0]->InputCount()); |
1259 EXPECT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind()); | 1258 EXPECT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind()); |
1260 EXPECT_EQ(bit, s.ToInt64(s[0]->InputAt(1))); | 1259 EXPECT_EQ(bit, s.ToInt64(s[0]->InputAt(1))); |
1261 } | 1260 } |
1262 } | 1261 } |
1263 | 1262 |
| 1263 TEST_F(InstructionSelectorTest, Word32EqualZeroAndBranchWithOneBitMask) { |
| 1264 TRACED_FORRANGE(int, bit, 0, 31) { |
| 1265 uint32_t mask = 1 << bit; |
| 1266 StreamBuilder m(this, MachineType::Int32(), MachineType::Int32()); |
| 1267 RawMachineLabel a, b; |
| 1268 m.Branch(m.Word32Equal(m.Word32And(m.Int32Constant(mask), m.Parameter(0)), |
| 1269 m.Int32Constant(0)), |
| 1270 &a, &b); |
| 1271 m.Bind(&a); |
| 1272 m.Return(m.Int32Constant(1)); |
| 1273 m.Bind(&b); |
| 1274 m.Return(m.Int32Constant(0)); |
| 1275 Stream s = m.Build(); |
| 1276 ASSERT_EQ(1U, s.size()); |
| 1277 EXPECT_EQ(kArm64TestAndBranch32, s[0]->arch_opcode()); |
| 1278 EXPECT_EQ(kEqual, s[0]->flags_condition()); |
| 1279 EXPECT_EQ(4U, s[0]->InputCount()); |
| 1280 EXPECT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind()); |
| 1281 EXPECT_EQ(bit, s.ToInt32(s[0]->InputAt(1))); |
| 1282 } |
| 1283 |
| 1284 TRACED_FORRANGE(int, bit, 0, 31) { |
| 1285 uint32_t mask = 1 << bit; |
| 1286 StreamBuilder m(this, MachineType::Int32(), MachineType::Int32()); |
| 1287 RawMachineLabel a, b; |
| 1288 m.Branch( |
| 1289 m.Word32NotEqual(m.Word32And(m.Int32Constant(mask), m.Parameter(0)), |
| 1290 m.Int32Constant(0)), |
| 1291 &a, &b); |
| 1292 m.Bind(&a); |
| 1293 m.Return(m.Int32Constant(1)); |
| 1294 m.Bind(&b); |
| 1295 m.Return(m.Int32Constant(0)); |
| 1296 Stream s = m.Build(); |
| 1297 ASSERT_EQ(1U, s.size()); |
| 1298 EXPECT_EQ(kArm64TestAndBranch32, s[0]->arch_opcode()); |
| 1299 EXPECT_EQ(kNotEqual, s[0]->flags_condition()); |
| 1300 EXPECT_EQ(4U, s[0]->InputCount()); |
| 1301 EXPECT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind()); |
| 1302 EXPECT_EQ(bit, s.ToInt32(s[0]->InputAt(1))); |
| 1303 } |
| 1304 } |
| 1305 |
| 1306 TEST_F(InstructionSelectorTest, Word64EqualZeroAndBranchWithOneBitMask) { |
| 1307 TRACED_FORRANGE(int, bit, 0, 63) { |
| 1308 uint64_t mask = V8_UINT64_C(1) << bit; |
| 1309 StreamBuilder m(this, MachineType::Int64(), MachineType::Int64()); |
| 1310 RawMachineLabel a, b; |
| 1311 m.Branch(m.Word64Equal(m.Word64And(m.Int64Constant(mask), m.Parameter(0)), |
| 1312 m.Int64Constant(0)), |
| 1313 &a, &b); |
| 1314 m.Bind(&a); |
| 1315 m.Return(m.Int64Constant(1)); |
| 1316 m.Bind(&b); |
| 1317 m.Return(m.Int64Constant(0)); |
| 1318 Stream s = m.Build(); |
| 1319 ASSERT_EQ(1U, s.size()); |
| 1320 EXPECT_EQ(kArm64TestAndBranch, s[0]->arch_opcode()); |
| 1321 EXPECT_EQ(kEqual, s[0]->flags_condition()); |
| 1322 EXPECT_EQ(4U, s[0]->InputCount()); |
| 1323 EXPECT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind()); |
| 1324 EXPECT_EQ(bit, s.ToInt64(s[0]->InputAt(1))); |
| 1325 } |
| 1326 |
| 1327 TRACED_FORRANGE(int, bit, 0, 63) { |
| 1328 uint64_t mask = V8_UINT64_C(1) << bit; |
| 1329 StreamBuilder m(this, MachineType::Int64(), MachineType::Int64()); |
| 1330 RawMachineLabel a, b; |
| 1331 m.Branch( |
| 1332 m.Word64NotEqual(m.Word64And(m.Int64Constant(mask), m.Parameter(0)), |
| 1333 m.Int64Constant(0)), |
| 1334 &a, &b); |
| 1335 m.Bind(&a); |
| 1336 m.Return(m.Int64Constant(1)); |
| 1337 m.Bind(&b); |
| 1338 m.Return(m.Int64Constant(0)); |
| 1339 Stream s = m.Build(); |
| 1340 ASSERT_EQ(1U, s.size()); |
| 1341 EXPECT_EQ(kArm64TestAndBranch, s[0]->arch_opcode()); |
| 1342 EXPECT_EQ(kNotEqual, s[0]->flags_condition()); |
| 1343 EXPECT_EQ(4U, s[0]->InputCount()); |
| 1344 EXPECT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind()); |
| 1345 EXPECT_EQ(bit, s.ToInt64(s[0]->InputAt(1))); |
| 1346 } |
| 1347 } |
1264 | 1348 |
1265 TEST_F(InstructionSelectorTest, CompareAgainstZeroAndBranch) { | 1349 TEST_F(InstructionSelectorTest, CompareAgainstZeroAndBranch) { |
1266 { | 1350 { |
1267 StreamBuilder m(this, MachineType::Int32(), MachineType::Int32()); | 1351 StreamBuilder m(this, MachineType::Int32(), MachineType::Int32()); |
1268 RawMachineLabel a, b; | 1352 RawMachineLabel a, b; |
1269 Node* p0 = m.Parameter(0); | 1353 Node* p0 = m.Parameter(0); |
1270 m.Branch(p0, &a, &b); | 1354 m.Branch(p0, &a, &b); |
1271 m.Bind(&a); | 1355 m.Bind(&a); |
1272 m.Return(m.Int32Constant(1)); | 1356 m.Return(m.Int32Constant(1)); |
1273 m.Bind(&b); | 1357 m.Bind(&b); |
(...skipping 17 matching lines...) Expand all Loading... |
1291 m.Return(m.Int32Constant(0)); | 1375 m.Return(m.Int32Constant(0)); |
1292 Stream s = m.Build(); | 1376 Stream s = m.Build(); |
1293 ASSERT_EQ(1U, s.size()); | 1377 ASSERT_EQ(1U, s.size()); |
1294 EXPECT_EQ(kArm64CompareAndBranch32, s[0]->arch_opcode()); | 1378 EXPECT_EQ(kArm64CompareAndBranch32, s[0]->arch_opcode()); |
1295 EXPECT_EQ(kEqual, s[0]->flags_condition()); | 1379 EXPECT_EQ(kEqual, s[0]->flags_condition()); |
1296 EXPECT_EQ(3U, s[0]->InputCount()); | 1380 EXPECT_EQ(3U, s[0]->InputCount()); |
1297 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); | 1381 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); |
1298 } | 1382 } |
1299 } | 1383 } |
1300 | 1384 |
| 1385 TEST_F(InstructionSelectorTest, EqualZeroAndBranch) { |
| 1386 { |
| 1387 StreamBuilder m(this, MachineType::Int32(), MachineType::Int32()); |
| 1388 RawMachineLabel a, b; |
| 1389 Node* p0 = m.Parameter(0); |
| 1390 m.Branch(m.Word32Equal(p0, m.Int32Constant(0)), &a, &b); |
| 1391 m.Bind(&a); |
| 1392 m.Return(m.Int32Constant(1)); |
| 1393 m.Bind(&b); |
| 1394 m.Return(m.Int32Constant(0)); |
| 1395 Stream s = m.Build(); |
| 1396 ASSERT_EQ(1U, s.size()); |
| 1397 EXPECT_EQ(kArm64CompareAndBranch32, s[0]->arch_opcode()); |
| 1398 EXPECT_EQ(kEqual, s[0]->flags_condition()); |
| 1399 EXPECT_EQ(3U, s[0]->InputCount()); |
| 1400 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); |
| 1401 } |
| 1402 |
| 1403 { |
| 1404 StreamBuilder m(this, MachineType::Int32(), MachineType::Int32()); |
| 1405 RawMachineLabel a, b; |
| 1406 Node* p0 = m.Parameter(0); |
| 1407 m.Branch(m.Word32NotEqual(p0, m.Int32Constant(0)), &a, &b); |
| 1408 m.Bind(&a); |
| 1409 m.Return(m.Int32Constant(1)); |
| 1410 m.Bind(&b); |
| 1411 m.Return(m.Int32Constant(0)); |
| 1412 Stream s = m.Build(); |
| 1413 ASSERT_EQ(1U, s.size()); |
| 1414 EXPECT_EQ(kArm64CompareAndBranch32, s[0]->arch_opcode()); |
| 1415 EXPECT_EQ(kNotEqual, s[0]->flags_condition()); |
| 1416 EXPECT_EQ(3U, s[0]->InputCount()); |
| 1417 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); |
| 1418 } |
| 1419 |
| 1420 { |
| 1421 StreamBuilder m(this, MachineType::Int64(), MachineType::Int64()); |
| 1422 RawMachineLabel a, b; |
| 1423 Node* p0 = m.Parameter(0); |
| 1424 m.Branch(m.Word64Equal(p0, m.Int64Constant(0)), &a, &b); |
| 1425 m.Bind(&a); |
| 1426 m.Return(m.Int64Constant(1)); |
| 1427 m.Bind(&b); |
| 1428 m.Return(m.Int64Constant(0)); |
| 1429 Stream s = m.Build(); |
| 1430 ASSERT_EQ(1U, s.size()); |
| 1431 EXPECT_EQ(kArm64CompareAndBranch, s[0]->arch_opcode()); |
| 1432 EXPECT_EQ(kEqual, s[0]->flags_condition()); |
| 1433 EXPECT_EQ(3U, s[0]->InputCount()); |
| 1434 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); |
| 1435 } |
| 1436 |
| 1437 { |
| 1438 StreamBuilder m(this, MachineType::Int64(), MachineType::Int64()); |
| 1439 RawMachineLabel a, b; |
| 1440 Node* p0 = m.Parameter(0); |
| 1441 m.Branch(m.Word64NotEqual(p0, m.Int64Constant(0)), &a, &b); |
| 1442 m.Bind(&a); |
| 1443 m.Return(m.Int64Constant(1)); |
| 1444 m.Bind(&b); |
| 1445 m.Return(m.Int64Constant(0)); |
| 1446 Stream s = m.Build(); |
| 1447 ASSERT_EQ(1U, s.size()); |
| 1448 EXPECT_EQ(kArm64CompareAndBranch, s[0]->arch_opcode()); |
| 1449 EXPECT_EQ(kNotEqual, s[0]->flags_condition()); |
| 1450 EXPECT_EQ(3U, s[0]->InputCount()); |
| 1451 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); |
| 1452 } |
| 1453 } |
1301 | 1454 |
1302 // ----------------------------------------------------------------------------- | 1455 // ----------------------------------------------------------------------------- |
1303 // Add and subtract instructions with overflow. | 1456 // Add and subtract instructions with overflow. |
1304 | 1457 |
1305 | 1458 |
1306 typedef InstructionSelectorTestWithParam<MachInst2> | 1459 typedef InstructionSelectorTestWithParam<MachInst2> |
1307 InstructionSelectorOvfAddSubTest; | 1460 InstructionSelectorOvfAddSubTest; |
1308 | 1461 |
1309 | 1462 |
1310 TEST_P(InstructionSelectorOvfAddSubTest, OvfParameter) { | 1463 TEST_P(InstructionSelectorOvfAddSubTest, OvfParameter) { |
(...skipping 2289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3600 EXPECT_EQ(kArm64Float64Neg, s[0]->arch_opcode()); | 3753 EXPECT_EQ(kArm64Float64Neg, s[0]->arch_opcode()); |
3601 ASSERT_EQ(1U, s[0]->InputCount()); | 3754 ASSERT_EQ(1U, s[0]->InputCount()); |
3602 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); | 3755 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); |
3603 ASSERT_EQ(1U, s[0]->OutputCount()); | 3756 ASSERT_EQ(1U, s[0]->OutputCount()); |
3604 EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output())); | 3757 EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output())); |
3605 } | 3758 } |
3606 | 3759 |
3607 } // namespace compiler | 3760 } // namespace compiler |
3608 } // namespace internal | 3761 } // namespace internal |
3609 } // namespace v8 | 3762 } // namespace v8 |
OLD | NEW |