| 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 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 public: | 509 public: |
| 510 RecordWriteStub(Register object, | 510 RecordWriteStub(Register object, |
| 511 Register value, | 511 Register value, |
| 512 Register address, | 512 Register address, |
| 513 EmitRememberedSet emit_remembered_set, | 513 EmitRememberedSet emit_remembered_set, |
| 514 SaveFPRegsMode fp_mode) | 514 SaveFPRegsMode fp_mode) |
| 515 : object_(object), | 515 : object_(object), |
| 516 value_(value), | 516 value_(value), |
| 517 address_(address), | 517 address_(address), |
| 518 emit_remembered_set_(emit_remembered_set), | 518 emit_remembered_set_(emit_remembered_set), |
| 519 save_fp_regs_mode_(fp_mode) { | 519 save_fp_regs_mode_(fp_mode), |
| 520 regs_(object, // An input reg. |
| 521 address, // An input reg. |
| 522 value) { // One scratch reg. |
| 520 } | 523 } |
| 521 | 524 |
| 522 static const byte kTwoByteNopInstruction = 0x3c; // Cmpb al, #imm8. | 525 static const byte kTwoByteNopInstruction = 0x3c; // Cmpb al, #imm8. |
| 523 static const byte kSkipIncrementalPartInstruction = 0xeb; // Jmp #imm8. | 526 static const byte kSkipNonIncrementalPartInstruction = 0xeb; // Jmp #imm8. |
| 524 | 527 |
| 525 static byte GetInstruction(bool enable) { | 528 static byte GetInstruction(bool enable) { |
| 526 // Can't use ternary operator here, because gcc makes an undefined | 529 // Can't use ternary operator here, because gcc makes an undefined |
| 527 // reference to a static const int. | 530 // reference to a static const int. |
| 528 if (enable) { | 531 if (enable) { |
| 532 return kSkipNonIncrementalPartInstruction; |
| 533 } else { |
| 529 return kTwoByteNopInstruction; | 534 return kTwoByteNopInstruction; |
| 530 } else { | |
| 531 return kSkipIncrementalPartInstruction; | |
| 532 } | 535 } |
| 533 } | 536 } |
| 534 | 537 |
| 535 static void Patch(Code* stub, bool enable) { | 538 static void Patch(Code* stub, bool enable) { |
| 536 ASSERT(*stub->instruction_start() == GetInstruction(!enable)); | 539 ASSERT(*stub->instruction_start() == GetInstruction(!enable)); |
| 537 *stub->instruction_start() = GetInstruction(enable); | 540 *stub->instruction_start() = GetInstruction(enable); |
| 538 } | 541 } |
| 539 | 542 |
| 540 private: | 543 private: |
| 544 // This is a helper class for freeing up 3 scratch registers, where the third |
| 545 // is always ecx (needed for shift operations). The input is two registers |
| 546 // that must be preserved and one scratch register provided by the caller. |
| 547 class RegisterAllocation { |
| 548 public: |
| 549 RegisterAllocation(Register object, |
| 550 Register address, |
| 551 Register scratch0) |
| 552 : object_orig_(object), |
| 553 address_orig_(address), |
| 554 scratch0_orig_(scratch0), |
| 555 object_(object), |
| 556 address_(address), |
| 557 scratch0_(scratch0) { |
| 558 ASSERT(!Aliasing(scratch0, object, address, no_reg)); |
| 559 scratch1_ = GetRegThatIsNotEcxOr(object_, address_, scratch0_); |
| 560 if (scratch0.is(ecx)) { |
| 561 scratch0_ = GetRegThatIsNotEcxOr(object_, address_, scratch1_); |
| 562 } |
| 563 if (object.is(ecx)) { |
| 564 object_ = GetRegThatIsNotEcxOr(address_, scratch0_, scratch1_); |
| 565 } |
| 566 if (address.is(ecx)) { |
| 567 address_ = GetRegThatIsNotEcxOr(object_, scratch0_, scratch1_); |
| 568 } |
| 569 ASSERT(!Aliasing(scratch0_, object_, address_, ecx)); |
| 570 } |
| 571 |
| 572 void Save(MacroAssembler* masm) { |
| 573 ASSERT(!address_orig_.is(object_)); |
| 574 ASSERT(object_.is(object_orig_) || address_.is(address_orig_)); |
| 575 ASSERT(!Aliasing(object_, address_, scratch1_, scratch0_)); |
| 576 ASSERT(!Aliasing(object_orig_, address_, scratch1_, scratch0_)); |
| 577 ASSERT(!Aliasing(object_, address_orig_, scratch1_, scratch0_)); |
| 578 // We don't have to save scratch0_orig_ because it was given to us as |
| 579 // a scratch register. But if we had to switch to a different reg then |
| 580 // we should save the new scratch0_. |
| 581 if (!scratch0_.is(scratch0_orig_)) masm->push(scratch0_); |
| 582 if (!ecx.is(scratch0_orig_) && |
| 583 !ecx.is(object_orig_) && |
| 584 !ecx.is(address_orig_)) { |
| 585 masm->push(ecx); |
| 586 } |
| 587 masm->push(scratch1_); |
| 588 if (!address_.is(address_orig_)) { |
| 589 masm->push(address_); |
| 590 masm->mov(address_, address_orig_); |
| 591 } |
| 592 if (!object_.is(object_orig_)) { |
| 593 masm->push(object_); |
| 594 masm->mov(object_, object_orig_); |
| 595 } |
| 596 } |
| 597 |
| 598 void Restore(MacroAssembler* masm) { |
| 599 // These will have been preserved the entire time, so we just need to move |
| 600 // them back. Only in one case is the orig_ reg different from the plain |
| 601 // one, since only one of them can alias with ecx. |
| 602 if (!object_.is(object_orig_)) { |
| 603 masm->mov(object_orig_, object_); |
| 604 masm->pop(object_); |
| 605 } |
| 606 if (!address_.is(address_orig_)) { |
| 607 masm->mov(address_orig_, address_); |
| 608 masm->pop(address_); |
| 609 } |
| 610 masm->pop(scratch1_); |
| 611 if (!ecx.is(scratch0_orig_) && |
| 612 !ecx.is(object_orig_) && |
| 613 !ecx.is(address_orig_)) { |
| 614 masm->pop(ecx); |
| 615 } |
| 616 if (!scratch0_.is(scratch0_orig_)) masm->pop(scratch0_); |
| 617 } |
| 618 |
| 619 // If we have to call into C then we need to save and restore all caller- |
| 620 // saved registers that were not already preserved. The caller saved |
| 621 // registers are eax, ecx and adx. The three scratch registers (incl. ecx) |
| 622 // will be restored by other means so we don't bother pushing them here. |
| 623 void SaveCallerSaveRegisters(MacroAssembler* masm, SaveFPRegsMode mode) { |
| 624 if (!scratch0_.is(eax) && !scratch1_.is(eax)) masm->push(eax); |
| 625 if (!scratch0_.is(edx) && !scratch1_.is(edx)) masm->push(edx); |
| 626 if (mode == kSaveFPRegs) { |
| 627 CpuFeatures::Scope scope(SSE2); |
| 628 masm->sub(Operand(esp), |
| 629 Immediate(kDoubleSize * (XMMRegister::kNumRegisters - 1))); |
| 630 // Save all XMM registers except XMM0. |
| 631 for (int i = XMMRegister::kNumRegisters - 1; i > 0; i--) { |
| 632 XMMRegister reg = XMMRegister::from_code(i); |
| 633 masm->movdbl(Operand(esp, (i - 1) * kDoubleSize), reg); |
| 634 } |
| 635 } |
| 636 } |
| 637 |
| 638 inline void RestoreCallerSaveRegisters(MacroAssembler*masm, |
| 639 SaveFPRegsMode mode) { |
| 640 if (mode == kSaveFPRegs) { |
| 641 CpuFeatures::Scope scope(SSE2); |
| 642 // Restore all XMM registers except XMM0. |
| 643 for (int i = XMMRegister::kNumRegisters - 1; i > 0; i--) { |
| 644 XMMRegister reg = XMMRegister::from_code(i); |
| 645 masm->movdbl(reg, Operand(esp, (i - 1) * kDoubleSize)); |
| 646 } |
| 647 masm->add(Operand(esp), |
| 648 Immediate(kDoubleSize * (XMMRegister::kNumRegisters - 1))); |
| 649 } |
| 650 if (!scratch0_.is(edx) && !scratch1_.is(edx)) masm->pop(edx); |
| 651 if (!scratch0_.is(eax) && !scratch1_.is(eax)) masm->pop(eax); |
| 652 } |
| 653 |
| 654 inline Register object() { return object_; } |
| 655 inline Register address() { return address_; } |
| 656 inline Register scratch0() { return scratch0_; } |
| 657 inline Register scratch1() { return scratch1_; } |
| 658 |
| 659 private: |
| 660 Register object_orig_; |
| 661 Register address_orig_; |
| 662 Register scratch0_orig_; |
| 663 Register object_; |
| 664 Register address_; |
| 665 Register scratch0_; |
| 666 Register scratch1_; |
| 667 // Third scratch register is always ecx. |
| 668 |
| 669 Register GetRegThatIsNotEcxOr(Register r1, |
| 670 Register r2, |
| 671 Register r3) { |
| 672 for (int i = 0; i < Register::kNumAllocatableRegisters; i++) { |
| 673 Register candidate = Register::FromAllocationIndex(i); |
| 674 if (candidate.is(ecx)) continue; |
| 675 if (candidate.is(r1)) continue; |
| 676 if (candidate.is(r2)) continue; |
| 677 if (candidate.is(r3)) continue; |
| 678 return candidate; |
| 679 } |
| 680 UNREACHABLE(); |
| 681 return no_reg; |
| 682 } |
| 683 friend class RecordWriteStub; |
| 684 }; |
| 685 |
| 541 void Generate(MacroAssembler* masm); | 686 void Generate(MacroAssembler* masm); |
| 687 void GenerateIncremental(MacroAssembler* masm); |
| 688 void GenerateIncrementalValueIsInNewSpace(MacroAssembler* masm); |
| 689 void GenerateIncrementalValueIsInNewSpaceObjectIsInOldSpaceRememberedSet( |
| 690 MacroAssembler* masm); |
| 691 void GenerateIncrementalValueIsInNewSpaceObjectIsInOldSpaceNoRememberedSet( |
| 692 MacroAssembler* masm, |
| 693 Label* value_in_new_space_object_is_black_no_remembered_set); |
| 694 void GenerateIncrementalValueIsInOldSpace(MacroAssembler* masm); |
| 542 | 695 |
| 543 Major MajorKey() { return RecordWrite; } | 696 Major MajorKey() { return RecordWrite; } |
| 544 | 697 |
| 545 int MinorKey() { | 698 int MinorKey() { |
| 546 return ObjectBits::encode(object_.code()) | | 699 return ObjectBits::encode(object_.code()) | |
| 547 ValueBits::encode(value_.code()) | | 700 ValueBits::encode(value_.code()) | |
| 548 AddressBits::encode(address_.code()) | | 701 AddressBits::encode(address_.code()) | |
| 549 EmitRememberedSetBits::encode(emit_remembered_set_) | | 702 EmitRememberedSetBits::encode(emit_remembered_set_) | |
| 550 SaveFPRegsModeBits::encode(save_fp_regs_mode_); | 703 SaveFPRegsModeBits::encode(save_fp_regs_mode_); |
| 551 } | 704 } |
| 552 | 705 |
| 553 class ObjectBits: public BitField<int, 0, 3> {}; | 706 class ObjectBits: public BitField<int, 0, 3> {}; |
| 554 class ValueBits: public BitField<int, 3, 3> {}; | 707 class ValueBits: public BitField<int, 3, 3> {}; |
| 555 class AddressBits: public BitField<int, 6, 3> {}; | 708 class AddressBits: public BitField<int, 6, 3> {}; |
| 556 class EmitRememberedSetBits: public BitField<EmitRememberedSet, 9, 1> {}; | 709 class EmitRememberedSetBits: public BitField<EmitRememberedSet, 9, 1> {}; |
| 557 class SaveFPRegsModeBits: public BitField<SaveFPRegsMode, 10, 1> {}; | 710 class SaveFPRegsModeBits: public BitField<SaveFPRegsMode, 10, 1> {}; |
| 558 | 711 |
| 559 Register object_; | 712 Register object_; |
| 560 Register value_; | 713 Register value_; |
| 561 Register address_; | 714 Register address_; |
| 562 EmitRememberedSet emit_remembered_set_; | 715 EmitRememberedSet emit_remembered_set_; |
| 563 SaveFPRegsMode save_fp_regs_mode_; | 716 SaveFPRegsMode save_fp_regs_mode_; |
| 717 Label slow_; |
| 718 RegisterAllocation regs_; |
| 564 }; | 719 }; |
| 565 | 720 |
| 566 | 721 |
| 567 // Generate code to load an element from a pixel array. The receiver is assumed | 722 // Generate code to load an element from a pixel array. The receiver is assumed |
| 568 // to not be a smi and to have elements, the caller must guarantee this | 723 // to not be a smi and to have elements, the caller must guarantee this |
| 569 // precondition. If key is not a smi, then the generated code branches to | 724 // precondition. If key is not a smi, then the generated code branches to |
| 570 // key_not_smi. Callers can specify NULL for key_not_smi to signal that a smi | 725 // key_not_smi. Callers can specify NULL for key_not_smi to signal that a smi |
| 571 // check has already been performed on key so that the smi check is not | 726 // check has already been performed on key so that the smi check is not |
| 572 // generated. If key is not a valid index within the bounds of the pixel array, | 727 // generated. If key is not a valid index within the bounds of the pixel array, |
| 573 // the generated code jumps to out_of_range. receiver, key and elements are | 728 // the generated code jumps to out_of_range. receiver, key and elements are |
| (...skipping 27 matching lines...) Expand all Loading... |
| 601 Register scratch1, | 756 Register scratch1, |
| 602 bool load_elements_from_receiver, | 757 bool load_elements_from_receiver, |
| 603 Label* key_not_smi, | 758 Label* key_not_smi, |
| 604 Label* value_not_smi, | 759 Label* value_not_smi, |
| 605 Label* not_pixel_array, | 760 Label* not_pixel_array, |
| 606 Label* out_of_range); | 761 Label* out_of_range); |
| 607 | 762 |
| 608 } } // namespace v8::internal | 763 } } // namespace v8::internal |
| 609 | 764 |
| 610 #endif // V8_IA32_CODE_STUBS_IA32_H_ | 765 #endif // V8_IA32_CODE_STUBS_IA32_H_ |
| OLD | NEW |