| 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 10 matching lines...) Expand all  Loading... | 
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
| 27 | 27 | 
| 28 #ifndef V8_IA32_CODEGEN_IA32_H_ | 28 #ifndef V8_IA32_CODEGEN_IA32_H_ | 
| 29 #define V8_IA32_CODEGEN_IA32_H_ | 29 #define V8_IA32_CODEGEN_IA32_H_ | 
| 30 | 30 | 
|  | 31 #include "ic-inl.h" | 
|  | 32 | 
| 31 namespace v8 { | 33 namespace v8 { | 
| 32 namespace internal { | 34 namespace internal { | 
| 33 | 35 | 
| 34 // Forward declarations | 36 // Forward declarations | 
| 35 class CompilationInfo; | 37 class CompilationInfo; | 
| 36 class DeferredCode; | 38 class DeferredCode; | 
| 37 class RegisterAllocator; | 39 class RegisterAllocator; | 
| 38 class RegisterFile; | 40 class RegisterFile; | 
| 39 | 41 | 
| 40 enum InitState { CONST_INIT, NOT_CONST_INIT }; | 42 enum InitState { CONST_INIT, NOT_CONST_INIT }; | 
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 692  public: | 694  public: | 
| 693   GenericBinaryOpStub(Token::Value op, | 695   GenericBinaryOpStub(Token::Value op, | 
| 694                       OverwriteMode mode, | 696                       OverwriteMode mode, | 
| 695                       GenericBinaryFlags flags, | 697                       GenericBinaryFlags flags, | 
| 696                       NumberInfo::Type operands_type = NumberInfo::kUnknown) | 698                       NumberInfo::Type operands_type = NumberInfo::kUnknown) | 
| 697       : op_(op), | 699       : op_(op), | 
| 698         mode_(mode), | 700         mode_(mode), | 
| 699         flags_(flags), | 701         flags_(flags), | 
| 700         args_in_registers_(false), | 702         args_in_registers_(false), | 
| 701         args_reversed_(false), | 703         args_reversed_(false), | 
| 702         name_(NULL), | 704         static_operands_type_(operands_type), | 
| 703         operands_type_(operands_type) { | 705         runtime_operands_type_(BinaryOpIC::DEFAULT), | 
|  | 706         name_(NULL) { | 
| 704     use_sse3_ = CpuFeatures::IsSupported(SSE3); | 707     use_sse3_ = CpuFeatures::IsSupported(SSE3); | 
| 705     ASSERT(OpBits::is_valid(Token::NUM_TOKENS)); | 708     ASSERT(OpBits::is_valid(Token::NUM_TOKENS)); | 
| 706   } | 709   } | 
| 707 | 710 | 
|  | 711   GenericBinaryOpStub(int key, BinaryOpIC::TypeInfo runtime_operands_type) | 
|  | 712       : op_(OpBits::decode(key)), | 
|  | 713         mode_(ModeBits::decode(key)), | 
|  | 714         flags_(FlagBits::decode(key)), | 
|  | 715         args_in_registers_(ArgsInRegistersBits::decode(key)), | 
|  | 716         args_reversed_(ArgsReversedBits::decode(key)), | 
|  | 717         use_sse3_(SSE3Bits::decode(key)), | 
|  | 718         static_operands_type_(StaticTypeInfoBits::decode(key)), | 
|  | 719         runtime_operands_type_(runtime_operands_type), | 
|  | 720         name_(NULL) { | 
|  | 721   } | 
|  | 722 | 
| 708   // Generate code to call the stub with the supplied arguments. This will add | 723   // Generate code to call the stub with the supplied arguments. This will add | 
| 709   // code at the call site to prepare arguments either in registers or on the | 724   // code at the call site to prepare arguments either in registers or on the | 
| 710   // stack together with the actual call. | 725   // stack together with the actual call. | 
| 711   void GenerateCall(MacroAssembler* masm, Register left, Register right); | 726   void GenerateCall(MacroAssembler* masm, Register left, Register right); | 
| 712   void GenerateCall(MacroAssembler* masm, Register left, Smi* right); | 727   void GenerateCall(MacroAssembler* masm, Register left, Smi* right); | 
| 713   void GenerateCall(MacroAssembler* masm, Smi* left, Register right); | 728   void GenerateCall(MacroAssembler* masm, Smi* left, Register right); | 
| 714 | 729 | 
| 715   Result GenerateCall(MacroAssembler* masm, | 730   Result GenerateCall(MacroAssembler* masm, | 
| 716                       VirtualFrame* frame, | 731                       VirtualFrame* frame, | 
| 717                       Result* left, | 732                       Result* left, | 
| 718                       Result* right); | 733                       Result* right); | 
| 719 | 734 | 
| 720  private: | 735  private: | 
| 721   Token::Value op_; | 736   Token::Value op_; | 
| 722   OverwriteMode mode_; | 737   OverwriteMode mode_; | 
| 723   GenericBinaryFlags flags_; | 738   GenericBinaryFlags flags_; | 
| 724   bool args_in_registers_;  // Arguments passed in registers not on the stack. | 739   bool args_in_registers_;  // Arguments passed in registers not on the stack. | 
| 725   bool args_reversed_;  // Left and right argument are swapped. | 740   bool args_reversed_;  // Left and right argument are swapped. | 
| 726   bool use_sse3_; | 741   bool use_sse3_; | 
|  | 742 | 
|  | 743   // Number type information of operands, determined by code generator. | 
|  | 744   NumberInfo::Type static_operands_type_; | 
|  | 745 | 
|  | 746   // Operand type information determined at runtime. | 
|  | 747   BinaryOpIC::TypeInfo runtime_operands_type_; | 
|  | 748 | 
| 727   char* name_; | 749   char* name_; | 
| 728   NumberInfo::Type operands_type_;  // Number type information of operands. |  | 
| 729 | 750 | 
| 730   const char* GetName(); | 751   const char* GetName(); | 
| 731 | 752 | 
| 732 #ifdef DEBUG | 753 #ifdef DEBUG | 
| 733   void Print() { | 754   void Print() { | 
| 734     PrintF("GenericBinaryOpStub %d (op %s), " | 755     PrintF("GenericBinaryOpStub %d (op %s), " | 
| 735            "(mode %d, flags %d, registers %d, reversed %d, number_info %s)\n", | 756            "(mode %d, flags %d, registers %d, reversed %d, number_info %s)\n", | 
| 736            MinorKey(), | 757            MinorKey(), | 
| 737            Token::String(op_), | 758            Token::String(op_), | 
| 738            static_cast<int>(mode_), | 759            static_cast<int>(mode_), | 
| 739            static_cast<int>(flags_), | 760            static_cast<int>(flags_), | 
| 740            static_cast<int>(args_in_registers_), | 761            static_cast<int>(args_in_registers_), | 
| 741            static_cast<int>(args_reversed_), | 762            static_cast<int>(args_reversed_), | 
| 742            NumberInfo::ToString(operands_type_)); | 763            NumberInfo::ToString(static_operands_type_)); | 
| 743   } | 764   } | 
| 744 #endif | 765 #endif | 
| 745 | 766 | 
| 746   // Minor key encoding in 16 bits NNNFRASOOOOOOOMM. | 767   // Minor key encoding in 18 bits RRNNNFRASOOOOOOOMM. | 
| 747   class ModeBits: public BitField<OverwriteMode, 0, 2> {}; | 768   class ModeBits: public BitField<OverwriteMode, 0, 2> {}; | 
| 748   class OpBits: public BitField<Token::Value, 2, 7> {}; | 769   class OpBits: public BitField<Token::Value, 2, 7> {}; | 
| 749   class SSE3Bits: public BitField<bool, 9, 1> {}; | 770   class SSE3Bits: public BitField<bool, 9, 1> {}; | 
| 750   class ArgsInRegistersBits: public BitField<bool, 10, 1> {}; | 771   class ArgsInRegistersBits: public BitField<bool, 10, 1> {}; | 
| 751   class ArgsReversedBits: public BitField<bool, 11, 1> {}; | 772   class ArgsReversedBits: public BitField<bool, 11, 1> {}; | 
| 752   class FlagBits: public BitField<GenericBinaryFlags, 12, 1> {}; | 773   class FlagBits: public BitField<GenericBinaryFlags, 12, 1> {}; | 
| 753   class NumberInfoBits: public BitField<NumberInfo::Type, 13, 3> {}; | 774   class StaticTypeInfoBits: public BitField<NumberInfo::Type, 13, 3> {}; | 
|  | 775   class RuntimeTypeInfoBits: public BitField<BinaryOpIC::TypeInfo, 16, 2> {}; | 
| 754 | 776 | 
| 755   Major MajorKey() { return GenericBinaryOp; } | 777   Major MajorKey() { return GenericBinaryOp; } | 
| 756   int MinorKey() { | 778   int MinorKey() { | 
| 757     // Encode the parameters in a unique 16 bit value. | 779     // Encode the parameters in a unique 18 bit value. | 
| 758     return OpBits::encode(op_) | 780     return OpBits::encode(op_) | 
| 759            | ModeBits::encode(mode_) | 781            | ModeBits::encode(mode_) | 
| 760            | FlagBits::encode(flags_) | 782            | FlagBits::encode(flags_) | 
| 761            | SSE3Bits::encode(use_sse3_) | 783            | SSE3Bits::encode(use_sse3_) | 
| 762            | ArgsInRegistersBits::encode(args_in_registers_) | 784            | ArgsInRegistersBits::encode(args_in_registers_) | 
| 763            | ArgsReversedBits::encode(args_reversed_) | 785            | ArgsReversedBits::encode(args_reversed_) | 
| 764            | NumberInfoBits::encode(operands_type_); | 786            | StaticTypeInfoBits::encode(static_operands_type_) | 
|  | 787            | RuntimeTypeInfoBits::encode(runtime_operands_type_); | 
| 765   } | 788   } | 
| 766 | 789 | 
| 767   void Generate(MacroAssembler* masm); | 790   void Generate(MacroAssembler* masm); | 
| 768   void GenerateSmiCode(MacroAssembler* masm, Label* slow); | 791   void GenerateSmiCode(MacroAssembler* masm, Label* slow); | 
| 769   void GenerateLoadArguments(MacroAssembler* masm); | 792   void GenerateLoadArguments(MacroAssembler* masm); | 
| 770   void GenerateReturn(MacroAssembler* masm); | 793   void GenerateReturn(MacroAssembler* masm); | 
| 771   void GenerateHeapResultAllocation(MacroAssembler* masm, Label* alloc_failure); | 794   void GenerateHeapResultAllocation(MacroAssembler* masm, Label* alloc_failure); | 
|  | 795   void GenerateRegisterArgsPush(MacroAssembler* masm); | 
|  | 796   void GenerateTypeTransition(MacroAssembler* masm); | 
| 772 | 797 | 
| 773   bool ArgsInRegistersSupported() { | 798   bool ArgsInRegistersSupported() { | 
| 774     return op_ == Token::ADD || op_ == Token::SUB | 799     return op_ == Token::ADD || op_ == Token::SUB | 
| 775         || op_ == Token::MUL || op_ == Token::DIV; | 800         || op_ == Token::MUL || op_ == Token::DIV; | 
| 776   } | 801   } | 
| 777   bool IsOperationCommutative() { | 802   bool IsOperationCommutative() { | 
| 778     return (op_ == Token::ADD) || (op_ == Token::MUL); | 803     return (op_ == Token::ADD) || (op_ == Token::MUL); | 
| 779   } | 804   } | 
| 780 | 805 | 
| 781   void SetArgsInRegisters() { args_in_registers_ = true; } | 806   void SetArgsInRegisters() { args_in_registers_ = true; } | 
| 782   void SetArgsReversed() { args_reversed_ = true; } | 807   void SetArgsReversed() { args_reversed_ = true; } | 
| 783   bool HasSmiCodeInStub() { return (flags_ & NO_SMI_CODE_IN_STUB) == 0; } | 808   bool HasSmiCodeInStub() { return (flags_ & NO_SMI_CODE_IN_STUB) == 0; } | 
| 784   bool HasArgsInRegisters() { return args_in_registers_; } | 809   bool HasArgsInRegisters() { return args_in_registers_; } | 
| 785   bool HasArgsReversed() { return args_reversed_; } | 810   bool HasArgsReversed() { return args_reversed_; } | 
|  | 811 | 
|  | 812   bool ShouldGenerateSmiCode() { | 
|  | 813     return HasSmiCodeInStub() && | 
|  | 814         runtime_operands_type_ != BinaryOpIC::HEAP_NUMBERS && | 
|  | 815         runtime_operands_type_ != BinaryOpIC::STRINGS; | 
|  | 816   } | 
|  | 817 | 
|  | 818   bool ShouldGenerateFPCode() { | 
|  | 819     return runtime_operands_type_ != BinaryOpIC::STRINGS; | 
|  | 820   } | 
|  | 821 | 
|  | 822   virtual int GetCodeKind() { return Code::BINARY_OP_IC; } | 
|  | 823 | 
|  | 824   virtual InlineCacheState GetICState() { | 
|  | 825     return BinaryOpIC::ToState(runtime_operands_type_); | 
|  | 826   } | 
| 786 }; | 827 }; | 
| 787 | 828 | 
| 788 | 829 | 
| 789 class StringStubBase: public CodeStub { | 830 class StringStubBase: public CodeStub { | 
| 790  public: | 831  public: | 
| 791   // Generate code for copying characters using a simple loop. This should only | 832   // Generate code for copying characters using a simple loop. This should only | 
| 792   // be used in places where the number of characters is small and the | 833   // be used in places where the number of characters is small and the | 
| 793   // additional setup and checking in GenerateCopyCharactersREP adds too much | 834   // additional setup and checking in GenerateCopyCharactersREP adds too much | 
| 794   // overhead. Copying of overlapping regions is not supported. | 835   // overhead. Copying of overlapping regions is not supported. | 
| 795   void GenerateCopyCharacters(MacroAssembler* masm, | 836   void GenerateCopyCharacters(MacroAssembler* masm, | 
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 923   void Print() { | 964   void Print() { | 
| 924     PrintF("NumberToStringStub\n"); | 965     PrintF("NumberToStringStub\n"); | 
| 925   } | 966   } | 
| 926 #endif | 967 #endif | 
| 927 }; | 968 }; | 
| 928 | 969 | 
| 929 | 970 | 
| 930 } }  // namespace v8::internal | 971 } }  // namespace v8::internal | 
| 931 | 972 | 
| 932 #endif  // V8_IA32_CODEGEN_IA32_H_ | 973 #endif  // V8_IA32_CODEGEN_IA32_H_ | 
| OLD | NEW | 
|---|