Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: src/arm/lithium-codegen-arm.cc

Issue 8352040: Speed up comparison with a constant. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/arm/lithium-codegen-arm.h ('k') | src/assembler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 403
404 int LCodeGen::ToInteger32(LConstantOperand* op) const { 404 int LCodeGen::ToInteger32(LConstantOperand* op) const {
405 Handle<Object> value = chunk_->LookupLiteral(op); 405 Handle<Object> value = chunk_->LookupLiteral(op);
406 ASSERT(chunk_->LookupLiteralRepresentation(op).IsInteger32()); 406 ASSERT(chunk_->LookupLiteralRepresentation(op).IsInteger32());
407 ASSERT(static_cast<double>(static_cast<int32_t>(value->Number())) == 407 ASSERT(static_cast<double>(static_cast<int32_t>(value->Number())) ==
408 value->Number()); 408 value->Number());
409 return static_cast<int32_t>(value->Number()); 409 return static_cast<int32_t>(value->Number());
410 } 410 }
411 411
412 412
413 double LCodeGen::ToDouble(LConstantOperand* op) const {
414 Handle<Object> value = chunk_->LookupLiteral(op);
415 return value->Number();
416 }
417
418
413 Operand LCodeGen::ToOperand(LOperand* op) { 419 Operand LCodeGen::ToOperand(LOperand* op) {
414 if (op->IsConstantOperand()) { 420 if (op->IsConstantOperand()) {
415 LConstantOperand* const_op = LConstantOperand::cast(op); 421 LConstantOperand* const_op = LConstantOperand::cast(op);
416 Handle<Object> literal = chunk_->LookupLiteral(const_op); 422 Handle<Object> literal = chunk_->LookupLiteral(const_op);
417 Representation r = chunk_->LookupLiteralRepresentation(const_op); 423 Representation r = chunk_->LookupLiteralRepresentation(const_op);
418 if (r.IsInteger32()) { 424 if (r.IsInteger32()) {
419 ASSERT(literal->IsNumber()); 425 ASSERT(literal->IsNumber());
420 return Operand(static_cast<int32_t>(literal->Number())); 426 return Operand(static_cast<int32_t>(literal->Number()));
421 } else if (r.IsDouble()) { 427 } else if (r.IsDouble()) {
422 Abort("ToOperand Unsupported double immediate."); 428 Abort("ToOperand Unsupported double immediate.");
(...skipping 1275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 break; 1704 break;
1699 case Token::IN: 1705 case Token::IN:
1700 case Token::INSTANCEOF: 1706 case Token::INSTANCEOF:
1701 default: 1707 default:
1702 UNREACHABLE(); 1708 UNREACHABLE();
1703 } 1709 }
1704 return cond; 1710 return cond;
1705 } 1711 }
1706 1712
1707 1713
1708 void LCodeGen::EmitCmpI(LOperand* left, LOperand* right) {
1709 __ cmp(ToRegister(left), ToRegister(right));
1710 }
1711
1712
1713 void LCodeGen::DoCmpIDAndBranch(LCmpIDAndBranch* instr) { 1714 void LCodeGen::DoCmpIDAndBranch(LCmpIDAndBranch* instr) {
1714 LOperand* left = instr->InputAt(0); 1715 LOperand* left = instr->InputAt(0);
1715 LOperand* right = instr->InputAt(1); 1716 LOperand* right = instr->InputAt(1);
1716 int false_block = chunk_->LookupDestination(instr->false_block_id()); 1717 int false_block = chunk_->LookupDestination(instr->false_block_id());
1717 int true_block = chunk_->LookupDestination(instr->true_block_id()); 1718 int true_block = chunk_->LookupDestination(instr->true_block_id());
1719 Condition cond = TokenToCondition(instr->op(), false);
1718 1720
1719 if (instr->is_double()) { 1721 if (left->IsConstantOperand() && right->IsConstantOperand()) {
1720 // Compare left and right as doubles and load the 1722 // We can statically evaluate the comparison.
1721 // resulting flags into the normal status register. 1723 double left_val = ToDouble(LConstantOperand::cast(left));
1722 __ VFPCompareAndSetFlags(ToDoubleRegister(left), ToDoubleRegister(right)); 1724 double right_val = ToDouble(LConstantOperand::cast(right));
1723 // If a NaN is involved, i.e. the result is unordered (V set), 1725 int next_block =
1724 // jump to false block label. 1726 EvalComparison(instr->op(), left_val, right_val) ? true_block
1725 __ b(vs, chunk_->GetAssemblyLabel(false_block)); 1727 : false_block;
1728 EmitGoto(next_block);
1726 } else { 1729 } else {
1727 EmitCmpI(left, right); 1730 if (instr->is_double()) {
1731 // Compare left and right operands as doubles and load the
1732 // resulting flags into the normal status register.
1733 __ VFPCompareAndSetFlags(ToDoubleRegister(left), ToDoubleRegister(right));
1734 // If a NaN is involved, i.e. the result is unordered (V set),
1735 // jump to false block label.
1736 __ b(vs, chunk_->GetAssemblyLabel(false_block));
1737 } else {
1738 if (right->IsConstantOperand()) {
1739 __ cmp(ToRegister(left),
1740 Operand(ToInteger32(LConstantOperand::cast(right))));
1741 } else if (left->IsConstantOperand()) {
1742 __ cmp(ToRegister(right),
1743 Operand(ToInteger32(LConstantOperand::cast(left))));
1744 // We transposed the operands. Reverse the condition.
1745 cond = ReverseCondition(cond);
1746 } else {
1747 __ cmp(ToRegister(left), ToRegister(right));
1748 }
1749 }
1750 EmitBranch(true_block, false_block, cond);
1728 } 1751 }
1729
1730 Condition cc = TokenToCondition(instr->op(), instr->is_double());
1731 EmitBranch(true_block, false_block, cc);
1732 } 1752 }
1733 1753
1734 1754
1735 void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) { 1755 void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) {
1736 Register left = ToRegister(instr->InputAt(0)); 1756 Register left = ToRegister(instr->InputAt(0));
1737 Register right = ToRegister(instr->InputAt(1)); 1757 Register right = ToRegister(instr->InputAt(1));
1738 int false_block = chunk_->LookupDestination(instr->false_block_id()); 1758 int false_block = chunk_->LookupDestination(instr->false_block_id());
1739 int true_block = chunk_->LookupDestination(instr->true_block_id()); 1759 int true_block = chunk_->LookupDestination(instr->true_block_id());
1740 1760
1741 __ cmp(left, Operand(right)); 1761 __ cmp(left, Operand(right));
(...skipping 2904 matching lines...) Expand 10 before | Expand all | Expand 10 after
4646 ASSERT(osr_pc_offset_ == -1); 4666 ASSERT(osr_pc_offset_ == -1);
4647 osr_pc_offset_ = masm()->pc_offset(); 4667 osr_pc_offset_ = masm()->pc_offset();
4648 } 4668 }
4649 4669
4650 4670
4651 4671
4652 4672
4653 #undef __ 4673 #undef __
4654 4674
4655 } } // namespace v8::internal 4675 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/arm/lithium-codegen-arm.h ('k') | src/assembler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698