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 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1314 | 1314 |
1315 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); | 1315 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); |
1316 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand()); | 1316 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand()); |
1317 return DefineSameAsFirst(new(zone()) LBitI(left, right)); | 1317 return DefineSameAsFirst(new(zone()) LBitI(left, right)); |
1318 } else { | 1318 } else { |
1319 return DoArithmeticT(instr->op(), instr); | 1319 return DoArithmeticT(instr->op(), instr); |
1320 } | 1320 } |
1321 } | 1321 } |
1322 | 1322 |
1323 | 1323 |
| 1324 LInstruction* LChunkBuilder::DoDivByPowerOf2I(HDiv* instr) { |
| 1325 ASSERT(instr->representation().IsSmiOrInteger32()); |
| 1326 ASSERT(instr->left()->representation().Equals(instr->representation())); |
| 1327 ASSERT(instr->right()->representation().Equals(instr->representation())); |
| 1328 LOperand* dividend = UseRegister(instr->left()); |
| 1329 int32_t divisor = instr->right()->GetInteger32Constant(); |
| 1330 LInstruction* result = |
| 1331 DefineAsRegister(new(zone()) LDivByPowerOf2I(dividend, divisor)); |
| 1332 bool can_deopt = |
| 1333 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
| 1334 instr->left()->RangeCanInclude(0) && divisor < 0) || |
| 1335 (instr->CheckFlag(HValue::kCanOverflow) && |
| 1336 instr->left()->RangeCanInclude(kMinInt) && divisor == -1) || |
| 1337 (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) && |
| 1338 divisor != 1 && divisor != -1); |
| 1339 return can_deopt ? AssignEnvironment(result) : result; |
| 1340 } |
| 1341 |
| 1342 |
| 1343 LInstruction* LChunkBuilder::DoDivI(HBinaryOperation* instr) { |
| 1344 ASSERT(instr->representation().IsSmiOrInteger32()); |
| 1345 ASSERT(instr->left()->representation().Equals(instr->representation())); |
| 1346 ASSERT(instr->right()->representation().Equals(instr->representation())); |
| 1347 LOperand* dividend = UseFixed(instr->left(), eax); |
| 1348 LOperand* divisor = UseRegister(instr->right()); |
| 1349 LOperand* temp = FixedTemp(edx); |
| 1350 LDivI* result = new(zone()) LDivI(dividend, divisor, temp); |
| 1351 return AssignEnvironment(DefineFixed(result, eax)); |
| 1352 } |
| 1353 |
| 1354 |
1324 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { | 1355 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { |
1325 if (instr->representation().IsSmiOrInteger32()) { | 1356 if (instr->representation().IsSmiOrInteger32()) { |
1326 ASSERT(instr->left()->representation().Equals(instr->representation())); | 1357 return instr->RightIsPowerOf2() ? DoDivByPowerOf2I(instr) : DoDivI(instr); |
1327 ASSERT(instr->right()->representation().Equals(instr->representation())); | |
1328 if (instr->RightIsPowerOf2()) { | |
1329 ASSERT(!instr->CheckFlag(HValue::kCanBeDivByZero)); | |
1330 LOperand* value = UseRegister(instr->left()); | |
1331 LDivI* div = | |
1332 new(zone()) LDivI(value, UseOrConstant(instr->right()), NULL); | |
1333 return AssignEnvironment(DefineAsRegister(div)); | |
1334 } | |
1335 // The temporary operand is necessary to ensure that right is not allocated | |
1336 // into edx. | |
1337 LOperand* temp = FixedTemp(edx); | |
1338 LOperand* dividend = UseFixed(instr->left(), eax); | |
1339 LOperand* divisor = UseRegister(instr->right()); | |
1340 LDivI* result = new(zone()) LDivI(dividend, divisor, temp); | |
1341 return AssignEnvironment(DefineFixed(result, eax)); | |
1342 } else if (instr->representation().IsDouble()) { | 1358 } else if (instr->representation().IsDouble()) { |
1343 return DoArithmeticD(Token::DIV, instr); | 1359 return DoArithmeticD(Token::DIV, instr); |
1344 } else { | 1360 } else { |
1345 return DoArithmeticT(Token::DIV, instr); | 1361 return DoArithmeticT(Token::DIV, instr); |
1346 } | 1362 } |
1347 } | 1363 } |
1348 | 1364 |
1349 | 1365 |
| 1366 LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) { |
| 1367 LOperand* dividend = UseRegisterAtStart(instr->left()); |
| 1368 int32_t divisor = instr->right()->GetInteger32Constant(); |
| 1369 LInstruction* result = |
| 1370 DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(dividend, divisor)); |
| 1371 bool can_deopt = |
| 1372 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) || |
| 1373 (instr->left()->RangeCanInclude(kMinInt) && divisor == -1); |
| 1374 return can_deopt ? AssignEnvironment(result) : result; |
| 1375 } |
| 1376 |
| 1377 |
| 1378 LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) { |
| 1379 LOperand* dividend = UseFixed(instr->left(), eax); |
| 1380 int32_t divisor = instr->right()->GetInteger32Constant(); |
| 1381 LOperand* temp = TempRegister(); |
| 1382 LInstruction* result = |
| 1383 DefineFixed( |
| 1384 new(zone()) LFlooringDivByConstI(dividend, divisor, temp), edx); |
| 1385 bool can_deopt = divisor <= 0; |
| 1386 return can_deopt ? AssignEnvironment(result) : result; |
| 1387 } |
| 1388 |
| 1389 |
1350 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) { | 1390 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) { |
1351 HValue* right = instr->right(); | 1391 if (instr->RightIsPowerOf2()) { |
1352 if (!right->IsConstant()) { | 1392 return DoFlooringDivByPowerOf2I(instr); |
1353 ASSERT(right->representation().IsInteger32()); | 1393 } else if (instr->right()->IsConstant()) { |
1354 // The temporary operand is necessary to ensure that right is not allocated | 1394 return DoFlooringDivByConstI(instr); |
1355 // into edx. | |
1356 LOperand* temp = FixedTemp(edx); | |
1357 LOperand* dividend = UseFixed(instr->left(), eax); | |
1358 LOperand* divisor = UseRegister(instr->right()); | |
1359 LDivI* flooring_div = new(zone()) LDivI(dividend, divisor, temp); | |
1360 return AssignEnvironment(DefineFixed(flooring_div, eax)); | |
1361 } | |
1362 | |
1363 ASSERT(right->IsConstant() && HConstant::cast(right)->HasInteger32Value()); | |
1364 LOperand* divisor = chunk_->DefineConstantOperand(HConstant::cast(right)); | |
1365 int32_t divisor_si = HConstant::cast(right)->Integer32Value(); | |
1366 if (divisor_si == 0) { | |
1367 LOperand* dividend = UseRegister(instr->left()); | |
1368 return AssignEnvironment(DefineAsRegister( | |
1369 new(zone()) LMathFloorOfDiv(dividend, divisor, NULL))); | |
1370 } else if (IsPowerOf2(abs(divisor_si))) { | |
1371 // use dividend as temp if divisor < 0 && divisor != -1 | |
1372 LOperand* dividend = divisor_si < -1 ? UseTempRegister(instr->left()) : | |
1373 UseRegisterAtStart(instr->left()); | |
1374 LInstruction* result = DefineAsRegister( | |
1375 new(zone()) LMathFloorOfDiv(dividend, divisor, NULL)); | |
1376 return divisor_si < 0 ? AssignEnvironment(result) : result; | |
1377 } else { | 1395 } else { |
1378 // needs edx:eax, plus a temp | 1396 return DoDivI(instr); |
1379 LOperand* dividend = UseFixed(instr->left(), eax); | |
1380 LOperand* temp = TempRegister(); | |
1381 LInstruction* result = DefineFixed( | |
1382 new(zone()) LMathFloorOfDiv(dividend, divisor, temp), edx); | |
1383 return divisor_si < 0 ? AssignEnvironment(result) : result; | |
1384 } | 1397 } |
1385 } | 1398 } |
1386 | 1399 |
1387 | 1400 |
| 1401 LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) { |
| 1402 ASSERT(instr->representation().IsSmiOrInteger32()); |
| 1403 ASSERT(instr->left()->representation().Equals(instr->representation())); |
| 1404 ASSERT(instr->right()->representation().Equals(instr->representation())); |
| 1405 LOperand* dividend = UseRegisterAtStart(instr->left()); |
| 1406 int32_t divisor = instr->right()->GetInteger32Constant(); |
| 1407 LInstruction* result = |
| 1408 DefineSameAsFirst(new(zone()) LModByPowerOf2I(dividend, divisor)); |
| 1409 bool can_deopt = |
| 1410 instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
| 1411 instr->left()->CanBeNegative(); |
| 1412 return can_deopt ? AssignEnvironment(result) : result; |
| 1413 } |
| 1414 |
| 1415 |
| 1416 LInstruction* LChunkBuilder::DoModI(HMod* instr) { |
| 1417 ASSERT(instr->representation().IsSmiOrInteger32()); |
| 1418 ASSERT(instr->left()->representation().Equals(instr->representation())); |
| 1419 ASSERT(instr->right()->representation().Equals(instr->representation())); |
| 1420 LOperand* dividend = UseFixed(instr->left(), eax); |
| 1421 LOperand* divisor = UseRegister(instr->right()); |
| 1422 LOperand* temp = FixedTemp(edx); |
| 1423 LInstruction* result = |
| 1424 DefineFixed(new(zone()) LModI(dividend, divisor, temp), edx); |
| 1425 bool can_deopt = (instr->right()->CanBeZero() || |
| 1426 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
| 1427 instr->left()->RangeCanInclude(kMinInt) && |
| 1428 instr->right()->RangeCanInclude(-1)) || |
| 1429 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
| 1430 instr->left()->CanBeNegative() && |
| 1431 instr->CanBeZero())); |
| 1432 return can_deopt ? AssignEnvironment(result) : result; |
| 1433 } |
| 1434 |
| 1435 |
1388 LInstruction* LChunkBuilder::DoMod(HMod* instr) { | 1436 LInstruction* LChunkBuilder::DoMod(HMod* instr) { |
1389 HValue* left = instr->left(); | |
1390 HValue* right = instr->right(); | |
1391 if (instr->representation().IsSmiOrInteger32()) { | 1437 if (instr->representation().IsSmiOrInteger32()) { |
1392 ASSERT(instr->left()->representation().Equals(instr->representation())); | 1438 return instr->RightIsPowerOf2() ? DoModByPowerOf2I(instr) : DoModI(instr); |
1393 ASSERT(instr->right()->representation().Equals(instr->representation())); | |
1394 | |
1395 if (instr->RightIsPowerOf2()) { | |
1396 ASSERT(!right->CanBeZero()); | |
1397 LModI* mod = new(zone()) LModI(UseRegisterAtStart(left), | |
1398 UseOrConstant(right), | |
1399 NULL); | |
1400 LInstruction* result = DefineSameAsFirst(mod); | |
1401 return (left->CanBeNegative() && | |
1402 instr->CheckFlag(HValue::kBailoutOnMinusZero)) | |
1403 ? AssignEnvironment(result) | |
1404 : result; | |
1405 return AssignEnvironment(DefineSameAsFirst(mod)); | |
1406 } else { | |
1407 // The temporary operand is necessary to ensure that right is not | |
1408 // allocated into edx. | |
1409 LModI* mod = new(zone()) LModI(UseFixed(left, eax), | |
1410 UseRegister(right), | |
1411 FixedTemp(edx)); | |
1412 LInstruction* result = DefineFixed(mod, edx); | |
1413 return (right->CanBeZero() || | |
1414 (left->RangeCanInclude(kMinInt) && | |
1415 right->RangeCanInclude(-1) && | |
1416 instr->CheckFlag(HValue::kBailoutOnMinusZero)) || | |
1417 (left->CanBeNegative() && | |
1418 instr->CanBeZero() && | |
1419 instr->CheckFlag(HValue::kBailoutOnMinusZero))) | |
1420 ? AssignEnvironment(result) | |
1421 : result; | |
1422 } | |
1423 } else if (instr->representation().IsDouble()) { | 1439 } else if (instr->representation().IsDouble()) { |
1424 return DoArithmeticD(Token::MOD, instr); | 1440 return DoArithmeticD(Token::MOD, instr); |
1425 } else { | 1441 } else { |
1426 return DoArithmeticT(Token::MOD, instr); | 1442 return DoArithmeticT(Token::MOD, instr); |
1427 } | 1443 } |
1428 } | 1444 } |
1429 | 1445 |
1430 | 1446 |
1431 LInstruction* LChunkBuilder::DoMul(HMul* instr) { | 1447 LInstruction* LChunkBuilder::DoMul(HMul* instr) { |
1432 if (instr->representation().IsSmiOrInteger32()) { | 1448 if (instr->representation().IsSmiOrInteger32()) { |
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2590 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { | 2606 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { |
2591 LOperand* object = UseRegister(instr->object()); | 2607 LOperand* object = UseRegister(instr->object()); |
2592 LOperand* index = UseTempRegister(instr->index()); | 2608 LOperand* index = UseTempRegister(instr->index()); |
2593 return DefineSameAsFirst(new(zone()) LLoadFieldByIndex(object, index)); | 2609 return DefineSameAsFirst(new(zone()) LLoadFieldByIndex(object, index)); |
2594 } | 2610 } |
2595 | 2611 |
2596 | 2612 |
2597 } } // namespace v8::internal | 2613 } } // namespace v8::internal |
2598 | 2614 |
2599 #endif // V8_TARGET_ARCH_IA32 | 2615 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |