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

Side by Side Diff: src/ia32/lithium-codegen-ia32.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/ia32/lithium-codegen-ia32.h ('k') | src/ia32/lithium-ia32.cc » ('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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 348
349 int LCodeGen::ToInteger32(LConstantOperand* op) const { 349 int LCodeGen::ToInteger32(LConstantOperand* op) const {
350 Handle<Object> value = chunk_->LookupLiteral(op); 350 Handle<Object> value = chunk_->LookupLiteral(op);
351 ASSERT(chunk_->LookupLiteralRepresentation(op).IsInteger32()); 351 ASSERT(chunk_->LookupLiteralRepresentation(op).IsInteger32());
352 ASSERT(static_cast<double>(static_cast<int32_t>(value->Number())) == 352 ASSERT(static_cast<double>(static_cast<int32_t>(value->Number())) ==
353 value->Number()); 353 value->Number());
354 return static_cast<int32_t>(value->Number()); 354 return static_cast<int32_t>(value->Number());
355 } 355 }
356 356
357 357
358 double LCodeGen::ToDouble(LConstantOperand* op) const {
359 Handle<Object> value = chunk_->LookupLiteral(op);
360 return value->Number();
361 }
362
363
358 Immediate LCodeGen::ToImmediate(LOperand* op) { 364 Immediate LCodeGen::ToImmediate(LOperand* op) {
359 LConstantOperand* const_op = LConstantOperand::cast(op); 365 LConstantOperand* const_op = LConstantOperand::cast(op);
360 Handle<Object> literal = chunk_->LookupLiteral(const_op); 366 Handle<Object> literal = chunk_->LookupLiteral(const_op);
361 Representation r = chunk_->LookupLiteralRepresentation(const_op); 367 Representation r = chunk_->LookupLiteralRepresentation(const_op);
362 if (r.IsInteger32()) { 368 if (r.IsInteger32()) {
363 ASSERT(literal->IsNumber()); 369 ASSERT(literal->IsNumber());
364 return Immediate(static_cast<int32_t>(literal->Number())); 370 return Immediate(static_cast<int32_t>(literal->Number()));
365 } else if (r.IsDouble()) { 371 } else if (r.IsDouble()) {
366 Abort("unsupported double immediate"); 372 Abort("unsupported double immediate");
367 } 373 }
(...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1567 break; 1573 break;
1568 case Token::IN: 1574 case Token::IN:
1569 case Token::INSTANCEOF: 1575 case Token::INSTANCEOF:
1570 default: 1576 default:
1571 UNREACHABLE(); 1577 UNREACHABLE();
1572 } 1578 }
1573 return cond; 1579 return cond;
1574 } 1580 }
1575 1581
1576 1582
1577 void LCodeGen::EmitCmpI(LOperand* left, LOperand* right) {
1578 if (right->IsConstantOperand()) {
1579 __ cmp(ToOperand(left), ToImmediate(right));
1580 } else {
1581 __ cmp(ToRegister(left), ToOperand(right));
1582 }
1583 }
1584
1585
1586 void LCodeGen::DoCmpIDAndBranch(LCmpIDAndBranch* instr) { 1583 void LCodeGen::DoCmpIDAndBranch(LCmpIDAndBranch* instr) {
1587 LOperand* left = instr->InputAt(0); 1584 LOperand* left = instr->InputAt(0);
1588 LOperand* right = instr->InputAt(1); 1585 LOperand* right = instr->InputAt(1);
1589 int false_block = chunk_->LookupDestination(instr->false_block_id()); 1586 int false_block = chunk_->LookupDestination(instr->false_block_id());
1590 int true_block = chunk_->LookupDestination(instr->true_block_id()); 1587 int true_block = chunk_->LookupDestination(instr->true_block_id());
1588 Condition cc = TokenToCondition(instr->op(), instr->is_double());
1591 1589
1592 if (instr->is_double()) { 1590 if (left->IsConstantOperand() && right->IsConstantOperand()) {
1593 // Don't base result on EFLAGS when a NaN is involved. Instead 1591 // We can statically evaluate the comparison.
1594 // jump to the false block. 1592 double left_val = ToDouble(LConstantOperand::cast(left));
1595 __ ucomisd(ToDoubleRegister(left), ToDoubleRegister(right)); 1593 double right_val = ToDouble(LConstantOperand::cast(right));
1596 __ j(parity_even, chunk_->GetAssemblyLabel(false_block)); 1594 int next_block =
1595 EvalComparison(instr->op(), left_val, right_val) ? true_block
1596 : false_block;
1597 EmitGoto(next_block);
1597 } else { 1598 } else {
1598 EmitCmpI(left, right); 1599 if (instr->is_double()) {
1600 // Don't base result on EFLAGS when a NaN is involved. Instead
1601 // jump to the false block.
1602 __ ucomisd(ToDoubleRegister(left), ToDoubleRegister(right));
1603 __ j(parity_even, chunk_->GetAssemblyLabel(false_block));
1604 } else {
1605 if (right->IsConstantOperand()) {
1606 __ cmp(ToRegister(left), ToImmediate(right));
1607 } else if (left->IsConstantOperand()) {
1608 __ cmp(ToOperand(right), ToImmediate(left));
1609 // We transposed the operands. Reverse the condition.
1610 cc = ReverseCondition(cc);
1611 } else {
1612 __ cmp(ToRegister(left), ToOperand(right));
1613 }
1614 }
1615 EmitBranch(true_block, false_block, cc);
1599 } 1616 }
1600
1601 Condition cc = TokenToCondition(instr->op(), instr->is_double());
1602 EmitBranch(true_block, false_block, cc);
1603 } 1617 }
1604 1618
1605 1619
1606 void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) { 1620 void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) {
1607 Register left = ToRegister(instr->InputAt(0)); 1621 Register left = ToRegister(instr->InputAt(0));
1608 Operand right = ToOperand(instr->InputAt(1)); 1622 Operand right = ToOperand(instr->InputAt(1));
1609 int false_block = chunk_->LookupDestination(instr->false_block_id()); 1623 int false_block = chunk_->LookupDestination(instr->false_block_id());
1610 int true_block = chunk_->LookupDestination(instr->true_block_id()); 1624 int true_block = chunk_->LookupDestination(instr->true_block_id());
1611 1625
1612 __ cmp(left, Operand(right)); 1626 __ cmp(left, Operand(right));
(...skipping 2957 matching lines...) Expand 10 before | Expand all | Expand 10 after
4570 env->deoptimization_index()); 4584 env->deoptimization_index());
4571 __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION, safepoint_generator); 4585 __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION, safepoint_generator);
4572 } 4586 }
4573 4587
4574 4588
4575 #undef __ 4589 #undef __
4576 4590
4577 } } // namespace v8::internal 4591 } } // namespace v8::internal
4578 4592
4579 #endif // V8_TARGET_ARCH_IA32 4593 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/ia32/lithium-codegen-ia32.h ('k') | src/ia32/lithium-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698