| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 5279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5290 // For a variable that rewrites to a slot, we signal it is the immediate | 5290 // For a variable that rewrites to a slot, we signal it is the immediate |
| 5291 // subexpression of a typeof. | 5291 // subexpression of a typeof. |
| 5292 LoadFromSlotCheckForArguments(variable->slot(), INSIDE_TYPEOF); | 5292 LoadFromSlotCheckForArguments(variable->slot(), INSIDE_TYPEOF); |
| 5293 } else { | 5293 } else { |
| 5294 // Anything else can be handled normally. | 5294 // Anything else can be handled normally. |
| 5295 Load(expr); | 5295 Load(expr); |
| 5296 } | 5296 } |
| 5297 } | 5297 } |
| 5298 | 5298 |
| 5299 | 5299 |
| 5300 static bool CouldBeNaN(const Result& result) { |
| 5301 if (result.type_info().IsSmi()) return false; |
| 5302 if (result.type_info().IsInteger32()) return false; |
| 5303 if (!result.is_constant()) return true; |
| 5304 if (!result.handle()->IsHeapNumber()) return false; |
| 5305 return isnan(HeapNumber::cast(*result.handle())->value()); |
| 5306 } |
| 5307 |
| 5308 |
| 5300 void CodeGenerator::Comparison(AstNode* node, | 5309 void CodeGenerator::Comparison(AstNode* node, |
| 5301 Condition cc, | 5310 Condition cc, |
| 5302 bool strict, | 5311 bool strict, |
| 5303 ControlDestination* dest) { | 5312 ControlDestination* dest) { |
| 5304 // Strict only makes sense for equality comparisons. | 5313 // Strict only makes sense for equality comparisons. |
| 5305 ASSERT(!strict || cc == equal); | 5314 ASSERT(!strict || cc == equal); |
| 5306 | 5315 |
| 5307 Result left_side; | 5316 Result left_side; |
| 5308 Result right_side; | 5317 Result right_side; |
| 5309 // Implement '>' and '<=' by reversal to obtain ECMA-262 conversion order. | 5318 // Implement '>' and '<=' by reversal to obtain ECMA-262 conversion order. |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5607 // the short one. | 5616 // the short one. |
| 5608 __ cmpl(FieldOperand(left_side.reg(), String::kLengthOffset), | 5617 __ cmpl(FieldOperand(left_side.reg(), String::kLengthOffset), |
| 5609 Immediate(1)); | 5618 Immediate(1)); |
| 5610 __ bind(&characters_were_different); | 5619 __ bind(&characters_were_different); |
| 5611 } | 5620 } |
| 5612 temp2.Unuse(); | 5621 temp2.Unuse(); |
| 5613 left_side.Unuse(); | 5622 left_side.Unuse(); |
| 5614 right_side.Unuse(); | 5623 right_side.Unuse(); |
| 5615 dest->Split(cc); | 5624 dest->Split(cc); |
| 5616 } | 5625 } |
| 5617 } else { // Neither side is a constant Smi or null. | 5626 } else { |
| 5627 // Neither side is a constant Smi, constant 1-char string, or constant null. |
| 5618 // If either side is a non-smi constant, skip the smi check. | 5628 // If either side is a non-smi constant, skip the smi check. |
| 5619 bool known_non_smi = | 5629 bool known_non_smi = |
| 5620 (left_side.is_constant() && !left_side.handle()->IsSmi()) || | 5630 (left_side.is_constant() && !left_side.handle()->IsSmi()) || |
| 5621 (right_side.is_constant() && !right_side.handle()->IsSmi()); | 5631 (right_side.is_constant() && !right_side.handle()->IsSmi()); |
| 5632 |
| 5633 NaNInformation nan_info = |
| 5634 (CouldBeNaN(left_side) && CouldBeNaN(right_side)) ? |
| 5635 kBothCouldBeNaN : |
| 5636 kCantBothBeNaN; |
| 5637 |
| 5622 left_side.ToRegister(); | 5638 left_side.ToRegister(); |
| 5623 right_side.ToRegister(); | 5639 right_side.ToRegister(); |
| 5624 | 5640 |
| 5625 if (known_non_smi) { | 5641 if (known_non_smi) { |
| 5642 // If at least one of the objects is not NaN, then if the objects |
| 5643 // are identical, they are equal. |
| 5644 if (nan_info == kCantBothBeNaN && cc == equal) { |
| 5645 __ cmpq(left_side.reg(), right_side.reg()); |
| 5646 dest->true_target()->Branch(equal); |
| 5647 } |
| 5648 |
| 5626 // When non-smi, call out to the compare stub. | 5649 // When non-smi, call out to the compare stub. |
| 5627 CompareStub stub(cc, strict); | 5650 CompareStub stub(cc, strict); |
| 5628 Result answer = frame_->CallStub(&stub, &left_side, &right_side); | 5651 Result answer = frame_->CallStub(&stub, &left_side, &right_side); |
| 5629 // The result is a Smi, which is negative, zero, or positive. | 5652 // The result is a Smi, which is negative, zero, or positive. |
| 5630 __ SmiTest(answer.reg()); // Sets both zero and sign flag. | 5653 __ SmiTest(answer.reg()); // Sets both zero and sign flag. |
| 5631 answer.Unuse(); | 5654 answer.Unuse(); |
| 5632 dest->Split(cc); | 5655 dest->Split(cc); |
| 5633 } else { | 5656 } else { |
| 5634 // Here we split control flow to the stub call and inlined cases | 5657 // Here we split control flow to the stub call and inlined cases |
| 5635 // before finally splitting it to the control destination. We use | 5658 // before finally splitting it to the control destination. We use |
| 5636 // a jump target and branching to duplicate the virtual frame at | 5659 // a jump target and branching to duplicate the virtual frame at |
| 5637 // the first split. We manually handle the off-frame references | 5660 // the first split. We manually handle the off-frame references |
| 5638 // by reconstituting them on the non-fall-through path. | 5661 // by reconstituting them on the non-fall-through path. |
| 5639 JumpTarget is_smi; | 5662 JumpTarget is_smi; |
| 5640 Register left_reg = left_side.reg(); | 5663 Register left_reg = left_side.reg(); |
| 5641 Register right_reg = right_side.reg(); | 5664 Register right_reg = right_side.reg(); |
| 5642 | 5665 |
| 5643 Condition both_smi = masm_->CheckBothSmi(left_reg, right_reg); | 5666 Condition both_smi = masm_->CheckBothSmi(left_reg, right_reg); |
| 5644 is_smi.Branch(both_smi); | 5667 is_smi.Branch(both_smi); |
| 5645 // When non-smi, call out to the compare stub. | 5668 // When non-smi, call out to the compare stub, after inlined checks. |
| 5669 // If at least one of the objects is not NaN, then if the objects |
| 5670 // are identical, they are equal. |
| 5671 if (nan_info == kCantBothBeNaN && cc == equal) { |
| 5672 __ cmpq(left_side.reg(), right_side.reg()); |
| 5673 dest->true_target()->Branch(equal); |
| 5674 } |
| 5675 |
| 5646 CompareStub stub(cc, strict); | 5676 CompareStub stub(cc, strict); |
| 5647 Result answer = frame_->CallStub(&stub, &left_side, &right_side); | 5677 Result answer = frame_->CallStub(&stub, &left_side, &right_side); |
| 5648 __ SmiTest(answer.reg()); // Sets both zero and sign flags. | 5678 __ SmiTest(answer.reg()); // Sets both zero and sign flags. |
| 5649 answer.Unuse(); | 5679 answer.Unuse(); |
| 5650 dest->true_target()->Branch(cc); | 5680 dest->true_target()->Branch(cc); |
| 5651 dest->false_target()->Jump(); | 5681 dest->false_target()->Jump(); |
| 5652 | 5682 |
| 5653 is_smi.Bind(); | 5683 is_smi.Bind(); |
| 5654 left_side = Result(left_reg); | 5684 left_side = Result(left_reg); |
| 5655 right_side = Result(right_reg); | 5685 right_side = Result(right_reg); |
| (...skipping 4782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10438 // Call the function from C++. | 10468 // Call the function from C++. |
| 10439 return FUNCTION_CAST<ModuloFunction>(buffer); | 10469 return FUNCTION_CAST<ModuloFunction>(buffer); |
| 10440 } | 10470 } |
| 10441 | 10471 |
| 10442 #endif | 10472 #endif |
| 10443 | 10473 |
| 10444 | 10474 |
| 10445 #undef __ | 10475 #undef __ |
| 10446 | 10476 |
| 10447 } } // namespace v8::internal | 10477 } } // namespace v8::internal |
| OLD | NEW |