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

Side by Side Diff: src/x64/lithium-codegen-x64.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/x64/lithium-codegen-x64.h ('k') | src/x64/lithium-x64.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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 367
368 int LCodeGen::ToInteger32(LConstantOperand* op) const { 368 int LCodeGen::ToInteger32(LConstantOperand* op) const {
369 Handle<Object> value = chunk_->LookupLiteral(op); 369 Handle<Object> value = chunk_->LookupLiteral(op);
370 ASSERT(chunk_->LookupLiteralRepresentation(op).IsInteger32()); 370 ASSERT(chunk_->LookupLiteralRepresentation(op).IsInteger32());
371 ASSERT(static_cast<double>(static_cast<int32_t>(value->Number())) == 371 ASSERT(static_cast<double>(static_cast<int32_t>(value->Number())) ==
372 value->Number()); 372 value->Number());
373 return static_cast<int32_t>(value->Number()); 373 return static_cast<int32_t>(value->Number());
374 } 374 }
375 375
376 376
377 double LCodeGen::ToDouble(LConstantOperand* op) const {
378 Handle<Object> value = chunk_->LookupLiteral(op);
379 return value->Number();
380 }
381
382
377 Handle<Object> LCodeGen::ToHandle(LConstantOperand* op) const { 383 Handle<Object> LCodeGen::ToHandle(LConstantOperand* op) const {
378 Handle<Object> literal = chunk_->LookupLiteral(op); 384 Handle<Object> literal = chunk_->LookupLiteral(op);
379 ASSERT(chunk_->LookupLiteralRepresentation(op).IsTagged()); 385 ASSERT(chunk_->LookupLiteralRepresentation(op).IsTagged());
380 return literal; 386 return literal;
381 } 387 }
382 388
383 389
384 Operand LCodeGen::ToOperand(LOperand* op) const { 390 Operand LCodeGen::ToOperand(LOperand* op) const {
385 // Does not handle registers. In X64 assembler, plain registers are not 391 // Does not handle registers. In X64 assembler, plain registers are not
386 // representable as an Operand. 392 // representable as an Operand.
(...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 break; 1525 break;
1520 case Token::IN: 1526 case Token::IN:
1521 case Token::INSTANCEOF: 1527 case Token::INSTANCEOF:
1522 default: 1528 default:
1523 UNREACHABLE(); 1529 UNREACHABLE();
1524 } 1530 }
1525 return cond; 1531 return cond;
1526 } 1532 }
1527 1533
1528 1534
1529 void LCodeGen::EmitCmpI(LOperand* left, LOperand* right) {
1530 if (right->IsConstantOperand()) {
1531 int32_t value = ToInteger32(LConstantOperand::cast(right));
1532 if (left->IsRegister()) {
1533 __ cmpl(ToRegister(left), Immediate(value));
1534 } else {
1535 __ cmpl(ToOperand(left), Immediate(value));
1536 }
1537 } else if (right->IsRegister()) {
1538 __ cmpl(ToRegister(left), ToRegister(right));
1539 } else {
1540 __ cmpl(ToRegister(left), ToOperand(right));
1541 }
1542 }
1543
1544
1545 void LCodeGen::DoCmpIDAndBranch(LCmpIDAndBranch* instr) { 1535 void LCodeGen::DoCmpIDAndBranch(LCmpIDAndBranch* instr) {
1546 LOperand* left = instr->InputAt(0); 1536 LOperand* left = instr->InputAt(0);
1547 LOperand* right = instr->InputAt(1); 1537 LOperand* right = instr->InputAt(1);
1548 int false_block = chunk_->LookupDestination(instr->false_block_id()); 1538 int false_block = chunk_->LookupDestination(instr->false_block_id());
1549 int true_block = chunk_->LookupDestination(instr->true_block_id()); 1539 int true_block = chunk_->LookupDestination(instr->true_block_id());
1540 Condition cc = TokenToCondition(instr->op(), instr->is_double());
1550 1541
1551 if (instr->is_double()) { 1542 if (left->IsConstantOperand() && right->IsConstantOperand()) {
1552 // Don't base result on EFLAGS when a NaN is involved. Instead 1543 // We can statically evaluate the comparison.
1553 // jump to the false block. 1544 double left_val = ToDouble(LConstantOperand::cast(left));
1554 __ ucomisd(ToDoubleRegister(left), ToDoubleRegister(right)); 1545 double right_val = ToDouble(LConstantOperand::cast(right));
1555 __ j(parity_even, chunk_->GetAssemblyLabel(false_block)); 1546 int next_block =
1547 EvalComparison(instr->op(), left_val, right_val) ? true_block
1548 : false_block;
1549 EmitGoto(next_block);
1556 } else { 1550 } else {
1557 EmitCmpI(left, right); 1551 if (instr->is_double()) {
1552 // Don't base result on EFLAGS when a NaN is involved. Instead
1553 // jump to the false block.
1554 __ ucomisd(ToDoubleRegister(left), ToDoubleRegister(right));
1555 __ j(parity_even, chunk_->GetAssemblyLabel(false_block));
1556 } else {
1557 int32_t value;
1558 if (right->IsConstantOperand()) {
1559 value = ToInteger32(LConstantOperand::cast(right));
1560 __ cmpl(ToRegister(left), Immediate(value));
1561 } else if (left->IsConstantOperand()) {
1562 value = ToInteger32(LConstantOperand::cast(left));
1563 if (right->IsRegister()) {
1564 __ cmpl(ToRegister(right), Immediate(value));
1565 } else {
1566 __ cmpl(ToOperand(right), Immediate(value));
1567 }
1568 // We transposed the operands. Reverse the condition.
1569 cc = ReverseCondition(cc);
1570 } else {
1571 if (right->IsRegister()) {
1572 __ cmpl(ToRegister(left), ToRegister(right));
1573 } else {
1574 __ cmpl(ToRegister(left), ToOperand(right));
1575 }
1576 }
1577 }
1578 EmitBranch(true_block, false_block, cc);
1558 } 1579 }
1559
1560 Condition cc = TokenToCondition(instr->op(), instr->is_double());
1561 EmitBranch(true_block, false_block, cc);
1562 } 1580 }
1563 1581
1564 1582
1565 void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) { 1583 void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) {
1566 Register left = ToRegister(instr->InputAt(0)); 1584 Register left = ToRegister(instr->InputAt(0));
1567 Register right = ToRegister(instr->InputAt(1)); 1585 Register right = ToRegister(instr->InputAt(1));
1568 int false_block = chunk_->LookupDestination(instr->false_block_id()); 1586 int false_block = chunk_->LookupDestination(instr->false_block_id());
1569 int true_block = chunk_->LookupDestination(instr->true_block_id()); 1587 int true_block = chunk_->LookupDestination(instr->true_block_id());
1570 1588
1571 __ cmpq(left, right); 1589 __ cmpq(left, right);
(...skipping 2704 matching lines...) Expand 10 before | Expand all | Expand 10 after
4276 RegisterEnvironmentForDeoptimization(environment); 4294 RegisterEnvironmentForDeoptimization(environment);
4277 ASSERT(osr_pc_offset_ == -1); 4295 ASSERT(osr_pc_offset_ == -1);
4278 osr_pc_offset_ = masm()->pc_offset(); 4296 osr_pc_offset_ = masm()->pc_offset();
4279 } 4297 }
4280 4298
4281 #undef __ 4299 #undef __
4282 4300
4283 } } // namespace v8::internal 4301 } } // namespace v8::internal
4284 4302
4285 #endif // V8_TARGET_ARCH_X64 4303 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/x64/lithium-codegen-x64.h ('k') | src/x64/lithium-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698