OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 friend class JumpTarget; | 597 friend class JumpTarget; |
598 friend class Reference; | 598 friend class Reference; |
599 friend class Result; | 599 friend class Result; |
600 | 600 |
601 friend class CodeGeneratorPatcher; // Used in test-log-stack-tracer.cc | 601 friend class CodeGeneratorPatcher; // Used in test-log-stack-tracer.cc |
602 | 602 |
603 DISALLOW_COPY_AND_ASSIGN(CodeGenerator); | 603 DISALLOW_COPY_AND_ASSIGN(CodeGenerator); |
604 }; | 604 }; |
605 | 605 |
606 | 606 |
607 // Flag that indicates whether or not the code that handles smi arguments | 607 // Flag that indicates whether how to generate code for the stub. |
608 // should be placed in the stub, inlined, or omitted entirely. | |
609 enum GenericBinaryFlags { | 608 enum GenericBinaryFlags { |
610 SMI_CODE_IN_STUB, | 609 NO_GENERIC_BINARY_FLAGS = 0, |
611 SMI_CODE_INLINED | 610 NO_SMI_CODE_IN_STUB = 1 << 0 // Omit smi code in stub. |
612 }; | 611 }; |
613 | 612 |
614 | 613 |
615 class GenericBinaryOpStub: public CodeStub { | 614 class GenericBinaryOpStub: public CodeStub { |
616 public: | 615 public: |
617 GenericBinaryOpStub(Token::Value op, | 616 GenericBinaryOpStub(Token::Value operation, |
618 OverwriteMode mode, | 617 OverwriteMode mode, |
619 GenericBinaryFlags flags) | 618 GenericBinaryFlags flags) |
620 : op_(op), mode_(mode), flags_(flags) { | 619 : op_(operation), |
| 620 mode_(mode), |
| 621 flags_(flags), |
| 622 args_in_registers_(false), |
| 623 args_reversed_(false) { |
621 use_sse3_ = CpuFeatures::IsSupported(CpuFeatures::SSE3); | 624 use_sse3_ = CpuFeatures::IsSupported(CpuFeatures::SSE3); |
622 ASSERT(OpBits::is_valid(Token::NUM_TOKENS)); | 625 ASSERT(OpBits::is_valid(Token::NUM_TOKENS)); |
623 } | 626 } |
624 | 627 |
625 void GenerateSmiCode(MacroAssembler* masm, Label* slow); | 628 // Generate code to call the stub with the supplied arguments. This will add |
| 629 // code at the call site to prepare arguments either in registers or on the |
| 630 // stack together with the actual call. |
| 631 void GenerateCall(MacroAssembler* masm, Register left, Register right); |
| 632 void GenerateCall(MacroAssembler* masm, Register left, Smi* right); |
| 633 void GenerateCall(MacroAssembler* masm, Smi* left, Register right); |
626 | 634 |
627 private: | 635 private: |
628 Token::Value op_; | 636 Token::Value op_; |
629 OverwriteMode mode_; | 637 OverwriteMode mode_; |
630 GenericBinaryFlags flags_; | 638 GenericBinaryFlags flags_; |
| 639 bool args_in_registers_; // Arguments passed in registers not on the stack. |
| 640 bool args_reversed_; // Left and right argument are swapped. |
631 bool use_sse3_; | 641 bool use_sse3_; |
632 | 642 |
633 const char* GetName(); | 643 const char* GetName(); |
634 | 644 |
635 #ifdef DEBUG | 645 #ifdef DEBUG |
636 void Print() { | 646 void Print() { |
637 PrintF("GenericBinaryOpStub (op %s), (mode %d, flags %d)\n", | 647 PrintF("GenericBinaryOpStub (op %s), (mode %d, flags %d, registers %d, rever
sed %d)\n", |
638 Token::String(op_), | 648 Token::String(op_), |
639 static_cast<int>(mode_), | 649 static_cast<int>(mode_), |
640 static_cast<int>(flags_)); | 650 static_cast<int>(flags_), |
| 651 static_cast<int>(args_in_registers_), |
| 652 static_cast<int>(args_reversed_)); |
641 } | 653 } |
642 #endif | 654 #endif |
643 | 655 |
644 // Minor key encoding in 16 bits FSOOOOOOOOOOOOMM. | 656 // Minor key encoding in 16 bits FRASOOOOOOOOOOMM. |
645 class ModeBits: public BitField<OverwriteMode, 0, 2> {}; | 657 class ModeBits: public BitField<OverwriteMode, 0, 2> {}; |
646 class OpBits: public BitField<Token::Value, 2, 12> {}; | 658 class OpBits: public BitField<Token::Value, 2, 10> {}; |
647 class SSE3Bits: public BitField<bool, 14, 1> {}; | 659 class SSE3Bits: public BitField<bool, 12, 1> {}; |
| 660 class ArgsInRegistersBits: public BitField<bool, 13, 1> {}; |
| 661 class ArgsReversedBits: public BitField<bool, 14, 1> {}; |
648 class FlagBits: public BitField<GenericBinaryFlags, 15, 1> {}; | 662 class FlagBits: public BitField<GenericBinaryFlags, 15, 1> {}; |
649 | 663 |
650 Major MajorKey() { return GenericBinaryOp; } | 664 Major MajorKey() { return GenericBinaryOp; } |
651 int MinorKey() { | 665 int MinorKey() { |
652 // Encode the parameters in a unique 16 bit value. | 666 // Encode the parameters in a unique 16 bit value. |
653 return OpBits::encode(op_) | 667 return OpBits::encode(op_) |
654 | ModeBits::encode(mode_) | 668 | ModeBits::encode(mode_) |
655 | FlagBits::encode(flags_) | 669 | FlagBits::encode(flags_) |
656 | SSE3Bits::encode(use_sse3_); | 670 | SSE3Bits::encode(use_sse3_) |
| 671 | ArgsInRegistersBits::encode(args_in_registers_) |
| 672 | ArgsReversedBits::encode(args_reversed_); |
657 } | 673 } |
| 674 |
658 void Generate(MacroAssembler* masm); | 675 void Generate(MacroAssembler* masm); |
| 676 void GenerateSmiCode(MacroAssembler* masm, Label* slow); |
| 677 void GenerateLoadArguments(MacroAssembler* masm); |
| 678 void GenerateReturn(MacroAssembler* masm); |
| 679 |
| 680 bool ArgsInRegistersSupported() { |
| 681 return ((op_ == Token::ADD) || (op_ == Token::SUB) |
| 682 || (op_ == Token::MUL) || (op_ == Token::DIV)) |
| 683 && flags_ != NO_SMI_CODE_IN_STUB; |
| 684 } |
| 685 bool IsOperationCommutative() { |
| 686 return (op_ == Token::ADD) || (op_ == Token::MUL); |
| 687 } |
| 688 |
| 689 void SetArgsInRegisters() { args_in_registers_ = true; } |
| 690 void SetArgsReversed() { args_reversed_ = true; } |
| 691 bool HasSmiCodeInStub() { return (flags_ & NO_SMI_CODE_IN_STUB) == 0; } |
| 692 bool HasArgumentsInRegisters() { return args_in_registers_; } |
| 693 bool HasArgumentsReversed() { return args_reversed_; } |
659 }; | 694 }; |
660 | 695 |
661 | 696 |
662 } } // namespace v8::internal | 697 } } // namespace v8::internal |
663 | 698 |
664 #endif // V8_IA32_CODEGEN_IA32_H_ | 699 #endif // V8_IA32_CODEGEN_IA32_H_ |
OLD | NEW |