OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1333 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && | 1333 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
1334 instr->left()->RangeCanInclude(0) && divisor < 0) || | 1334 instr->left()->RangeCanInclude(0) && divisor < 0) || |
1335 (instr->CheckFlag(HValue::kCanOverflow) && | 1335 (instr->CheckFlag(HValue::kCanOverflow) && |
1336 instr->left()->RangeCanInclude(kMinInt) && divisor == -1) || | 1336 instr->left()->RangeCanInclude(kMinInt) && divisor == -1) || |
1337 (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) && | 1337 (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) && |
1338 divisor != 1 && divisor != -1); | 1338 divisor != 1 && divisor != -1); |
1339 return can_deopt ? AssignEnvironment(result) : result; | 1339 return can_deopt ? AssignEnvironment(result) : result; |
1340 } | 1340 } |
1341 | 1341 |
1342 | 1342 |
1343 LInstruction* LChunkBuilder::DoDivByConstI(HDiv* instr) { | |
1344 ASSERT(instr->representation().IsInteger32()); | |
1345 ASSERT(instr->left()->representation().Equals(instr->representation())); | |
1346 ASSERT(instr->right()->representation().Equals(instr->representation())); | |
1347 LOperand* dividend = UseRegister(instr->left()); | |
1348 int32_t divisor = instr->right()->GetInteger32Constant(); | |
1349 LOperand* temp1 = FixedTemp(eax); | |
1350 LOperand* temp2 = FixedTemp(edx); | |
1351 LInstruction* result = | |
1352 DefineFixed( | |
1353 new(zone()) LDivByConstI(dividend, divisor, temp1, temp2), edx); | |
1354 bool can_deopt = | |
1355 divisor == 0 || | |
1356 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && | |
1357 instr->left()->RangeCanInclude(0) && divisor < 0) || | |
1358 !instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32); | |
1359 return can_deopt ? AssignEnvironment(result) : result; | |
1360 } | |
1361 | |
1362 | |
1363 LInstruction* LChunkBuilder::DoDivI(HBinaryOperation* instr) { | 1343 LInstruction* LChunkBuilder::DoDivI(HBinaryOperation* instr) { |
1364 ASSERT(instr->representation().IsSmiOrInteger32()); | 1344 ASSERT(instr->representation().IsSmiOrInteger32()); |
1365 ASSERT(instr->left()->representation().Equals(instr->representation())); | 1345 ASSERT(instr->left()->representation().Equals(instr->representation())); |
1366 ASSERT(instr->right()->representation().Equals(instr->representation())); | 1346 ASSERT(instr->right()->representation().Equals(instr->representation())); |
1367 LOperand* dividend = UseFixed(instr->left(), eax); | 1347 LOperand* dividend = UseFixed(instr->left(), eax); |
1368 LOperand* divisor = UseRegister(instr->right()); | 1348 LOperand* divisor = UseRegister(instr->right()); |
1369 LOperand* temp = FixedTemp(edx); | 1349 LOperand* temp = FixedTemp(edx); |
1370 LInstruction* result = | 1350 LDivI* result = new(zone()) LDivI(dividend, divisor, temp); |
1371 DefineFixed(new(zone()) LDivI(dividend, divisor, temp), eax); | 1351 return AssignEnvironment(DefineFixed(result, eax)); |
1372 return AssignEnvironment(result); | |
1373 } | 1352 } |
1374 | 1353 |
1375 | 1354 |
1376 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { | 1355 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { |
1377 if (instr->representation().IsSmiOrInteger32()) { | 1356 if (instr->representation().IsSmiOrInteger32()) { |
1378 if (instr->RightIsPowerOf2()) { | 1357 return instr->RightIsPowerOf2() ? DoDivByPowerOf2I(instr) : DoDivI(instr); |
1379 return DoDivByPowerOf2I(instr); | |
1380 } else if (instr->right()->IsConstant()) { | |
1381 return DoDivByConstI(instr); | |
1382 } else { | |
1383 return DoDivI(instr); | |
1384 } | |
1385 } else if (instr->representation().IsDouble()) { | 1358 } else if (instr->representation().IsDouble()) { |
1386 return DoArithmeticD(Token::DIV, instr); | 1359 return DoArithmeticD(Token::DIV, instr); |
1387 } else { | 1360 } else { |
1388 return DoArithmeticT(Token::DIV, instr); | 1361 return DoArithmeticT(Token::DIV, instr); |
1389 } | 1362 } |
1390 } | 1363 } |
1391 | 1364 |
1392 | 1365 |
1393 LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) { | 1366 LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) { |
1394 LOperand* dividend = UseRegisterAtStart(instr->left()); | 1367 LOperand* dividend = UseRegisterAtStart(instr->left()); |
1395 int32_t divisor = instr->right()->GetInteger32Constant(); | 1368 int32_t divisor = instr->right()->GetInteger32Constant(); |
1396 LInstruction* result = | 1369 LInstruction* result = |
1397 DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(dividend, divisor)); | 1370 DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(dividend, divisor)); |
1398 bool can_deopt = | 1371 bool can_deopt = |
1399 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) || | 1372 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) || |
1400 (instr->left()->RangeCanInclude(kMinInt) && divisor == -1); | 1373 (instr->left()->RangeCanInclude(kMinInt) && divisor == -1); |
1401 return can_deopt ? AssignEnvironment(result) : result; | 1374 return can_deopt ? AssignEnvironment(result) : result; |
1402 } | 1375 } |
1403 | 1376 |
1404 | 1377 |
1405 LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) { | 1378 LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) { |
1406 ASSERT(instr->representation().IsInteger32()); | 1379 LOperand* dividend = UseFixed(instr->left(), eax); |
1407 ASSERT(instr->left()->representation().Equals(instr->representation())); | |
1408 ASSERT(instr->right()->representation().Equals(instr->representation())); | |
1409 LOperand* dividend = UseRegister(instr->left()); | |
1410 int32_t divisor = instr->right()->GetInteger32Constant(); | 1380 int32_t divisor = instr->right()->GetInteger32Constant(); |
1411 LOperand* temp1 = FixedTemp(eax); | 1381 LOperand* temp = TempRegister(); |
1412 LOperand* temp2 = FixedTemp(edx); | |
1413 LInstruction* result = | 1382 LInstruction* result = |
1414 DefineFixed(new(zone()) LFlooringDivByConstI(dividend, | 1383 DefineFixed( |
1415 divisor, | 1384 new(zone()) LFlooringDivByConstI(dividend, divisor, temp), edx); |
1416 temp1, | 1385 bool can_deopt = divisor <= 0; |
1417 temp2), | |
1418 edx); | |
1419 bool can_deopt = | |
1420 divisor == 0 || | |
1421 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && | |
1422 instr->left()->RangeCanInclude(0) && divisor < 0); | |
1423 return can_deopt ? AssignEnvironment(result) : result; | 1386 return can_deopt ? AssignEnvironment(result) : result; |
1424 } | 1387 } |
1425 | 1388 |
1426 | 1389 |
1427 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) { | 1390 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) { |
1428 if (instr->RightIsPowerOf2()) { | 1391 if (instr->RightIsPowerOf2()) { |
1429 return DoFlooringDivByPowerOf2I(instr); | 1392 return DoFlooringDivByPowerOf2I(instr); |
1430 } else if (instr->right()->IsConstant()) { | 1393 } else if (instr->right()->IsConstant()) { |
1431 return DoFlooringDivByConstI(instr); | 1394 return DoFlooringDivByConstI(instr); |
1432 } else { | 1395 } else { |
(...skipping 10 matching lines...) Expand all Loading... |
1443 int32_t divisor = instr->right()->GetInteger32Constant(); | 1406 int32_t divisor = instr->right()->GetInteger32Constant(); |
1444 LInstruction* result = | 1407 LInstruction* result = |
1445 DefineSameAsFirst(new(zone()) LModByPowerOf2I(dividend, divisor)); | 1408 DefineSameAsFirst(new(zone()) LModByPowerOf2I(dividend, divisor)); |
1446 bool can_deopt = | 1409 bool can_deopt = |
1447 instr->CheckFlag(HValue::kBailoutOnMinusZero) && | 1410 instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
1448 instr->left()->CanBeNegative(); | 1411 instr->left()->CanBeNegative(); |
1449 return can_deopt ? AssignEnvironment(result) : result; | 1412 return can_deopt ? AssignEnvironment(result) : result; |
1450 } | 1413 } |
1451 | 1414 |
1452 | 1415 |
1453 LInstruction* LChunkBuilder::DoModByConstI(HMod* instr) { | |
1454 ASSERT(instr->representation().IsSmiOrInteger32()); | |
1455 ASSERT(instr->left()->representation().Equals(instr->representation())); | |
1456 ASSERT(instr->right()->representation().Equals(instr->representation())); | |
1457 LOperand* dividend = UseRegister(instr->left()); | |
1458 int32_t divisor = instr->right()->GetInteger32Constant(); | |
1459 LOperand* temp1 = FixedTemp(eax); | |
1460 LOperand* temp2 = FixedTemp(edx); | |
1461 LInstruction* result = | |
1462 DefineFixed( | |
1463 new(zone()) LModByConstI(dividend, divisor, temp1, temp2), eax); | |
1464 bool can_deopt = | |
1465 divisor == 0 || | |
1466 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && | |
1467 instr->left()->CanBeNegative()); | |
1468 return can_deopt ? AssignEnvironment(result) : result; | |
1469 } | |
1470 | |
1471 | |
1472 LInstruction* LChunkBuilder::DoModI(HMod* instr) { | 1416 LInstruction* LChunkBuilder::DoModI(HMod* instr) { |
1473 ASSERT(instr->representation().IsSmiOrInteger32()); | 1417 ASSERT(instr->representation().IsSmiOrInteger32()); |
1474 ASSERT(instr->left()->representation().Equals(instr->representation())); | 1418 ASSERT(instr->left()->representation().Equals(instr->representation())); |
1475 ASSERT(instr->right()->representation().Equals(instr->representation())); | 1419 ASSERT(instr->right()->representation().Equals(instr->representation())); |
1476 LOperand* dividend = UseFixed(instr->left(), eax); | 1420 LOperand* dividend = UseFixed(instr->left(), eax); |
1477 LOperand* divisor = UseRegister(instr->right()); | 1421 LOperand* divisor = UseRegister(instr->right()); |
1478 LOperand* temp = FixedTemp(edx); | 1422 LOperand* temp = FixedTemp(edx); |
1479 LInstruction* result = | 1423 LInstruction* result = |
1480 DefineFixed(new(zone()) LModI(dividend, divisor, temp), edx); | 1424 DefineFixed(new(zone()) LModI(dividend, divisor, temp), edx); |
1481 bool can_deopt = (instr->right()->CanBeZero() || | 1425 bool can_deopt = (instr->right()->CanBeZero() || |
1482 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && | 1426 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
1483 instr->left()->RangeCanInclude(kMinInt) && | 1427 instr->left()->RangeCanInclude(kMinInt) && |
1484 instr->right()->RangeCanInclude(-1)) || | 1428 instr->right()->RangeCanInclude(-1)) || |
1485 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && | 1429 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
1486 instr->left()->CanBeNegative() && | 1430 instr->left()->CanBeNegative() && |
1487 instr->CanBeZero())); | 1431 instr->CanBeZero())); |
1488 return can_deopt ? AssignEnvironment(result) : result; | 1432 return can_deopt ? AssignEnvironment(result) : result; |
1489 } | 1433 } |
1490 | 1434 |
1491 | 1435 |
1492 LInstruction* LChunkBuilder::DoMod(HMod* instr) { | 1436 LInstruction* LChunkBuilder::DoMod(HMod* instr) { |
1493 if (instr->representation().IsSmiOrInteger32()) { | 1437 if (instr->representation().IsSmiOrInteger32()) { |
1494 if (instr->RightIsPowerOf2()) { | 1438 return instr->RightIsPowerOf2() ? DoModByPowerOf2I(instr) : DoModI(instr); |
1495 return DoModByPowerOf2I(instr); | |
1496 } else if (instr->right()->IsConstant()) { | |
1497 return DoModByConstI(instr); | |
1498 } else { | |
1499 return DoModI(instr); | |
1500 } | |
1501 } else if (instr->representation().IsDouble()) { | 1439 } else if (instr->representation().IsDouble()) { |
1502 return DoArithmeticD(Token::MOD, instr); | 1440 return DoArithmeticD(Token::MOD, instr); |
1503 } else { | 1441 } else { |
1504 return DoArithmeticT(Token::MOD, instr); | 1442 return DoArithmeticT(Token::MOD, instr); |
1505 } | 1443 } |
1506 } | 1444 } |
1507 | 1445 |
1508 | 1446 |
1509 LInstruction* LChunkBuilder::DoMul(HMul* instr) { | 1447 LInstruction* LChunkBuilder::DoMul(HMul* instr) { |
1510 if (instr->representation().IsSmiOrInteger32()) { | 1448 if (instr->representation().IsSmiOrInteger32()) { |
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2668 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { | 2606 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { |
2669 LOperand* object = UseRegister(instr->object()); | 2607 LOperand* object = UseRegister(instr->object()); |
2670 LOperand* index = UseTempRegister(instr->index()); | 2608 LOperand* index = UseTempRegister(instr->index()); |
2671 return DefineSameAsFirst(new(zone()) LLoadFieldByIndex(object, index)); | 2609 return DefineSameAsFirst(new(zone()) LLoadFieldByIndex(object, index)); |
2672 } | 2610 } |
2673 | 2611 |
2674 | 2612 |
2675 } } // namespace v8::internal | 2613 } } // namespace v8::internal |
2676 | 2614 |
2677 #endif // V8_TARGET_ARCH_IA32 | 2615 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |