| 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 1403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1414 __ FlooringDiv(dividend, Abs(divisor)); | 1414 __ FlooringDiv(dividend, Abs(divisor)); |
| 1415 __ mov(eax, dividend); | 1415 __ mov(eax, dividend); |
| 1416 __ shr(eax, 31); | 1416 __ shr(eax, 31); |
| 1417 __ add(edx, eax); | 1417 __ add(edx, eax); |
| 1418 __ imul(edx, edx, Abs(divisor)); | 1418 __ imul(edx, edx, Abs(divisor)); |
| 1419 __ mov(eax, dividend); | 1419 __ mov(eax, dividend); |
| 1420 __ sub(eax, edx); | 1420 __ sub(eax, edx); |
| 1421 | 1421 |
| 1422 // Check for negative zero. | 1422 // Check for negative zero. |
| 1423 HMod* hmod = instr->hydrogen(); | 1423 HMod* hmod = instr->hydrogen(); |
| 1424 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero) && | 1424 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1425 hmod->left()->CanBeNegative()) { | |
| 1426 Label remainder_not_zero; | 1425 Label remainder_not_zero; |
| 1427 __ j(not_zero, &remainder_not_zero, Label::kNear); | 1426 __ j(not_zero, &remainder_not_zero, Label::kNear); |
| 1428 __ cmp(dividend, Immediate(0)); | 1427 __ cmp(dividend, Immediate(0)); |
| 1429 DeoptimizeIf(less, instr->environment()); | 1428 DeoptimizeIf(less, instr->environment()); |
| 1430 __ bind(&remainder_not_zero); | 1429 __ bind(&remainder_not_zero); |
| 1431 } | 1430 } |
| 1432 } | 1431 } |
| 1433 | 1432 |
| 1434 | 1433 |
| 1435 void LCodeGen::DoModI(LModI* instr) { | 1434 void LCodeGen::DoModI(LModI* instr) { |
| 1436 HMod* hmod = instr->hydrogen(); | 1435 HMod* hmod = instr->hydrogen(); |
| 1437 HValue* left = hmod->left(); | |
| 1438 HValue* right = hmod->right(); | |
| 1439 | 1436 |
| 1440 Register left_reg = ToRegister(instr->left()); | 1437 Register left_reg = ToRegister(instr->left()); |
| 1441 ASSERT(left_reg.is(eax)); | 1438 ASSERT(left_reg.is(eax)); |
| 1442 Register right_reg = ToRegister(instr->right()); | 1439 Register right_reg = ToRegister(instr->right()); |
| 1443 ASSERT(!right_reg.is(eax)); | 1440 ASSERT(!right_reg.is(eax)); |
| 1444 ASSERT(!right_reg.is(edx)); | 1441 ASSERT(!right_reg.is(edx)); |
| 1445 Register result_reg = ToRegister(instr->result()); | 1442 Register result_reg = ToRegister(instr->result()); |
| 1446 ASSERT(result_reg.is(edx)); | 1443 ASSERT(result_reg.is(edx)); |
| 1447 | 1444 |
| 1448 Label done; | 1445 Label done; |
| 1449 // Check for x % 0, idiv would signal a divide error. We have to | 1446 // Check for x % 0, idiv would signal a divide error. We have to |
| 1450 // deopt in this case because we can't return a NaN. | 1447 // deopt in this case because we can't return a NaN. |
| 1451 if (right->CanBeZero()) { | 1448 if (hmod->CheckFlag(HValue::kCanBeDivByZero)) { |
| 1452 __ test(right_reg, Operand(right_reg)); | 1449 __ test(right_reg, Operand(right_reg)); |
| 1453 DeoptimizeIf(zero, instr->environment()); | 1450 DeoptimizeIf(zero, instr->environment()); |
| 1454 } | 1451 } |
| 1455 | 1452 |
| 1456 // Check for kMinInt % -1, idiv would signal a divide error. We | 1453 // Check for kMinInt % -1, idiv would signal a divide error. We |
| 1457 // have to deopt if we care about -0, because we can't return that. | 1454 // have to deopt if we care about -0, because we can't return that. |
| 1458 if (left->RangeCanInclude(kMinInt) && right->RangeCanInclude(-1)) { | 1455 if (hmod->CheckFlag(HValue::kCanOverflow)) { |
| 1459 Label no_overflow_possible; | 1456 Label no_overflow_possible; |
| 1460 __ cmp(left_reg, kMinInt); | 1457 __ cmp(left_reg, kMinInt); |
| 1461 __ j(not_equal, &no_overflow_possible, Label::kNear); | 1458 __ j(not_equal, &no_overflow_possible, Label::kNear); |
| 1462 __ cmp(right_reg, -1); | 1459 __ cmp(right_reg, -1); |
| 1463 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1460 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1464 DeoptimizeIf(equal, instr->environment()); | 1461 DeoptimizeIf(equal, instr->environment()); |
| 1465 } else { | 1462 } else { |
| 1466 __ j(not_equal, &no_overflow_possible, Label::kNear); | 1463 __ j(not_equal, &no_overflow_possible, Label::kNear); |
| 1467 __ Set(result_reg, Immediate(0)); | 1464 __ Set(result_reg, Immediate(0)); |
| 1468 __ jmp(&done, Label::kNear); | 1465 __ jmp(&done, Label::kNear); |
| 1469 } | 1466 } |
| 1470 __ bind(&no_overflow_possible); | 1467 __ bind(&no_overflow_possible); |
| 1471 } | 1468 } |
| 1472 | 1469 |
| 1473 // Sign extend dividend in eax into edx:eax. | 1470 // Sign extend dividend in eax into edx:eax. |
| 1474 __ cdq(); | 1471 __ cdq(); |
| 1475 | 1472 |
| 1476 // If we care about -0, test if the dividend is <0 and the result is 0. | 1473 // If we care about -0, test if the dividend is <0 and the result is 0. |
| 1477 if (left->CanBeNegative() && | 1474 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1478 hmod->CanBeZero() && | |
| 1479 hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { | |
| 1480 Label positive_left; | 1475 Label positive_left; |
| 1481 __ test(left_reg, Operand(left_reg)); | 1476 __ test(left_reg, Operand(left_reg)); |
| 1482 __ j(not_sign, &positive_left, Label::kNear); | 1477 __ j(not_sign, &positive_left, Label::kNear); |
| 1483 __ idiv(right_reg); | 1478 __ idiv(right_reg); |
| 1484 __ test(result_reg, Operand(result_reg)); | 1479 __ test(result_reg, Operand(result_reg)); |
| 1485 DeoptimizeIf(zero, instr->environment()); | 1480 DeoptimizeIf(zero, instr->environment()); |
| 1486 __ jmp(&done, Label::kNear); | 1481 __ jmp(&done, Label::kNear); |
| 1487 __ bind(&positive_left); | 1482 __ bind(&positive_left); |
| 1488 } | 1483 } |
| 1489 __ idiv(right_reg); | 1484 __ idiv(right_reg); |
| 1490 __ bind(&done); | 1485 __ bind(&done); |
| 1491 } | 1486 } |
| 1492 | 1487 |
| 1493 | 1488 |
| 1494 void LCodeGen::DoDivByPowerOf2I(LDivByPowerOf2I* instr) { | 1489 void LCodeGen::DoDivByPowerOf2I(LDivByPowerOf2I* instr) { |
| 1495 Register dividend = ToRegister(instr->dividend()); | 1490 Register dividend = ToRegister(instr->dividend()); |
| 1496 int32_t divisor = instr->divisor(); | 1491 int32_t divisor = instr->divisor(); |
| 1497 Register result = ToRegister(instr->result()); | 1492 Register result = ToRegister(instr->result()); |
| 1498 ASSERT(divisor == kMinInt || (divisor != 0 && IsPowerOf2(Abs(divisor)))); | 1493 ASSERT(divisor == kMinInt || (divisor != 0 && IsPowerOf2(Abs(divisor)))); |
| 1499 ASSERT(!result.is(dividend)); | 1494 ASSERT(!result.is(dividend)); |
| 1500 | 1495 |
| 1501 // Check for (0 / -x) that will produce negative zero. | 1496 // Check for (0 / -x) that will produce negative zero. |
| 1502 HDiv* hdiv = instr->hydrogen(); | 1497 HDiv* hdiv = instr->hydrogen(); |
| 1503 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && | 1498 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { |
| 1504 hdiv->left()->RangeCanInclude(0) && divisor < 0) { | |
| 1505 __ test(dividend, dividend); | 1499 __ test(dividend, dividend); |
| 1506 DeoptimizeIf(zero, instr->environment()); | 1500 DeoptimizeIf(zero, instr->environment()); |
| 1507 } | 1501 } |
| 1508 // Check for (kMinInt / -1). | 1502 // Check for (kMinInt / -1). |
| 1509 if (hdiv->CheckFlag(HValue::kCanOverflow) && | 1503 if (hdiv->CheckFlag(HValue::kCanOverflow) && divisor == -1) { |
| 1510 hdiv->left()->RangeCanInclude(kMinInt) && divisor == -1) { | |
| 1511 __ cmp(dividend, kMinInt); | 1504 __ cmp(dividend, kMinInt); |
| 1512 DeoptimizeIf(zero, instr->environment()); | 1505 DeoptimizeIf(zero, instr->environment()); |
| 1513 } | 1506 } |
| 1514 // Deoptimize if remainder will not be 0. | 1507 // Deoptimize if remainder will not be 0. |
| 1515 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) && | 1508 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) && |
| 1516 divisor != 1 && divisor != -1) { | 1509 divisor != 1 && divisor != -1) { |
| 1517 int32_t mask = divisor < 0 ? -(divisor + 1) : (divisor - 1); | 1510 int32_t mask = divisor < 0 ? -(divisor + 1) : (divisor - 1); |
| 1518 __ test(dividend, Immediate(mask)); | 1511 __ test(dividend, Immediate(mask)); |
| 1519 DeoptimizeIf(not_zero, instr->environment()); | 1512 DeoptimizeIf(not_zero, instr->environment()); |
| 1520 } | 1513 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1536 int32_t divisor = instr->divisor(); | 1529 int32_t divisor = instr->divisor(); |
| 1537 ASSERT(ToRegister(instr->result()).is(edx)); | 1530 ASSERT(ToRegister(instr->result()).is(edx)); |
| 1538 | 1531 |
| 1539 if (divisor == 0) { | 1532 if (divisor == 0) { |
| 1540 DeoptimizeIf(no_condition, instr->environment()); | 1533 DeoptimizeIf(no_condition, instr->environment()); |
| 1541 return; | 1534 return; |
| 1542 } | 1535 } |
| 1543 | 1536 |
| 1544 // Check for (0 / -x) that will produce negative zero. | 1537 // Check for (0 / -x) that will produce negative zero. |
| 1545 HDiv* hdiv = instr->hydrogen(); | 1538 HDiv* hdiv = instr->hydrogen(); |
| 1546 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && | 1539 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { |
| 1547 hdiv->left()->RangeCanInclude(0) && divisor < 0) { | |
| 1548 __ test(dividend, dividend); | 1540 __ test(dividend, dividend); |
| 1549 DeoptimizeIf(zero, instr->environment()); | 1541 DeoptimizeIf(zero, instr->environment()); |
| 1550 } | 1542 } |
| 1551 | 1543 |
| 1552 __ FlooringDiv(dividend, Abs(divisor)); | 1544 __ FlooringDiv(dividend, Abs(divisor)); |
| 1553 __ mov(eax, dividend); | 1545 __ mov(eax, dividend); |
| 1554 __ shr(eax, 31); | 1546 __ shr(eax, 31); |
| 1555 __ add(edx, eax); | 1547 __ add(edx, eax); |
| 1556 if (divisor < 0) __ neg(edx); | 1548 if (divisor < 0) __ neg(edx); |
| 1557 | 1549 |
| 1558 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) { | 1550 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) { |
| 1559 __ mov(eax, edx); | 1551 __ mov(eax, edx); |
| 1560 __ imul(eax, eax, divisor); | 1552 __ imul(eax, eax, divisor); |
| 1561 __ sub(eax, dividend); | 1553 __ sub(eax, dividend); |
| 1562 DeoptimizeIf(not_equal, instr->environment()); | 1554 DeoptimizeIf(not_equal, instr->environment()); |
| 1563 } | 1555 } |
| 1564 } | 1556 } |
| 1565 | 1557 |
| 1566 | 1558 |
| 1567 void LCodeGen::DoDivI(LDivI* instr) { | 1559 void LCodeGen::DoDivI(LDivI* instr) { |
| 1560 HBinaryOperation* hdiv = instr->hydrogen(); |
| 1568 Register dividend = ToRegister(instr->left()); | 1561 Register dividend = ToRegister(instr->left()); |
| 1569 Register divisor = ToRegister(instr->right()); | 1562 Register divisor = ToRegister(instr->right()); |
| 1570 Register remainder = ToRegister(instr->temp()); | 1563 Register remainder = ToRegister(instr->temp()); |
| 1571 Register result = ToRegister(instr->result()); | 1564 Register result = ToRegister(instr->result()); |
| 1572 ASSERT(dividend.is(eax)); | 1565 ASSERT(dividend.is(eax)); |
| 1573 ASSERT(remainder.is(edx)); | 1566 ASSERT(remainder.is(edx)); |
| 1574 ASSERT(result.is(eax)); | 1567 ASSERT(result.is(eax)); |
| 1575 ASSERT(!divisor.is(eax)); | 1568 ASSERT(!divisor.is(eax)); |
| 1576 ASSERT(!divisor.is(edx)); | 1569 ASSERT(!divisor.is(edx)); |
| 1577 | 1570 |
| 1578 // Check for x / 0. | 1571 // Check for x / 0. |
| 1579 HBinaryOperation* hdiv = instr->hydrogen(); | |
| 1580 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { | 1572 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { |
| 1581 __ test(divisor, divisor); | 1573 __ test(divisor, divisor); |
| 1582 DeoptimizeIf(zero, instr->environment()); | 1574 DeoptimizeIf(zero, instr->environment()); |
| 1583 } | 1575 } |
| 1584 | 1576 |
| 1585 // Check for (0 / -x) that will produce negative zero. | 1577 // Check for (0 / -x) that will produce negative zero. |
| 1586 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1578 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1587 Label dividend_not_zero; | 1579 Label dividend_not_zero; |
| 1588 __ test(dividend, dividend); | 1580 __ test(dividend, dividend); |
| 1589 __ j(not_zero, ÷nd_not_zero, Label::kNear); | 1581 __ j(not_zero, ÷nd_not_zero, Label::kNear); |
| 1590 __ test(divisor, divisor); | 1582 __ test(divisor, divisor); |
| 1591 DeoptimizeIf(sign, instr->environment()); | 1583 DeoptimizeIf(sign, instr->environment()); |
| 1592 __ bind(÷nd_not_zero); | 1584 __ bind(÷nd_not_zero); |
| 1593 } | 1585 } |
| 1594 | 1586 |
| 1595 // Check for (kMinInt / -1). | 1587 // Check for (kMinInt / -1). |
| 1596 if (hdiv->CheckFlag(HValue::kCanOverflow)) { | 1588 if (hdiv->CheckFlag(HValue::kCanOverflow)) { |
| 1597 Label dividend_not_min_int; | 1589 Label dividend_not_min_int; |
| 1598 __ cmp(dividend, kMinInt); | 1590 __ cmp(dividend, kMinInt); |
| 1599 __ j(not_zero, ÷nd_not_min_int, Label::kNear); | 1591 __ j(not_zero, ÷nd_not_min_int, Label::kNear); |
| 1600 __ cmp(divisor, -1); | 1592 __ cmp(divisor, -1); |
| 1601 DeoptimizeIf(zero, instr->environment()); | 1593 DeoptimizeIf(zero, instr->environment()); |
| 1602 __ bind(÷nd_not_min_int); | 1594 __ bind(÷nd_not_min_int); |
| 1603 } | 1595 } |
| 1604 | 1596 |
| 1605 // Sign extend to edx (= remainder). | 1597 // Sign extend to edx (= remainder). |
| 1606 __ cdq(); | 1598 __ cdq(); |
| 1607 __ idiv(divisor); | 1599 __ idiv(divisor); |
| 1608 | 1600 |
| 1609 if (instr->is_flooring()) { | 1601 if (hdiv->IsMathFloorOfDiv()) { |
| 1610 Label done; | 1602 Label done; |
| 1611 __ test(remainder, remainder); | 1603 __ test(remainder, remainder); |
| 1612 __ j(zero, &done, Label::kNear); | 1604 __ j(zero, &done, Label::kNear); |
| 1613 __ xor_(remainder, divisor); | 1605 __ xor_(remainder, divisor); |
| 1614 __ sar(remainder, 31); | 1606 __ sar(remainder, 31); |
| 1615 __ add(result, remainder); | 1607 __ add(result, remainder); |
| 1616 __ bind(&done); | 1608 __ bind(&done); |
| 1617 } else if (!instr->hydrogen()->CheckFlag( | 1609 } else if (!hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) { |
| 1618 HInstruction::kAllUsesTruncatingToInt32)) { | |
| 1619 // Deoptimize if remainder is not 0. | 1610 // Deoptimize if remainder is not 0. |
| 1620 __ test(remainder, remainder); | 1611 __ test(remainder, remainder); |
| 1621 DeoptimizeIf(not_zero, instr->environment()); | 1612 DeoptimizeIf(not_zero, instr->environment()); |
| 1622 } | 1613 } |
| 1623 } | 1614 } |
| 1624 | 1615 |
| 1625 | 1616 |
| 1626 void LCodeGen::DoFlooringDivByPowerOf2I(LFlooringDivByPowerOf2I* instr) { | 1617 void LCodeGen::DoFlooringDivByPowerOf2I(LFlooringDivByPowerOf2I* instr) { |
| 1627 Register dividend = ToRegister(instr->dividend()); | 1618 Register dividend = ToRegister(instr->dividend()); |
| 1628 int32_t divisor = instr->divisor(); | 1619 int32_t divisor = instr->divisor(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1665 int32_t divisor = instr->divisor(); | 1656 int32_t divisor = instr->divisor(); |
| 1666 ASSERT(ToRegister(instr->result()).is(edx)); | 1657 ASSERT(ToRegister(instr->result()).is(edx)); |
| 1667 | 1658 |
| 1668 if (divisor == 0) { | 1659 if (divisor == 0) { |
| 1669 DeoptimizeIf(no_condition, instr->environment()); | 1660 DeoptimizeIf(no_condition, instr->environment()); |
| 1670 return; | 1661 return; |
| 1671 } | 1662 } |
| 1672 | 1663 |
| 1673 // Check for (0 / -x) that will produce negative zero. | 1664 // Check for (0 / -x) that will produce negative zero. |
| 1674 HMathFloorOfDiv* hdiv = instr->hydrogen(); | 1665 HMathFloorOfDiv* hdiv = instr->hydrogen(); |
| 1675 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && | 1666 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { |
| 1676 hdiv->left()->RangeCanInclude(0) && divisor < 0) { | |
| 1677 __ test(dividend, dividend); | 1667 __ test(dividend, dividend); |
| 1678 DeoptimizeIf(zero, instr->environment()); | 1668 DeoptimizeIf(zero, instr->environment()); |
| 1679 } | 1669 } |
| 1680 | 1670 |
| 1681 __ FlooringDiv(dividend, divisor); | 1671 __ FlooringDiv(dividend, divisor); |
| 1682 } | 1672 } |
| 1683 | 1673 |
| 1684 | 1674 |
| 1685 void LCodeGen::DoMulI(LMulI* instr) { | 1675 void LCodeGen::DoMulI(LMulI* instr) { |
| 1686 Register left = ToRegister(instr->left()); | 1676 Register left = ToRegister(instr->left()); |
| (...skipping 4666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6353 FixedArray::kHeaderSize - kPointerSize)); | 6343 FixedArray::kHeaderSize - kPointerSize)); |
| 6354 __ bind(&done); | 6344 __ bind(&done); |
| 6355 } | 6345 } |
| 6356 | 6346 |
| 6357 | 6347 |
| 6358 #undef __ | 6348 #undef __ |
| 6359 | 6349 |
| 6360 } } // namespace v8::internal | 6350 } } // namespace v8::internal |
| 6361 | 6351 |
| 6362 #endif // V8_TARGET_ARCH_IA32 | 6352 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |