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 __ imul(edx, edx, Abs(divisor)); | |
1416 __ mov(eax, dividend); | |
1417 __ sub(eax, edx); | |
1418 | |
1419 // Check for negative zero. | |
1420 HMod* hmod = instr->hydrogen(); | |
1421 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero) && | |
1422 hmod->left()->CanBeNegative()) { | |
1423 Label remainder_not_zero; | |
1424 __ j(not_zero, &remainder_not_zero, Label::kNear); | |
1425 __ cmp(dividend, Immediate(0)); | |
1426 DeoptimizeIf(less, instr->environment()); | |
1427 __ bind(&remainder_not_zero); | |
1428 } | |
1429 } | |
1430 | |
1431 | |
1432 void LCodeGen::DoModI(LModI* instr) { | 1404 void LCodeGen::DoModI(LModI* instr) { |
1433 HMod* hmod = instr->hydrogen(); | 1405 HMod* hmod = instr->hydrogen(); |
1434 HValue* left = hmod->left(); | 1406 HValue* left = hmod->left(); |
1435 HValue* right = hmod->right(); | 1407 HValue* right = hmod->right(); |
1436 | 1408 |
1437 Register left_reg = ToRegister(instr->left()); | 1409 Register left_reg = ToRegister(instr->left()); |
1438 ASSERT(left_reg.is(eax)); | 1410 ASSERT(left_reg.is(eax)); |
1439 Register right_reg = ToRegister(instr->right()); | 1411 Register right_reg = ToRegister(instr->right()); |
1440 ASSERT(!right_reg.is(eax)); | 1412 ASSERT(!right_reg.is(eax)); |
1441 ASSERT(!right_reg.is(edx)); | 1413 ASSERT(!right_reg.is(edx)); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1521 // The arithmetic shift is always OK, the 'if' is an optimization only. | 1493 // The arithmetic shift is always OK, the 'if' is an optimization only. |
1522 if (shift > 1) __ sar(result, 31); | 1494 if (shift > 1) __ sar(result, 31); |
1523 __ shr(result, 32 - shift); | 1495 __ shr(result, 32 - shift); |
1524 __ add(result, dividend); | 1496 __ add(result, dividend); |
1525 __ sar(result, shift); | 1497 __ sar(result, shift); |
1526 } | 1498 } |
1527 if (divisor < 0) __ neg(result); | 1499 if (divisor < 0) __ neg(result); |
1528 } | 1500 } |
1529 | 1501 |
1530 | 1502 |
1531 void LCodeGen::DoDivByConstI(LDivByConstI* instr) { | |
1532 Register dividend = ToRegister(instr->dividend()); | |
1533 int32_t divisor = instr->divisor(); | |
1534 ASSERT(ToRegister(instr->result()).is(edx)); | |
1535 | |
1536 if (divisor == 0) { | |
1537 DeoptimizeIf(no_condition, instr->environment()); | |
1538 return; | |
1539 } | |
1540 | |
1541 // Check for (0 / -x) that will produce negative zero. | |
1542 HDiv* hdiv = instr->hydrogen(); | |
1543 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && | |
1544 hdiv->left()->RangeCanInclude(0) && divisor < 0) { | |
1545 __ test(dividend, dividend); | |
1546 DeoptimizeIf(zero, instr->environment()); | |
1547 } | |
1548 | |
1549 __ FlooringDiv(dividend, Abs(divisor)); | |
1550 if (divisor < 0) __ neg(edx); | |
1551 | |
1552 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) { | |
1553 __ mov(eax, edx); | |
1554 __ imul(eax, eax, divisor); | |
1555 __ sub(eax, dividend); | |
1556 DeoptimizeIf(not_equal, instr->environment()); | |
1557 } | |
1558 } | |
1559 | |
1560 | |
1561 void LCodeGen::DoDivI(LDivI* instr) { | 1503 void LCodeGen::DoDivI(LDivI* instr) { |
1562 Register dividend = ToRegister(instr->left()); | 1504 Register dividend = ToRegister(instr->left()); |
1563 Register divisor = ToRegister(instr->right()); | 1505 Register divisor = ToRegister(instr->right()); |
1564 Register remainder = ToRegister(instr->temp()); | 1506 Register remainder = ToRegister(instr->temp()); |
1565 Register result = ToRegister(instr->result()); | 1507 Register result = ToRegister(instr->result()); |
1566 ASSERT(dividend.is(eax)); | 1508 ASSERT(dividend.is(eax)); |
1567 ASSERT(remainder.is(edx)); | 1509 ASSERT(remainder.is(edx)); |
1568 ASSERT(result.is(eax)); | 1510 ASSERT(result.is(eax)); |
1569 ASSERT(!divisor.is(eax)); | 1511 ASSERT(!divisor.is(eax)); |
1570 ASSERT(!divisor.is(edx)); | 1512 ASSERT(!divisor.is(edx)); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1650 } | 1592 } |
1651 __ bind(¬_kmin_int); | 1593 __ bind(¬_kmin_int); |
1652 __ sar(dividend, shift); | 1594 __ sar(dividend, shift); |
1653 __ bind(&done); | 1595 __ bind(&done); |
1654 } | 1596 } |
1655 | 1597 |
1656 | 1598 |
1657 void LCodeGen::DoFlooringDivByConstI(LFlooringDivByConstI* instr) { | 1599 void LCodeGen::DoFlooringDivByConstI(LFlooringDivByConstI* instr) { |
1658 Register dividend = ToRegister(instr->dividend()); | 1600 Register dividend = ToRegister(instr->dividend()); |
1659 int32_t divisor = instr->divisor(); | 1601 int32_t divisor = instr->divisor(); |
| 1602 Register scratch = ToRegister(instr->temp()); |
| 1603 ASSERT(ToRegister(instr->dividend()).is(eax)); |
1660 ASSERT(ToRegister(instr->result()).is(edx)); | 1604 ASSERT(ToRegister(instr->result()).is(edx)); |
1661 | 1605 |
1662 if (divisor == 0) { | 1606 if (divisor == 0) { |
1663 DeoptimizeIf(no_condition, instr->environment()); | 1607 DeoptimizeIf(no_condition, instr->environment()); |
1664 return; | 1608 return; |
1665 } | 1609 } |
1666 | 1610 |
1667 // Check for (0 / -x) that will produce negative zero. | 1611 // Find b which: 2^b < divisor_abs < 2^(b+1). |
1668 HMathFloorOfDiv* hdiv = instr->hydrogen(); | 1612 uint32_t divisor_abs = abs(divisor); |
1669 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && | 1613 unsigned b = 31 - CompilerIntrinsics::CountLeadingZeros(divisor_abs); |
1670 hdiv->left()->RangeCanInclude(0) && divisor < 0) { | 1614 unsigned shift = 32 + b; // Precision +1bit (effectively). |
| 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)) { |
1671 __ test(dividend, dividend); | 1629 __ test(dividend, dividend); |
1672 DeoptimizeIf(zero, instr->environment()); | 1630 DeoptimizeIf(zero, instr->environment()); |
1673 } | 1631 } |
1674 | 1632 __ mov(edx, static_cast<int32_t>(multiplier)); |
1675 __ FlooringDiv(dividend, divisor); | 1633 __ imul(edx); |
| 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); |
1676 } | 1657 } |
1677 | 1658 |
1678 | 1659 |
1679 void LCodeGen::DoMulI(LMulI* instr) { | 1660 void LCodeGen::DoMulI(LMulI* instr) { |
1680 Register left = ToRegister(instr->left()); | 1661 Register left = ToRegister(instr->left()); |
1681 LOperand* right = instr->right(); | 1662 LOperand* right = instr->right(); |
1682 | 1663 |
1683 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1664 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
1684 __ mov(ToRegister(instr->temp()), left); | 1665 __ mov(ToRegister(instr->temp()), left); |
1685 } | 1666 } |
(...skipping 4622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6308 FixedArray::kHeaderSize - kPointerSize)); | 6289 FixedArray::kHeaderSize - kPointerSize)); |
6309 __ bind(&done); | 6290 __ bind(&done); |
6310 } | 6291 } |
6311 | 6292 |
6312 | 6293 |
6313 #undef __ | 6294 #undef __ |
6314 | 6295 |
6315 } } // namespace v8::internal | 6296 } } // namespace v8::internal |
6316 | 6297 |
6317 #endif // V8_TARGET_ARCH_IA32 | 6298 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |