OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_ASSEMBLER_X64_H_ | 5 #ifndef VM_ASSEMBLER_X64_H_ |
6 #define VM_ASSEMBLER_X64_H_ | 6 #define VM_ASSEMBLER_X64_H_ |
7 | 7 |
8 #ifndef VM_ASSEMBLER_H_ | 8 #ifndef VM_ASSEMBLER_H_ |
9 #error Do not include assembler_x64.h directly; use assembler.h instead. | 9 #error Do not include assembler_x64.h directly; use assembler.h instead. |
10 #endif | 10 #endif |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 | 314 |
315 static bool sse4_1_supported_; | 315 static bool sse4_1_supported_; |
316 #ifdef DEBUG | 316 #ifdef DEBUG |
317 static bool initialized_; | 317 static bool initialized_; |
318 #endif | 318 #endif |
319 }; | 319 }; |
320 | 320 |
321 | 321 |
322 class Assembler : public ValueObject { | 322 class Assembler : public ValueObject { |
323 public: | 323 public: |
324 explicit Assembler(bool use_far_branches = false) | 324 explicit Assembler(bool use_far_branches = false); |
325 : buffer_(), | 325 |
326 object_pool_(GrowableObjectArray::Handle()), | |
327 prologue_offset_(-1), | |
328 comments_() { | |
329 // This mode is only needed and implemented for MIPS and ARM. | |
330 ASSERT(!use_far_branches); | |
331 } | |
332 ~Assembler() { } | 326 ~Assembler() { } |
333 | 327 |
334 static const bool kNearJump = true; | 328 static const bool kNearJump = true; |
335 static const bool kFarJump = false; | 329 static const bool kFarJump = false; |
336 | 330 |
337 /* | 331 /* |
338 * Emit Machine Instructions. | 332 * Emit Machine Instructions. |
339 */ | 333 */ |
340 void call(Register reg); | 334 void call(Register reg); |
341 void call(const Address& address); | 335 void call(const Address& address); |
342 void call(Label* label); | 336 void call(Label* label); |
343 void call(const ExternalLabel* label); | 337 void call(const ExternalLabel* label); |
344 | 338 |
345 static const intptr_t kCallExternalLabelSize = 13; | 339 static const intptr_t kCallExternalLabelSize = 10; |
346 | 340 |
347 void pushq(Register reg); | 341 void pushq(Register reg); |
348 void pushq(const Address& address); | 342 void pushq(const Address& address); |
349 void pushq(const Immediate& imm); | 343 void pushq(const Immediate& imm); |
350 | 344 |
351 void popq(Register reg); | 345 void popq(Register reg); |
352 void popq(const Address& address); | 346 void popq(const Address& address); |
353 | 347 |
354 void setcc(Condition condition, ByteRegister dst); | 348 void setcc(Condition condition, ByteRegister dst); |
355 | 349 |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
645 void CompareRegisters(Register a, Register b); | 639 void CompareRegisters(Register a, Register b); |
646 | 640 |
647 // Issues a move instruction if 'to' is not the same as 'from'. | 641 // Issues a move instruction if 'to' is not the same as 'from'. |
648 void MoveRegister(Register to, Register from); | 642 void MoveRegister(Register to, Register from); |
649 void PopRegister(Register r); | 643 void PopRegister(Register r); |
650 | 644 |
651 void AddImmediate(Register reg, const Immediate& imm); | 645 void AddImmediate(Register reg, const Immediate& imm); |
652 | 646 |
653 void Drop(intptr_t stack_elements); | 647 void Drop(intptr_t stack_elements); |
654 | 648 |
655 void LoadObject(Register dst, const Object& object); | 649 enum Patchability { |
650 kPatchable, | |
651 kNotPatchable, | |
652 }; | |
653 | |
654 void LoadObjectFromPool(Register dst, const Object& obj, | |
655 Patchability patchable, Register pp); | |
656 void LoadObject(Register dst, const Object& object) { | |
657 LoadObjectFromPool(dst, object, kPatchable, PP); | |
658 } | |
659 void JumpPatchable(const ExternalLabel* label, Register pp); | |
660 void JumpFromPool(const ExternalLabel* label, Register pp); | |
661 void ConditionalJumpFromPool(Condition condition, const ExternalLabel* label, | |
662 Register pp); | |
663 void CallPatchable(const ExternalLabel* label); | |
664 void CallFromPool(const ExternalLabel* label); | |
656 void StoreObject(const Address& dst, const Object& obj); | 665 void StoreObject(const Address& dst, const Object& obj); |
657 void PushObject(const Object& object); | 666 void PushObject(const Object& object); |
658 void CompareObject(Register reg, const Object& object); | 667 void CompareObject(Register reg, const Object& object); |
659 void LoadDoubleConstant(XmmRegister dst, double value); | 668 void LoadDoubleConstant(XmmRegister dst, double value); |
660 | 669 |
661 // Destroys value. | 670 // Destroys value. |
662 void StoreIntoObject(Register object, // Object we are storing into. | 671 void StoreIntoObject(Register object, // Object we are storing into. |
663 const Address& dest, // Where we are storing into. | 672 const Address& dest, // Where we are storing into. |
664 Register value, // Value we are storing. | 673 Register value, // Value we are storing. |
665 bool can_value_be_smi = true); | 674 bool can_value_be_smi = true); |
666 | 675 |
667 void StoreIntoObjectNoBarrier(Register object, | 676 void StoreIntoObjectNoBarrier(Register object, |
668 const Address& dest, | 677 const Address& dest, |
669 Register value); | 678 Register value); |
670 | 679 |
671 void DoubleNegate(XmmRegister d); | 680 void DoubleNegate(XmmRegister d); |
672 void FloatNegate(XmmRegister f); | 681 void FloatNegate(XmmRegister f); |
673 | 682 |
674 void DoubleAbs(XmmRegister reg); | 683 void DoubleAbs(XmmRegister reg); |
675 | 684 |
676 void LockCmpxchgl(const Address& address, Register reg) { | 685 void LockCmpxchgl(const Address& address, Register reg) { |
677 lock(); | 686 lock(); |
678 cmpxchgl(address, reg); | 687 cmpxchgl(address, reg); |
679 } | 688 } |
680 | 689 |
681 void EnterFrame(intptr_t frame_space); | 690 void EnterFrame(intptr_t frame_space); |
682 void LeaveFrame(); | 691 void LeaveFrame(); |
692 void LeaveFrameWithPP(); | |
683 void ReserveAlignedFrameSpace(intptr_t frame_space); | 693 void ReserveAlignedFrameSpace(intptr_t frame_space); |
684 | 694 |
685 // Create a frame for calling into runtime that preserves all volatile | 695 // Create a frame for calling into runtime that preserves all volatile |
686 // registers. Frame's RSP is guaranteed to be correctly aligned and | 696 // registers. Frame's RSP is guaranteed to be correctly aligned and |
687 // frame_space bytes are reserved under it. | 697 // frame_space bytes are reserved under it. |
688 void EnterCallRuntimeFrame(intptr_t frame_space); | 698 void EnterCallRuntimeFrame(intptr_t frame_space); |
689 void LeaveCallRuntimeFrame(); | 699 void LeaveCallRuntimeFrame(); |
690 | 700 |
691 | 701 |
692 void CallRuntime(const RuntimeEntry& entry, intptr_t argument_count); | 702 void CallRuntime(const RuntimeEntry& entry, intptr_t argument_count); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
724 int prologue_offset() const { return prologue_offset_; } | 734 int prologue_offset() const { return prologue_offset_; } |
725 const ZoneGrowableArray<int>& GetPointerOffsets() const { | 735 const ZoneGrowableArray<int>& GetPointerOffsets() const { |
726 return buffer_.pointer_offsets(); | 736 return buffer_.pointer_offsets(); |
727 } | 737 } |
728 const GrowableObjectArray& object_pool() const { return object_pool_; } | 738 const GrowableObjectArray& object_pool() const { return object_pool_; } |
729 | 739 |
730 void FinalizeInstructions(const MemoryRegion& region) { | 740 void FinalizeInstructions(const MemoryRegion& region) { |
731 buffer_.FinalizeInstructions(region); | 741 buffer_.FinalizeInstructions(region); |
732 } | 742 } |
733 | 743 |
744 void LoadPoolPointer(Register pp); | |
745 | |
734 // Set up a Dart frame on entry with a frame pointer and PC information to | 746 // Set up a Dart frame on entry with a frame pointer and PC information to |
735 // enable easy access to the RawInstruction object of code corresponding | 747 // enable easy access to the RawInstruction object of code corresponding |
736 // to this frame. | 748 // to this frame. |
737 // The dart frame layout is as follows: | 749 // The dart frame layout is as follows: |
738 // .... | 750 // .... |
739 // ret PC | 751 // ret PC |
740 // saved RBP <=== RBP | 752 // saved RBP <=== RBP |
741 // pc (used to derive the RawInstruction Object of the dart code) | 753 // pc (used to derive the RawInstruction Object of the dart code) |
754 // saved PP | |
742 // locals space <=== RSP | 755 // locals space <=== RSP |
743 // ..... | 756 // ..... |
744 // This code sets this up with the sequence: | 757 // This code sets this up with the sequence: |
745 // pushq rbp | 758 // pushq rbp |
746 // movq rbp, rsp | 759 // movq rbp, rsp |
747 // call L | 760 // call L |
748 // L: <code to adjust saved pc if there is any intrinsification code> | 761 // L: <code to adjust saved pc if there is any intrinsification code> |
762 // ... | |
763 // pushq r15 | |
749 // ..... | 764 // ..... |
750 void EnterDartFrame(intptr_t frame_size); | 765 void EnterDartFrame(intptr_t frame_size, Register new_pp, Register new_pc); |
751 | 766 |
752 // Set up a Dart frame for a function compiled for on-stack replacement. | 767 // Set up a Dart frame for a function compiled for on-stack replacement. |
753 // The frame layout is a normal Dart frame, but the frame is partially set | 768 // The frame layout is a normal Dart frame, but the frame is partially set |
754 // up on entry (it is the frame of the unoptimized code). | 769 // up on entry (it is the frame of the unoptimized code). |
755 void EnterOsrFrame(intptr_t extra_size); | 770 void EnterOsrFrame(intptr_t extra_size, Register new_pp, Register new_pc); |
756 | 771 |
757 // Set up a stub frame so that the stack traversal code can easily identify | 772 // Set up a stub frame so that the stack traversal code can easily identify |
758 // a stub frame. | 773 // a stub frame. |
759 // The stub frame layout is as follows: | 774 // The stub frame layout is as follows: |
760 // .... | 775 // .... |
761 // ret PC | 776 // ret PC |
762 // saved RBP | 777 // saved RBP |
763 // pc (used to derive the RawInstruction Object of the stub) | 778 // pc (used to derive the RawInstruction Object of the stub) |
764 // ..... | 779 // ..... |
765 // This code sets this up with the sequence: | 780 // This code sets this up with the sequence: |
766 // pushq rbp | 781 // pushq rbp |
767 // movq rbp, rsp | 782 // movq rbp, rsp |
768 // pushq immediate(0) | 783 // pushq immediate(0) |
769 // ..... | 784 // ..... |
770 void EnterStubFrame(); | 785 void EnterStubFrame(); |
786 void EnterStubFrameWithPP(); | |
771 | 787 |
772 // Instruction pattern from entrypoint is used in dart frame prologs | 788 // Instruction pattern from entrypoint is used in dart frame prologues |
773 // to set up the frame and save a PC which can be used to figure out the | 789 // to set up the frame and save a PC which can be used to figure out the |
774 // RawInstruction object corresponding to the code running in the frame. | 790 // RawInstruction object corresponding to the code running in the frame. |
775 // entrypoint: | 791 // entrypoint: |
776 // pushq rbp (size is 1 byte) | 792 // pushq rbp (size is 1 byte) |
777 // movq rbp, rsp (size is 3 bytes) | 793 // movq rbp, rsp (size is 3 bytes) |
778 // call L (size is 5 bytes) | 794 // call L (size is 5 bytes) |
779 // L: | 795 // L: |
780 static const intptr_t kEntryPointToPcMarkerOffset = 9; | 796 static const intptr_t kEntryPointToPcMarkerOffset = 9; |
781 | 797 |
782 // Inlined allocation of an instance of class 'cls', code has no runtime | 798 // Inlined allocation of an instance of class 'cls', code has no runtime |
(...skipping 12 matching lines...) Expand all Loading... | |
795 void Unreachable(const char* message); | 811 void Unreachable(const char* message); |
796 | 812 |
797 static void InitializeMemoryWithBreakpoints(uword data, int length); | 813 static void InitializeMemoryWithBreakpoints(uword data, int length); |
798 | 814 |
799 static const char* RegisterName(Register reg); | 815 static const char* RegisterName(Register reg); |
800 | 816 |
801 static const char* FpuRegisterName(FpuRegister reg); | 817 static const char* FpuRegisterName(FpuRegister reg); |
802 | 818 |
803 private: | 819 private: |
804 AssemblerBuffer buffer_; | 820 AssemblerBuffer buffer_; |
805 GrowableObjectArray& object_pool_; // Object pool is not used on x64. | 821 GrowableObjectArray& object_pool_; // Objects and patchable jump targets. |
806 int prologue_offset_; | 822 int prologue_offset_; |
807 | 823 |
808 class CodeComment : public ZoneAllocated { | 824 class CodeComment : public ZoneAllocated { |
809 public: | 825 public: |
810 CodeComment(intptr_t pc_offset, const String& comment) | 826 CodeComment(intptr_t pc_offset, const String& comment) |
811 : pc_offset_(pc_offset), comment_(comment) { } | 827 : pc_offset_(pc_offset), comment_(comment) { } |
812 | 828 |
813 intptr_t pc_offset() const { return pc_offset_; } | 829 intptr_t pc_offset() const { return pc_offset_; } |
814 const String& comment() const { return comment_; } | 830 const String& comment() const { return comment_; } |
815 | 831 |
816 private: | 832 private: |
817 intptr_t pc_offset_; | 833 intptr_t pc_offset_; |
818 const String& comment_; | 834 const String& comment_; |
819 | 835 |
820 DISALLOW_COPY_AND_ASSIGN(CodeComment); | 836 DISALLOW_COPY_AND_ASSIGN(CodeComment); |
821 }; | 837 }; |
822 | 838 |
823 GrowableArray<CodeComment*> comments_; | 839 GrowableArray<CodeComment*> comments_; |
824 | 840 |
841 int32_t AddObject(const Object& obj); | |
842 int32_t AddExternalLabel(const ExternalLabel* label, Patchability patchable); | |
843 void LoadExternalLabel(Register dst, | |
844 const ExternalLabel* label, | |
845 Patchability, | |
srdjan
2013/09/04 22:57:23
Give the argument its nam, e.g., patchable.
zra
2013/09/05 00:23:11
Done.
| |
846 Register pp); | |
847 bool CanLoadFromObjectPool(const Object& object); | |
848 void LoadWordFromPoolOffset(Register dst, Register pp, int32_t offset, | |
849 Patchability patchable); | |
850 | |
825 inline void EmitUint8(uint8_t value); | 851 inline void EmitUint8(uint8_t value); |
826 inline void EmitInt32(int32_t value); | 852 inline void EmitInt32(int32_t value); |
827 inline void EmitInt64(int64_t value); | 853 inline void EmitInt64(int64_t value); |
828 | 854 |
829 inline void EmitRegisterREX(Register reg, uint8_t rex); | 855 inline void EmitRegisterREX(Register reg, uint8_t rex); |
830 inline void EmitRegisterOperand(int rm, int reg); | 856 inline void EmitRegisterOperand(int rm, int reg); |
831 inline void EmitOperandREX(int rm, const Operand& operand, uint8_t rex); | 857 inline void EmitOperandREX(int rm, const Operand& operand, uint8_t rex); |
832 inline void EmitXmmRegisterOperand(int rm, XmmRegister reg); | 858 inline void EmitXmmRegisterOperand(int rm, XmmRegister reg); |
833 inline void EmitFixup(AssemblerFixup* fixup); | 859 inline void EmitFixup(AssemblerFixup* fixup); |
834 inline void EmitOperandSizeOverride(); | 860 inline void EmitOperandSizeOverride(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
937 } | 963 } |
938 | 964 |
939 | 965 |
940 inline void Assembler::EmitOperandSizeOverride() { | 966 inline void Assembler::EmitOperandSizeOverride() { |
941 EmitUint8(0x66); | 967 EmitUint8(0x66); |
942 } | 968 } |
943 | 969 |
944 } // namespace dart | 970 } // namespace dart |
945 | 971 |
946 #endif // VM_ASSEMBLER_X64_H_ | 972 #endif // VM_ASSEMBLER_X64_H_ |
OLD | NEW |