Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/ia32/lithium-ia32.cc

Issue 191293012: Reland "Handle non-power-of-2 divisors in division-like operations". (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/ia32/lithium-ia32.h ('k') | src/ia32/macro-assembler-ia32.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
1343 LInstruction* LChunkBuilder::DoDivI(HBinaryOperation* instr) { 1363 LInstruction* LChunkBuilder::DoDivI(HBinaryOperation* instr) {
1344 ASSERT(instr->representation().IsSmiOrInteger32()); 1364 ASSERT(instr->representation().IsSmiOrInteger32());
1345 ASSERT(instr->left()->representation().Equals(instr->representation())); 1365 ASSERT(instr->left()->representation().Equals(instr->representation()));
1346 ASSERT(instr->right()->representation().Equals(instr->representation())); 1366 ASSERT(instr->right()->representation().Equals(instr->representation()));
1347 LOperand* dividend = UseFixed(instr->left(), eax); 1367 LOperand* dividend = UseFixed(instr->left(), eax);
1348 LOperand* divisor = UseRegister(instr->right()); 1368 LOperand* divisor = UseRegister(instr->right());
1349 LOperand* temp = FixedTemp(edx); 1369 LOperand* temp = FixedTemp(edx);
1350 LDivI* result = new(zone()) LDivI(dividend, divisor, temp); 1370 LInstruction* result =
1351 return AssignEnvironment(DefineFixed(result, eax)); 1371 DefineFixed(new(zone()) LDivI(dividend, divisor, temp), eax);
1372 return AssignEnvironment(result);
1352 } 1373 }
1353 1374
1354 1375
1355 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { 1376 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
1356 if (instr->representation().IsSmiOrInteger32()) { 1377 if (instr->representation().IsSmiOrInteger32()) {
1357 return instr->RightIsPowerOf2() ? DoDivByPowerOf2I(instr) : DoDivI(instr); 1378 if (instr->RightIsPowerOf2()) {
1379 return DoDivByPowerOf2I(instr);
1380 } else if (instr->right()->IsConstant()) {
1381 return DoDivByConstI(instr);
1382 } else {
1383 return DoDivI(instr);
1384 }
1358 } else if (instr->representation().IsDouble()) { 1385 } else if (instr->representation().IsDouble()) {
1359 return DoArithmeticD(Token::DIV, instr); 1386 return DoArithmeticD(Token::DIV, instr);
1360 } else { 1387 } else {
1361 return DoArithmeticT(Token::DIV, instr); 1388 return DoArithmeticT(Token::DIV, instr);
1362 } 1389 }
1363 } 1390 }
1364 1391
1365 1392
1366 LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) { 1393 LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) {
1367 LOperand* dividend = UseRegisterAtStart(instr->left()); 1394 LOperand* dividend = UseRegisterAtStart(instr->left());
1368 int32_t divisor = instr->right()->GetInteger32Constant(); 1395 int32_t divisor = instr->right()->GetInteger32Constant();
1369 LInstruction* result = 1396 LInstruction* result =
1370 DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(dividend, divisor)); 1397 DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(dividend, divisor));
1371 bool can_deopt = 1398 bool can_deopt =
1372 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) || 1399 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1373 (instr->left()->RangeCanInclude(kMinInt) && divisor == -1); 1400 (instr->left()->RangeCanInclude(kMinInt) && divisor == -1);
1374 return can_deopt ? AssignEnvironment(result) : result; 1401 return can_deopt ? AssignEnvironment(result) : result;
1375 } 1402 }
1376 1403
1377 1404
1378 LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) { 1405 LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) {
1379 LOperand* dividend = UseFixed(instr->left(), eax); 1406 ASSERT(instr->representation().IsInteger32());
1407 ASSERT(instr->left()->representation().Equals(instr->representation()));
1408 ASSERT(instr->right()->representation().Equals(instr->representation()));
1409 LOperand* dividend = UseRegister(instr->left());
1380 int32_t divisor = instr->right()->GetInteger32Constant(); 1410 int32_t divisor = instr->right()->GetInteger32Constant();
1381 LOperand* temp = TempRegister(); 1411 LOperand* temp1 = FixedTemp(eax);
1412 LOperand* temp2 = FixedTemp(edx);
1382 LInstruction* result = 1413 LInstruction* result =
1383 DefineFixed( 1414 DefineFixed(new(zone()) LFlooringDivByConstI(dividend,
1384 new(zone()) LFlooringDivByConstI(dividend, divisor, temp), edx); 1415 divisor,
1385 bool can_deopt = divisor <= 0; 1416 temp1,
1417 temp2),
1418 edx);
1419 bool can_deopt =
1420 divisor == 0 ||
1421 (instr->CheckFlag(HValue::kBailoutOnMinusZero) &&
1422 instr->left()->RangeCanInclude(0) && divisor < 0);
1386 return can_deopt ? AssignEnvironment(result) : result; 1423 return can_deopt ? AssignEnvironment(result) : result;
1387 } 1424 }
1388 1425
1389 1426
1390 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) { 1427 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) {
1391 if (instr->RightIsPowerOf2()) { 1428 if (instr->RightIsPowerOf2()) {
1392 return DoFlooringDivByPowerOf2I(instr); 1429 return DoFlooringDivByPowerOf2I(instr);
1393 } else if (instr->right()->IsConstant()) { 1430 } else if (instr->right()->IsConstant()) {
1394 return DoFlooringDivByConstI(instr); 1431 return DoFlooringDivByConstI(instr);
1395 } else { 1432 } else {
(...skipping 10 matching lines...) Expand all
1406 int32_t divisor = instr->right()->GetInteger32Constant(); 1443 int32_t divisor = instr->right()->GetInteger32Constant();
1407 LInstruction* result = 1444 LInstruction* result =
1408 DefineSameAsFirst(new(zone()) LModByPowerOf2I(dividend, divisor)); 1445 DefineSameAsFirst(new(zone()) LModByPowerOf2I(dividend, divisor));
1409 bool can_deopt = 1446 bool can_deopt =
1410 instr->CheckFlag(HValue::kBailoutOnMinusZero) && 1447 instr->CheckFlag(HValue::kBailoutOnMinusZero) &&
1411 instr->left()->CanBeNegative(); 1448 instr->left()->CanBeNegative();
1412 return can_deopt ? AssignEnvironment(result) : result; 1449 return can_deopt ? AssignEnvironment(result) : result;
1413 } 1450 }
1414 1451
1415 1452
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
1416 LInstruction* LChunkBuilder::DoModI(HMod* instr) { 1472 LInstruction* LChunkBuilder::DoModI(HMod* instr) {
1417 ASSERT(instr->representation().IsSmiOrInteger32()); 1473 ASSERT(instr->representation().IsSmiOrInteger32());
1418 ASSERT(instr->left()->representation().Equals(instr->representation())); 1474 ASSERT(instr->left()->representation().Equals(instr->representation()));
1419 ASSERT(instr->right()->representation().Equals(instr->representation())); 1475 ASSERT(instr->right()->representation().Equals(instr->representation()));
1420 LOperand* dividend = UseFixed(instr->left(), eax); 1476 LOperand* dividend = UseFixed(instr->left(), eax);
1421 LOperand* divisor = UseRegister(instr->right()); 1477 LOperand* divisor = UseRegister(instr->right());
1422 LOperand* temp = FixedTemp(edx); 1478 LOperand* temp = FixedTemp(edx);
1423 LInstruction* result = 1479 LInstruction* result =
1424 DefineFixed(new(zone()) LModI(dividend, divisor, temp), edx); 1480 DefineFixed(new(zone()) LModI(dividend, divisor, temp), edx);
1425 bool can_deopt = (instr->right()->CanBeZero() || 1481 bool can_deopt = (instr->right()->CanBeZero() ||
1426 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && 1482 (instr->CheckFlag(HValue::kBailoutOnMinusZero) &&
1427 instr->left()->RangeCanInclude(kMinInt) && 1483 instr->left()->RangeCanInclude(kMinInt) &&
1428 instr->right()->RangeCanInclude(-1)) || 1484 instr->right()->RangeCanInclude(-1)) ||
1429 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && 1485 (instr->CheckFlag(HValue::kBailoutOnMinusZero) &&
1430 instr->left()->CanBeNegative() && 1486 instr->left()->CanBeNegative() &&
1431 instr->CanBeZero())); 1487 instr->CanBeZero()));
1432 return can_deopt ? AssignEnvironment(result) : result; 1488 return can_deopt ? AssignEnvironment(result) : result;
1433 } 1489 }
1434 1490
1435 1491
1436 LInstruction* LChunkBuilder::DoMod(HMod* instr) { 1492 LInstruction* LChunkBuilder::DoMod(HMod* instr) {
1437 if (instr->representation().IsSmiOrInteger32()) { 1493 if (instr->representation().IsSmiOrInteger32()) {
1438 return instr->RightIsPowerOf2() ? DoModByPowerOf2I(instr) : DoModI(instr); 1494 if (instr->RightIsPowerOf2()) {
1495 return DoModByPowerOf2I(instr);
1496 } else if (instr->right()->IsConstant()) {
1497 return DoModByConstI(instr);
1498 } else {
1499 return DoModI(instr);
1500 }
1439 } else if (instr->representation().IsDouble()) { 1501 } else if (instr->representation().IsDouble()) {
1440 return DoArithmeticD(Token::MOD, instr); 1502 return DoArithmeticD(Token::MOD, instr);
1441 } else { 1503 } else {
1442 return DoArithmeticT(Token::MOD, instr); 1504 return DoArithmeticT(Token::MOD, instr);
1443 } 1505 }
1444 } 1506 }
1445 1507
1446 1508
1447 LInstruction* LChunkBuilder::DoMul(HMul* instr) { 1509 LInstruction* LChunkBuilder::DoMul(HMul* instr) {
1448 if (instr->representation().IsSmiOrInteger32()) { 1510 if (instr->representation().IsSmiOrInteger32()) {
(...skipping 1171 matching lines...) Expand 10 before | Expand all | Expand 10 after
2620 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { 2682 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) {
2621 LOperand* object = UseRegister(instr->object()); 2683 LOperand* object = UseRegister(instr->object());
2622 LOperand* index = UseTempRegister(instr->index()); 2684 LOperand* index = UseTempRegister(instr->index());
2623 return DefineSameAsFirst(new(zone()) LLoadFieldByIndex(object, index)); 2685 return DefineSameAsFirst(new(zone()) LLoadFieldByIndex(object, index));
2624 } 2686 }
2625 2687
2626 2688
2627 } } // namespace v8::internal 2689 } } // namespace v8::internal
2628 2690
2629 #endif // V8_TARGET_ARCH_IA32 2691 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/ia32/lithium-ia32.h ('k') | src/ia32/macro-assembler-ia32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698