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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 | 360 |
361 int LCodeGen::ToInteger32(LConstantOperand* op) const { | 361 int LCodeGen::ToInteger32(LConstantOperand* op) const { |
362 Handle<Object> value = chunk_->LookupLiteral(op); | 362 Handle<Object> value = chunk_->LookupLiteral(op); |
363 ASSERT(chunk_->LookupLiteralRepresentation(op).IsInteger32()); | 363 ASSERT(chunk_->LookupLiteralRepresentation(op).IsInteger32()); |
364 ASSERT(static_cast<double>(static_cast<int32_t>(value->Number())) == | 364 ASSERT(static_cast<double>(static_cast<int32_t>(value->Number())) == |
365 value->Number()); | 365 value->Number()); |
366 return static_cast<int32_t>(value->Number()); | 366 return static_cast<int32_t>(value->Number()); |
367 } | 367 } |
368 | 368 |
369 | 369 |
370 double LCodeGen::ToDouble(LConstantOperand* op) const { | |
371 Handle<Object> value = chunk_->LookupLiteral(op); | |
372 return value->Number(); | |
373 } | |
374 | |
375 | |
370 Handle<Object> LCodeGen::ToHandle(LConstantOperand* op) const { | 376 Handle<Object> LCodeGen::ToHandle(LConstantOperand* op) const { |
371 Handle<Object> literal = chunk_->LookupLiteral(op); | 377 Handle<Object> literal = chunk_->LookupLiteral(op); |
372 ASSERT(chunk_->LookupLiteralRepresentation(op).IsTagged()); | 378 ASSERT(chunk_->LookupLiteralRepresentation(op).IsTagged()); |
373 return literal; | 379 return literal; |
374 } | 380 } |
375 | 381 |
376 | 382 |
377 Operand LCodeGen::ToOperand(LOperand* op) const { | 383 Operand LCodeGen::ToOperand(LOperand* op) const { |
378 // Does not handle registers. In X64 assembler, plain registers are not | 384 // Does not handle registers. In X64 assembler, plain registers are not |
379 // representable as an Operand. | 385 // representable as an Operand. |
(...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1512 break; | 1518 break; |
1513 case Token::IN: | 1519 case Token::IN: |
1514 case Token::INSTANCEOF: | 1520 case Token::INSTANCEOF: |
1515 default: | 1521 default: |
1516 UNREACHABLE(); | 1522 UNREACHABLE(); |
1517 } | 1523 } |
1518 return cond; | 1524 return cond; |
1519 } | 1525 } |
1520 | 1526 |
1521 | 1527 |
1522 void LCodeGen::EmitCmpI(LOperand* left, LOperand* right) { | |
1523 if (right->IsConstantOperand()) { | |
1524 int32_t value = ToInteger32(LConstantOperand::cast(right)); | |
1525 if (left->IsRegister()) { | |
1526 __ cmpl(ToRegister(left), Immediate(value)); | |
1527 } else { | |
1528 __ cmpl(ToOperand(left), Immediate(value)); | |
1529 } | |
1530 } else if (right->IsRegister()) { | |
1531 __ cmpl(ToRegister(left), ToRegister(right)); | |
1532 } else { | |
1533 __ cmpl(ToRegister(left), ToOperand(right)); | |
1534 } | |
1535 } | |
1536 | |
1537 | |
1538 void LCodeGen::DoCmpIDAndBranch(LCmpIDAndBranch* instr) { | 1528 void LCodeGen::DoCmpIDAndBranch(LCmpIDAndBranch* instr) { |
1539 LOperand* left = instr->InputAt(0); | 1529 LOperand* left = instr->InputAt(0); |
1540 LOperand* right = instr->InputAt(1); | 1530 LOperand* right = instr->InputAt(1); |
1541 int false_block = chunk_->LookupDestination(instr->false_block_id()); | 1531 int false_block = chunk_->LookupDestination(instr->false_block_id()); |
1542 int true_block = chunk_->LookupDestination(instr->true_block_id()); | 1532 int true_block = chunk_->LookupDestination(instr->true_block_id()); |
1533 Condition cc = TokenToCondition(instr->op(), instr->is_double()); | |
1543 | 1534 |
1544 if (instr->is_double()) { | 1535 if (left->IsConstantOperand() && right->IsConstantOperand()) { |
1545 // Don't base result on EFLAGS when a NaN is involved. Instead | 1536 // We can statically evaluate the comparison. |
1546 // jump to the false block. | 1537 double left_val = ToDouble(LConstantOperand::cast(left)); |
1547 __ ucomisd(ToDoubleRegister(left), ToDoubleRegister(right)); | 1538 double right_val = ToDouble(LConstantOperand::cast(right)); |
1548 __ j(parity_even, chunk_->GetAssemblyLabel(false_block)); | 1539 int next_block = |
1540 EvalComparison(instr->op(), left_val, right_val) ? true_block | |
1541 : false_block; | |
1542 EmitGoto(next_block); | |
1549 } else { | 1543 } else { |
1550 EmitCmpI(left, right); | 1544 if (instr->is_double()) { |
1545 // Don't base result on EFLAGS when a NaN is involved. Instead | |
1546 // jump to the false block. | |
1547 __ ucomisd(ToDoubleRegister(left), ToDoubleRegister(right)); | |
1548 __ j(parity_even, chunk_->GetAssemblyLabel(false_block)); | |
1549 } else { | |
1550 int32_t value; | |
1551 if (right->IsConstantOperand()) { | |
1552 value = ToInteger32(LConstantOperand::cast(right)); | |
1553 if (left->IsRegister()) { | |
1554 __ cmpl(ToRegister(left), Immediate(value)); | |
1555 } else { | |
1556 __ cmpl(ToOperand(left), Immediate(value)); | |
William Hesse
2011/09/09 11:14:46
This case is not needed, because left is created w
Alexandre
2011/09/09 17:07:22
I cleaned up this case. I hope ToRegister will wor
| |
1557 } | |
1558 } else if (left->IsConstantOperand()) { | |
1559 value = ToInteger32(LConstantOperand::cast(left)); | |
1560 if (right->IsRegister()) { | |
1561 __ cmpl(ToRegister(right), Immediate(value)); | |
1562 } else { | |
1563 __ cmpl(ToOperand(right), Immediate(value)); | |
1564 } | |
1565 // We transposed the operands. Reverse the condition. | |
1566 cc = ReverseCondition(cc); | |
1567 } else { | |
1568 __ cmp(ToRegister(left), ToOperand(right)); | |
William Hesse
2011/09/09 11:14:46
This must be a cmpl.
Alexandre
2011/09/09 17:07:22
Done on x64.
| |
1569 } | |
1570 } | |
1571 EmitBranch(true_block, false_block, cc); | |
1551 } | 1572 } |
1552 | |
1553 Condition cc = TokenToCondition(instr->op(), instr->is_double()); | |
1554 EmitBranch(true_block, false_block, cc); | |
1555 } | 1573 } |
1556 | 1574 |
1557 | 1575 |
1558 void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) { | 1576 void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) { |
1559 Register left = ToRegister(instr->InputAt(0)); | 1577 Register left = ToRegister(instr->InputAt(0)); |
1560 Register right = ToRegister(instr->InputAt(1)); | 1578 Register right = ToRegister(instr->InputAt(1)); |
1561 int false_block = chunk_->LookupDestination(instr->false_block_id()); | 1579 int false_block = chunk_->LookupDestination(instr->false_block_id()); |
1562 int true_block = chunk_->LookupDestination(instr->true_block_id()); | 1580 int true_block = chunk_->LookupDestination(instr->true_block_id()); |
1563 | 1581 |
1564 __ cmpq(left, right); | 1582 __ cmpq(left, right); |
(...skipping 2598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4163 RegisterEnvironmentForDeoptimization(environment); | 4181 RegisterEnvironmentForDeoptimization(environment); |
4164 ASSERT(osr_pc_offset_ == -1); | 4182 ASSERT(osr_pc_offset_ == -1); |
4165 osr_pc_offset_ = masm()->pc_offset(); | 4183 osr_pc_offset_ = masm()->pc_offset(); |
4166 } | 4184 } |
4167 | 4185 |
4168 #undef __ | 4186 #undef __ |
4169 | 4187 |
4170 } } // namespace v8::internal | 4188 } } // namespace v8::internal |
4171 | 4189 |
4172 #endif // V8_TARGET_ARCH_X64 | 4190 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |