| 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 1383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1394 } | 1394 } |
| 1395 __ jmp(&done, Label::kNear); | 1395 __ jmp(&done, Label::kNear); |
| 1396 } | 1396 } |
| 1397 | 1397 |
| 1398 __ bind(÷nd_is_not_negative); | 1398 __ bind(÷nd_is_not_negative); |
| 1399 __ and_(dividend, mask); | 1399 __ and_(dividend, mask); |
| 1400 __ bind(&done); | 1400 __ bind(&done); |
| 1401 } | 1401 } |
| 1402 | 1402 |
| 1403 | 1403 |
| 1404 void LCodeGen::DoModByConstI(LModByConstI* instr) { |
| 1405 Register dividend = ToRegister(instr->dividend()); |
| 1406 int32_t divisor = instr->divisor(); |
| 1407 ASSERT(ToRegister(instr->result()).is(eax)); |
| 1408 |
| 1409 if (divisor == 0) { |
| 1410 DeoptimizeIf(no_condition, instr->environment()); |
| 1411 return; |
| 1412 } |
| 1413 |
| 1414 __ FlooringDiv(dividend, Abs(divisor)); |
| 1415 __ mov(eax, dividend); |
| 1416 __ shr(eax, 31); |
| 1417 __ add(edx, eax); |
| 1418 __ imul(edx, edx, Abs(divisor)); |
| 1419 __ mov(eax, dividend); |
| 1420 __ sub(eax, edx); |
| 1421 |
| 1422 // Check for negative zero. |
| 1423 HMod* hmod = instr->hydrogen(); |
| 1424 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero) && |
| 1425 hmod->left()->CanBeNegative()) { |
| 1426 Label remainder_not_zero; |
| 1427 __ j(not_zero, &remainder_not_zero, Label::kNear); |
| 1428 __ cmp(dividend, Immediate(0)); |
| 1429 DeoptimizeIf(less, instr->environment()); |
| 1430 __ bind(&remainder_not_zero); |
| 1431 } |
| 1432 } |
| 1433 |
| 1434 |
| 1404 void LCodeGen::DoModI(LModI* instr) { | 1435 void LCodeGen::DoModI(LModI* instr) { |
| 1405 HMod* hmod = instr->hydrogen(); | 1436 HMod* hmod = instr->hydrogen(); |
| 1406 HValue* left = hmod->left(); | 1437 HValue* left = hmod->left(); |
| 1407 HValue* right = hmod->right(); | 1438 HValue* right = hmod->right(); |
| 1408 | 1439 |
| 1409 Register left_reg = ToRegister(instr->left()); | 1440 Register left_reg = ToRegister(instr->left()); |
| 1410 ASSERT(left_reg.is(eax)); | 1441 ASSERT(left_reg.is(eax)); |
| 1411 Register right_reg = ToRegister(instr->right()); | 1442 Register right_reg = ToRegister(instr->right()); |
| 1412 ASSERT(!right_reg.is(eax)); | 1443 ASSERT(!right_reg.is(eax)); |
| 1413 ASSERT(!right_reg.is(edx)); | 1444 ASSERT(!right_reg.is(edx)); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1493 // The arithmetic shift is always OK, the 'if' is an optimization only. | 1524 // The arithmetic shift is always OK, the 'if' is an optimization only. |
| 1494 if (shift > 1) __ sar(result, 31); | 1525 if (shift > 1) __ sar(result, 31); |
| 1495 __ shr(result, 32 - shift); | 1526 __ shr(result, 32 - shift); |
| 1496 __ add(result, dividend); | 1527 __ add(result, dividend); |
| 1497 __ sar(result, shift); | 1528 __ sar(result, shift); |
| 1498 } | 1529 } |
| 1499 if (divisor < 0) __ neg(result); | 1530 if (divisor < 0) __ neg(result); |
| 1500 } | 1531 } |
| 1501 | 1532 |
| 1502 | 1533 |
| 1534 void LCodeGen::DoDivByConstI(LDivByConstI* instr) { |
| 1535 Register dividend = ToRegister(instr->dividend()); |
| 1536 int32_t divisor = instr->divisor(); |
| 1537 ASSERT(ToRegister(instr->result()).is(edx)); |
| 1538 |
| 1539 if (divisor == 0) { |
| 1540 DeoptimizeIf(no_condition, instr->environment()); |
| 1541 return; |
| 1542 } |
| 1543 |
| 1544 // Check for (0 / -x) that will produce negative zero. |
| 1545 HDiv* hdiv = instr->hydrogen(); |
| 1546 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && |
| 1547 hdiv->left()->RangeCanInclude(0) && divisor < 0) { |
| 1548 __ test(dividend, dividend); |
| 1549 DeoptimizeIf(zero, instr->environment()); |
| 1550 } |
| 1551 |
| 1552 __ FlooringDiv(dividend, Abs(divisor)); |
| 1553 __ mov(eax, dividend); |
| 1554 __ shr(eax, 31); |
| 1555 __ add(edx, eax); |
| 1556 if (divisor < 0) __ neg(edx); |
| 1557 |
| 1558 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) { |
| 1559 __ mov(eax, edx); |
| 1560 __ imul(eax, eax, divisor); |
| 1561 __ sub(eax, dividend); |
| 1562 DeoptimizeIf(not_equal, instr->environment()); |
| 1563 } |
| 1564 } |
| 1565 |
| 1566 |
| 1503 void LCodeGen::DoDivI(LDivI* instr) { | 1567 void LCodeGen::DoDivI(LDivI* instr) { |
| 1504 Register dividend = ToRegister(instr->left()); | 1568 Register dividend = ToRegister(instr->left()); |
| 1505 Register divisor = ToRegister(instr->right()); | 1569 Register divisor = ToRegister(instr->right()); |
| 1506 Register remainder = ToRegister(instr->temp()); | 1570 Register remainder = ToRegister(instr->temp()); |
| 1507 Register result = ToRegister(instr->result()); | 1571 Register result = ToRegister(instr->result()); |
| 1508 ASSERT(dividend.is(eax)); | 1572 ASSERT(dividend.is(eax)); |
| 1509 ASSERT(remainder.is(edx)); | 1573 ASSERT(remainder.is(edx)); |
| 1510 ASSERT(result.is(eax)); | 1574 ASSERT(result.is(eax)); |
| 1511 ASSERT(!divisor.is(eax)); | 1575 ASSERT(!divisor.is(eax)); |
| 1512 ASSERT(!divisor.is(edx)); | 1576 ASSERT(!divisor.is(edx)); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1592 } | 1656 } |
| 1593 __ bind(¬_kmin_int); | 1657 __ bind(¬_kmin_int); |
| 1594 __ sar(dividend, shift); | 1658 __ sar(dividend, shift); |
| 1595 __ bind(&done); | 1659 __ bind(&done); |
| 1596 } | 1660 } |
| 1597 | 1661 |
| 1598 | 1662 |
| 1599 void LCodeGen::DoFlooringDivByConstI(LFlooringDivByConstI* instr) { | 1663 void LCodeGen::DoFlooringDivByConstI(LFlooringDivByConstI* instr) { |
| 1600 Register dividend = ToRegister(instr->dividend()); | 1664 Register dividend = ToRegister(instr->dividend()); |
| 1601 int32_t divisor = instr->divisor(); | 1665 int32_t divisor = instr->divisor(); |
| 1602 Register scratch = ToRegister(instr->temp()); | |
| 1603 ASSERT(ToRegister(instr->dividend()).is(eax)); | |
| 1604 ASSERT(ToRegister(instr->result()).is(edx)); | 1666 ASSERT(ToRegister(instr->result()).is(edx)); |
| 1605 | 1667 |
| 1606 if (divisor == 0) { | 1668 if (divisor == 0) { |
| 1607 DeoptimizeIf(no_condition, instr->environment()); | 1669 DeoptimizeIf(no_condition, instr->environment()); |
| 1608 return; | 1670 return; |
| 1609 } | 1671 } |
| 1610 | 1672 |
| 1611 // Find b which: 2^b < divisor_abs < 2^(b+1). | 1673 // Check for (0 / -x) that will produce negative zero. |
| 1612 uint32_t divisor_abs = abs(divisor); | 1674 HMathFloorOfDiv* hdiv = instr->hydrogen(); |
| 1613 unsigned b = 31 - CompilerIntrinsics::CountLeadingZeros(divisor_abs); | 1675 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && |
| 1614 unsigned shift = 32 + b; // Precision +1bit (effectively). | 1676 hdiv->left()->RangeCanInclude(0) && divisor < 0) { |
| 1615 double multiplier_f = | |
| 1616 static_cast<double>(static_cast<uint64_t>(1) << shift) / divisor_abs; | |
| 1617 int64_t multiplier; | |
| 1618 if (multiplier_f - std::floor(multiplier_f) < 0.5) { | |
| 1619 multiplier = static_cast<int64_t>(std::floor(multiplier_f)); | |
| 1620 } else { | |
| 1621 multiplier = static_cast<int64_t>(std::floor(multiplier_f)) + 1; | |
| 1622 } | |
| 1623 // The multiplier is a uint32. | |
| 1624 ASSERT(multiplier > 0 && | |
| 1625 multiplier < (static_cast<int64_t>(1) << 32)); | |
| 1626 __ mov(scratch, dividend); | |
| 1627 if (divisor < 0 && | |
| 1628 instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | |
| 1629 __ test(dividend, dividend); | 1677 __ test(dividend, dividend); |
| 1630 DeoptimizeIf(zero, instr->environment()); | 1678 DeoptimizeIf(zero, instr->environment()); |
| 1631 } | 1679 } |
| 1632 __ mov(edx, static_cast<int32_t>(multiplier)); | 1680 |
| 1633 __ imul(edx); | 1681 __ FlooringDiv(dividend, divisor); |
| 1634 if (static_cast<int32_t>(multiplier) < 0) { | |
| 1635 __ add(edx, scratch); | |
| 1636 } | |
| 1637 Register reg_lo = eax; | |
| 1638 Register reg_byte_scratch = scratch; | |
| 1639 if (!reg_byte_scratch.is_byte_register()) { | |
| 1640 __ xchg(reg_lo, reg_byte_scratch); | |
| 1641 reg_lo = scratch; | |
| 1642 reg_byte_scratch = eax; | |
| 1643 } | |
| 1644 if (divisor < 0) { | |
| 1645 __ xor_(reg_byte_scratch, reg_byte_scratch); | |
| 1646 __ cmp(reg_lo, 0x40000000); | |
| 1647 __ setcc(above, reg_byte_scratch); | |
| 1648 __ neg(edx); | |
| 1649 __ sub(edx, reg_byte_scratch); | |
| 1650 } else { | |
| 1651 __ xor_(reg_byte_scratch, reg_byte_scratch); | |
| 1652 __ cmp(reg_lo, 0xC0000000); | |
| 1653 __ setcc(above_equal, reg_byte_scratch); | |
| 1654 __ add(edx, reg_byte_scratch); | |
| 1655 } | |
| 1656 __ sar(edx, shift - 32); | |
| 1657 } | 1682 } |
| 1658 | 1683 |
| 1659 | 1684 |
| 1660 void LCodeGen::DoMulI(LMulI* instr) { | 1685 void LCodeGen::DoMulI(LMulI* instr) { |
| 1661 Register left = ToRegister(instr->left()); | 1686 Register left = ToRegister(instr->left()); |
| 1662 LOperand* right = instr->right(); | 1687 LOperand* right = instr->right(); |
| 1663 | 1688 |
| 1664 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1689 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1665 __ mov(ToRegister(instr->temp()), left); | 1690 __ mov(ToRegister(instr->temp()), left); |
| 1666 } | 1691 } |
| (...skipping 4661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6328 FixedArray::kHeaderSize - kPointerSize)); | 6353 FixedArray::kHeaderSize - kPointerSize)); |
| 6329 __ bind(&done); | 6354 __ bind(&done); |
| 6330 } | 6355 } |
| 6331 | 6356 |
| 6332 | 6357 |
| 6333 #undef __ | 6358 #undef __ |
| 6334 | 6359 |
| 6335 } } // namespace v8::internal | 6360 } } // namespace v8::internal |
| 6336 | 6361 |
| 6337 #endif // V8_TARGET_ARCH_IA32 | 6362 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |