| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 1540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1551 Register reg = ToRegister(instr->InputAt(0)); | 1551 Register reg = ToRegister(instr->InputAt(0)); |
| 1552 __ cmp(reg, Operand(0)); | 1552 __ cmp(reg, Operand(0)); |
| 1553 EmitBranch(true_block, false_block, ne); | 1553 EmitBranch(true_block, false_block, ne); |
| 1554 } else if (r.IsDouble()) { | 1554 } else if (r.IsDouble()) { |
| 1555 DoubleRegister reg = ToDoubleRegister(instr->InputAt(0)); | 1555 DoubleRegister reg = ToDoubleRegister(instr->InputAt(0)); |
| 1556 Register scratch = scratch0(); | 1556 Register scratch = scratch0(); |
| 1557 | 1557 |
| 1558 // Test the double value. Zero and NaN are false. | 1558 // Test the double value. Zero and NaN are false. |
| 1559 __ VFPCompareAndLoadFlags(reg, 0.0, scratch); | 1559 __ VFPCompareAndLoadFlags(reg, 0.0, scratch); |
| 1560 __ tst(scratch, Operand(kVFPZConditionFlagBit | kVFPVConditionFlagBit)); | 1560 __ tst(scratch, Operand(kVFPZConditionFlagBit | kVFPVConditionFlagBit)); |
| 1561 EmitBranch(true_block, false_block, ne); | 1561 EmitBranch(true_block, false_block, eq); |
| 1562 } else { | 1562 } else { |
| 1563 ASSERT(r.IsTagged()); | 1563 ASSERT(r.IsTagged()); |
| 1564 Register reg = ToRegister(instr->InputAt(0)); | 1564 Register reg = ToRegister(instr->InputAt(0)); |
| 1565 if (instr->hydrogen()->value()->type().IsBoolean()) { | 1565 HType type = instr->hydrogen()->value()->type(); |
| 1566 __ LoadRoot(ip, Heap::kTrueValueRootIndex); | 1566 if (type.IsBoolean()) { |
| 1567 __ cmp(reg, ip); | 1567 __ CompareRoot(reg, Heap::kTrueValueRootIndex); |
| 1568 EmitBranch(true_block, false_block, eq); | 1568 EmitBranch(true_block, false_block, eq); |
| 1569 } else if (type.IsSmi()) { |
| 1570 __ cmp(reg, Operand(0)); |
| 1571 EmitBranch(true_block, false_block, ne); |
| 1569 } else { | 1572 } else { |
| 1570 Label* true_label = chunk_->GetAssemblyLabel(true_block); | 1573 Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 1571 Label* false_label = chunk_->GetAssemblyLabel(false_block); | 1574 Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 1572 | 1575 |
| 1573 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); | 1576 ToBooleanStub::Types expected = instr->hydrogen()->expected_input_types(); |
| 1574 __ cmp(reg, ip); | 1577 // Avoid deopts in the case where we've never executed this path before. |
| 1575 __ b(eq, false_label); | 1578 if (expected.IsEmpty()) expected = ToBooleanStub::all_types(); |
| 1576 __ LoadRoot(ip, Heap::kTrueValueRootIndex); | |
| 1577 __ cmp(reg, ip); | |
| 1578 __ b(eq, true_label); | |
| 1579 __ LoadRoot(ip, Heap::kFalseValueRootIndex); | |
| 1580 __ cmp(reg, ip); | |
| 1581 __ b(eq, false_label); | |
| 1582 __ cmp(reg, Operand(0)); | |
| 1583 __ b(eq, false_label); | |
| 1584 __ JumpIfSmi(reg, true_label); | |
| 1585 | 1579 |
| 1586 // Test double values. Zero and NaN are false. | 1580 if (expected.Contains(ToBooleanStub::UNDEFINED)) { |
| 1587 Label call_stub; | 1581 // undefined -> false. |
| 1588 DoubleRegister dbl_scratch = double_scratch0(); | 1582 __ CompareRoot(reg, Heap::kUndefinedValueRootIndex); |
| 1589 Register scratch = scratch0(); | 1583 __ b(eq, false_label); |
| 1590 __ ldr(scratch, FieldMemOperand(reg, HeapObject::kMapOffset)); | 1584 } else if (expected.Contains(ToBooleanStub::INTERNAL_OBJECT)) { |
| 1591 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); | 1585 // We've seen undefined for the first time -> deopt. |
| 1592 __ cmp(scratch, Operand(ip)); | 1586 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 1593 __ b(ne, &call_stub); | 1587 DeoptimizeIf(eq, instr->environment()); |
| 1594 __ sub(ip, reg, Operand(kHeapObjectTag)); | 1588 } |
| 1595 __ vldr(dbl_scratch, ip, HeapNumber::kValueOffset); | |
| 1596 __ VFPCompareAndLoadFlags(dbl_scratch, 0.0, scratch); | |
| 1597 __ tst(scratch, Operand(kVFPZConditionFlagBit | kVFPVConditionFlagBit)); | |
| 1598 __ b(ne, false_label); | |
| 1599 __ b(true_label); | |
| 1600 | 1589 |
| 1601 // The conversion stub doesn't cause garbage collections so it's | 1590 if (expected.Contains(ToBooleanStub::BOOLEAN)) { |
| 1602 // safe to not record a safepoint after the call. | 1591 // Boolean -> its value. |
| 1603 __ bind(&call_stub); | 1592 __ CompareRoot(reg, Heap::kTrueValueRootIndex); |
| 1604 ToBooleanStub stub(reg); | 1593 __ b(eq, true_label); |
| 1605 RegList saved_regs = kJSCallerSaved | kCalleeSaved; | 1594 __ CompareRoot(reg, Heap::kFalseValueRootIndex); |
| 1606 __ stm(db_w, sp, saved_regs); | 1595 __ b(eq, false_label); |
| 1607 __ CallStub(&stub); | 1596 } else if (expected.Contains(ToBooleanStub::INTERNAL_OBJECT)) { |
| 1608 __ cmp(reg, Operand(0)); | 1597 // We've seen a boolean for the first time -> deopt. |
| 1609 __ ldm(ia_w, sp, saved_regs); | 1598 __ CompareRoot(reg, Heap::kTrueValueRootIndex); |
| 1610 EmitBranch(true_block, false_block, ne); | 1599 DeoptimizeIf(eq, instr->environment()); |
| 1600 __ CompareRoot(reg, Heap::kFalseValueRootIndex); |
| 1601 DeoptimizeIf(eq, instr->environment()); |
| 1602 } |
| 1603 |
| 1604 #if 0 |
| 1605 if (expected.Contains(ToBooleanStub::BOOLEAN)) { |
| 1606 // false -> false. |
| 1607 __ CompareRoot(reg, Heap::kFalseValueRootIndex); |
| 1608 __ b(eq, false_label); |
| 1609 } else if (expected.Contains(ToBooleanStub::INTERNAL_OBJECT)) { |
| 1610 // We've seen a boolean for the first time -> deopt. |
| 1611 __ CompareRoot(reg, Heap::kFalseValueRootIndex); |
| 1612 DeoptimizeIf(eq, instr->environment()); |
| 1613 } |
| 1614 #endif |
| 1615 |
| 1616 if (expected.Contains(ToBooleanStub::NULL_TYPE)) { |
| 1617 // 'null' -> false. |
| 1618 __ CompareRoot(reg, Heap::kNullValueRootIndex); |
| 1619 __ b(eq, false_label); |
| 1620 } else if (expected.Contains(ToBooleanStub::INTERNAL_OBJECT)) { |
| 1621 // We've seen null for the first time -> deopt. |
| 1622 __ CompareRoot(reg, Heap::kNullValueRootIndex); |
| 1623 DeoptimizeIf(eq, instr->environment()); |
| 1624 } |
| 1625 |
| 1626 if (expected.Contains(ToBooleanStub::SMI)) { |
| 1627 // Smis: 0 -> false, all other -> true. |
| 1628 __ cmp(reg, Operand(0)); |
| 1629 __ b(eq, false_label); |
| 1630 __ JumpIfSmi(reg, true_label); |
| 1631 } else if (expected.NeedsMap()) { |
| 1632 // If we need a map later and have a Smi -> deopt. |
| 1633 __ tst(reg, Operand(kSmiTagMask)); |
| 1634 DeoptimizeIf(eq, instr->environment()); |
| 1635 } |
| 1636 |
| 1637 const Register map = scratch0(); |
| 1638 if (expected.NeedsMap()) { |
| 1639 __ ldr(map, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 1640 // Everything with a map could be undetectable, so check this now. |
| 1641 __ ldrb(ip, FieldMemOperand(map, Map::kBitFieldOffset)); |
| 1642 __ tst(ip, Operand(1 << Map::kIsUndetectable)); |
| 1643 __ b(ne, false_label); |
| 1644 } |
| 1645 |
| 1646 if (expected.Contains(ToBooleanStub::SPEC_OBJECT)) { |
| 1647 // spec object -> true. |
| 1648 __ CompareInstanceType(map, ip, FIRST_SPEC_OBJECT_TYPE); |
| 1649 __ b(ge, true_label); |
| 1650 } else if (expected.Contains(ToBooleanStub::INTERNAL_OBJECT)) { |
| 1651 // We've seen a spec object for the first time -> deopt. |
| 1652 __ CompareInstanceType(map, ip, FIRST_SPEC_OBJECT_TYPE); |
| 1653 DeoptimizeIf(ge, instr->environment()); |
| 1654 } |
| 1655 |
| 1656 if (expected.Contains(ToBooleanStub::STRING)) { |
| 1657 // String value -> false iff empty. |
| 1658 Label not_string; |
| 1659 __ CompareInstanceType(map, ip, FIRST_NONSTRING_TYPE); |
| 1660 __ b(ge, ¬_string); |
| 1661 __ ldr(ip, FieldMemOperand(reg, String::kLengthOffset)); |
| 1662 __ cmp(ip, Operand(0)); |
| 1663 __ b(ne, true_label); |
| 1664 __ b(false_label); |
| 1665 __ bind(¬_string); |
| 1666 } else if (expected.Contains(ToBooleanStub::INTERNAL_OBJECT)) { |
| 1667 // We've seen a string for the first time -> deopt |
| 1668 __ CompareInstanceType(map, ip, FIRST_NONSTRING_TYPE); |
| 1669 DeoptimizeIf(lt, instr->environment()); |
| 1670 } |
| 1671 |
| 1672 if (expected.Contains(ToBooleanStub::HEAP_NUMBER)) { |
| 1673 // heap number -> false iff +0, -0, or NaN. |
| 1674 DoubleRegister dbl_scratch = double_scratch0(); |
| 1675 Label not_heap_number; |
| 1676 __ CompareRoot(map, Heap::kHeapNumberMapRootIndex); |
| 1677 __ b(ne, ¬_heap_number); |
| 1678 __ vldr(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset)); |
| 1679 __ VFPCompareAndSetFlags(dbl_scratch, 0.0); |
| 1680 __ b(vs, false_label); // NaN -> false. |
| 1681 __ b(eq, false_label); // +0, -0 -> false. |
| 1682 __ b(true_label); |
| 1683 __ bind(¬_heap_number); |
| 1684 } else if (expected.Contains(ToBooleanStub::INTERNAL_OBJECT)) { |
| 1685 // We've seen a heap number for the first time -> deopt. |
| 1686 __ CompareRoot(map, Heap::kHeapNumberMapRootIndex); |
| 1687 DeoptimizeIf(eq, instr->environment()); |
| 1688 } |
| 1689 |
| 1690 if (expected.Contains(ToBooleanStub::INTERNAL_OBJECT)) { |
| 1691 // internal objects -> true |
| 1692 __ b(true_label); |
| 1693 } else { |
| 1694 // We've seen something for the first time -> deopt. |
| 1695 DeoptimizeIf(al, instr->environment()); |
| 1696 } |
| 1611 } | 1697 } |
| 1612 } | 1698 } |
| 1613 } | 1699 } |
| 1614 | 1700 |
| 1615 | 1701 |
| 1616 void LCodeGen::EmitGoto(int block) { | 1702 void LCodeGen::EmitGoto(int block) { |
| 1617 block = chunk_->LookupDestination(block); | 1703 block = chunk_->LookupDestination(block); |
| 1618 int next_block = GetNextEmittedBlock(current_block_); | 1704 int next_block = GetNextEmittedBlock(current_block_); |
| 1619 if (block != next_block) { | 1705 if (block != next_block) { |
| 1620 __ jmp(chunk_->GetAssemblyLabel(block)); | 1706 __ jmp(chunk_->GetAssemblyLabel(block)); |
| (...skipping 2869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4490 ASSERT(osr_pc_offset_ == -1); | 4576 ASSERT(osr_pc_offset_ == -1); |
| 4491 osr_pc_offset_ = masm()->pc_offset(); | 4577 osr_pc_offset_ = masm()->pc_offset(); |
| 4492 } | 4578 } |
| 4493 | 4579 |
| 4494 | 4580 |
| 4495 | 4581 |
| 4496 | 4582 |
| 4497 #undef __ | 4583 #undef __ |
| 4498 | 4584 |
| 4499 } } // namespace v8::internal | 4585 } } // namespace v8::internal |
| OLD | NEW |