| 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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 | 336 |
| 337 bool in_spilled_code() const { return in_spilled_code_; } | 337 bool in_spilled_code() const { return in_spilled_code_; } |
| 338 void set_in_spilled_code(bool flag) { in_spilled_code_ = flag; } | 338 void set_in_spilled_code(bool flag) { in_spilled_code_ = flag; } |
| 339 | 339 |
| 340 private: | 340 private: |
| 341 // Construction/Destruction | 341 // Construction/Destruction |
| 342 explicit CodeGenerator(MacroAssembler* masm); | 342 explicit CodeGenerator(MacroAssembler* masm); |
| 343 | 343 |
| 344 // Accessors | 344 // Accessors |
| 345 inline bool is_eval(); | 345 inline bool is_eval(); |
| 346 Scope* scope(); | 346 inline Scope* scope(); |
| 347 | 347 |
| 348 // Generating deferred code. | 348 // Generating deferred code. |
| 349 void ProcessDeferred(); | 349 void ProcessDeferred(); |
| 350 | 350 |
| 351 // State | 351 // State |
| 352 ControlDestination* destination() const { return state_->destination(); } | 352 ControlDestination* destination() const { return state_->destination(); } |
| 353 | 353 |
| 354 // Track loop nesting level. | 354 // Track loop nesting level. |
| 355 int loop_nesting() const { return loop_nesting_; } | 355 int loop_nesting() const { return loop_nesting_; } |
| 356 void IncrementLoopNesting() { loop_nesting_++; } | 356 void IncrementLoopNesting() { loop_nesting_++; } |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 void GenerateArgumentsAccess(ZoneList<Expression*>* args); | 540 void GenerateArgumentsAccess(ZoneList<Expression*>* args); |
| 541 | 541 |
| 542 // Support for accessing the class and value fields of an object. | 542 // Support for accessing the class and value fields of an object. |
| 543 void GenerateClassOf(ZoneList<Expression*>* args); | 543 void GenerateClassOf(ZoneList<Expression*>* args); |
| 544 void GenerateValueOf(ZoneList<Expression*>* args); | 544 void GenerateValueOf(ZoneList<Expression*>* args); |
| 545 void GenerateSetValueOf(ZoneList<Expression*>* args); | 545 void GenerateSetValueOf(ZoneList<Expression*>* args); |
| 546 | 546 |
| 547 // Fast support for charCodeAt(n). | 547 // Fast support for charCodeAt(n). |
| 548 void GenerateFastCharCodeAt(ZoneList<Expression*>* args); | 548 void GenerateFastCharCodeAt(ZoneList<Expression*>* args); |
| 549 | 549 |
| 550 // Fast support for string.charAt(n) and string[n]. |
| 551 void GenerateCharFromCode(ZoneList<Expression*>* args); |
| 552 |
| 550 // Fast support for object equality testing. | 553 // Fast support for object equality testing. |
| 551 void GenerateObjectEquals(ZoneList<Expression*>* args); | 554 void GenerateObjectEquals(ZoneList<Expression*>* args); |
| 552 | 555 |
| 553 void GenerateLog(ZoneList<Expression*>* args); | 556 void GenerateLog(ZoneList<Expression*>* args); |
| 554 | 557 |
| 555 void GenerateGetFramePointer(ZoneList<Expression*>* args); | 558 void GenerateGetFramePointer(ZoneList<Expression*>* args); |
| 556 | 559 |
| 557 // Fast support for Math.random(). | 560 // Fast support for Math.random(). |
| 558 void GenerateRandomPositiveSmi(ZoneList<Expression*>* args); | 561 void GenerateRandomPositiveSmi(ZoneList<Expression*>* args); |
| 559 | 562 |
| 560 // Fast support for StringAdd. | 563 // Fast support for StringAdd. |
| 561 void GenerateStringAdd(ZoneList<Expression*>* args); | 564 void GenerateStringAdd(ZoneList<Expression*>* args); |
| 562 | 565 |
| 563 // Fast support for SubString. | 566 // Fast support for SubString. |
| 564 void GenerateSubString(ZoneList<Expression*>* args); | 567 void GenerateSubString(ZoneList<Expression*>* args); |
| 565 | 568 |
| 566 // Fast support for StringCompare. | 569 // Fast support for StringCompare. |
| 567 void GenerateStringCompare(ZoneList<Expression*>* args); | 570 void GenerateStringCompare(ZoneList<Expression*>* args); |
| 568 | 571 |
| 569 // Support for direct calls from JavaScript to native RegExp code. | 572 // Support for direct calls from JavaScript to native RegExp code. |
| 570 void GenerateRegExpExec(ZoneList<Expression*>* args); | 573 void GenerateRegExpExec(ZoneList<Expression*>* args); |
| 571 | 574 |
| 572 // Fast support for number to string. | 575 // Fast support for number to string. |
| 573 void GenerateNumberToString(ZoneList<Expression*>* args); | 576 void GenerateNumberToString(ZoneList<Expression*>* args); |
| 574 | 577 |
| 578 // Fast support for Math.pow(). |
| 579 void GenerateMathPow(ZoneList<Expression*>* args); |
| 580 |
| 575 // Fast call to math functions. | 581 // Fast call to math functions. |
| 576 void GenerateMathSin(ZoneList<Expression*>* args); | 582 void GenerateMathSin(ZoneList<Expression*>* args); |
| 577 void GenerateMathCos(ZoneList<Expression*>* args); | 583 void GenerateMathCos(ZoneList<Expression*>* args); |
| 578 | 584 |
| 585 // Fast case for sqrt |
| 586 void GenerateMathSqrt(ZoneList<Expression*>* args); |
| 587 |
| 579 // Simple condition analysis. | 588 // Simple condition analysis. |
| 580 enum ConditionAnalysis { | 589 enum ConditionAnalysis { |
| 581 ALWAYS_TRUE, | 590 ALWAYS_TRUE, |
| 582 ALWAYS_FALSE, | 591 ALWAYS_FALSE, |
| 583 DONT_KNOW | 592 DONT_KNOW |
| 584 }; | 593 }; |
| 585 ConditionAnalysis AnalyzeCondition(Expression* cond); | 594 ConditionAnalysis AnalyzeCondition(Expression* cond); |
| 586 | 595 |
| 587 // Methods used to indicate which source code is generated for. Source | 596 // Methods used to indicate which source code is generated for. Source |
| 588 // positions are collected by the assembler and emitted with the relocation | 597 // positions are collected by the assembler and emitted with the relocation |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 NO_GENERIC_BINARY_FLAGS = 0, | 657 NO_GENERIC_BINARY_FLAGS = 0, |
| 649 NO_SMI_CODE_IN_STUB = 1 << 0 // Omit smi code in stub. | 658 NO_SMI_CODE_IN_STUB = 1 << 0 // Omit smi code in stub. |
| 650 }; | 659 }; |
| 651 | 660 |
| 652 | 661 |
| 653 class GenericBinaryOpStub: public CodeStub { | 662 class GenericBinaryOpStub: public CodeStub { |
| 654 public: | 663 public: |
| 655 GenericBinaryOpStub(Token::Value op, | 664 GenericBinaryOpStub(Token::Value op, |
| 656 OverwriteMode mode, | 665 OverwriteMode mode, |
| 657 GenericBinaryFlags flags, | 666 GenericBinaryFlags flags, |
| 658 NumberInfo::Type operands_type = NumberInfo::kUnknown) | 667 NumberInfo operands_type = NumberInfo::Unknown()) |
| 659 : op_(op), | 668 : op_(op), |
| 660 mode_(mode), | 669 mode_(mode), |
| 661 flags_(flags), | 670 flags_(flags), |
| 662 args_in_registers_(false), | 671 args_in_registers_(false), |
| 663 args_reversed_(false), | 672 args_reversed_(false), |
| 664 name_(NULL), | 673 name_(NULL), |
| 665 operands_type_(operands_type) { | 674 operands_type_(operands_type) { |
| 666 use_sse3_ = CpuFeatures::IsSupported(SSE3); | 675 use_sse3_ = CpuFeatures::IsSupported(SSE3); |
| 667 ASSERT(OpBits::is_valid(Token::NUM_TOKENS)); | 676 ASSERT(OpBits::is_valid(Token::NUM_TOKENS)); |
| 668 } | 677 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 680 Result* right); | 689 Result* right); |
| 681 | 690 |
| 682 private: | 691 private: |
| 683 Token::Value op_; | 692 Token::Value op_; |
| 684 OverwriteMode mode_; | 693 OverwriteMode mode_; |
| 685 GenericBinaryFlags flags_; | 694 GenericBinaryFlags flags_; |
| 686 bool args_in_registers_; // Arguments passed in registers not on the stack. | 695 bool args_in_registers_; // Arguments passed in registers not on the stack. |
| 687 bool args_reversed_; // Left and right argument are swapped. | 696 bool args_reversed_; // Left and right argument are swapped. |
| 688 bool use_sse3_; | 697 bool use_sse3_; |
| 689 char* name_; | 698 char* name_; |
| 690 NumberInfo::Type operands_type_; | 699 NumberInfo operands_type_; |
| 691 | 700 |
| 692 const char* GetName(); | 701 const char* GetName(); |
| 693 | 702 |
| 694 #ifdef DEBUG | 703 #ifdef DEBUG |
| 695 void Print() { | 704 void Print() { |
| 696 PrintF("GenericBinaryOpStub %d (op %s), " | 705 PrintF("GenericBinaryOpStub %d (op %s), " |
| 697 "(mode %d, flags %d, registers %d, reversed %d, only_numbers %s)\n", | 706 "(mode %d, flags %d, registers %d, reversed %d, only_numbers %s)\n", |
| 698 MinorKey(), | 707 MinorKey(), |
| 699 Token::String(op_), | 708 Token::String(op_), |
| 700 static_cast<int>(mode_), | 709 static_cast<int>(mode_), |
| 701 static_cast<int>(flags_), | 710 static_cast<int>(flags_), |
| 702 static_cast<int>(args_in_registers_), | 711 static_cast<int>(args_in_registers_), |
| 703 static_cast<int>(args_reversed_), | 712 static_cast<int>(args_reversed_), |
| 704 NumberInfo::ToString(operands_type_)); | 713 operands_type_.ToString()); |
| 705 } | 714 } |
| 706 #endif | 715 #endif |
| 707 | 716 |
| 708 // Minor key encoding in 16 bits NNNFRASOOOOOOOMM. | 717 // Minor key encoding in 16 bits NNNFRASOOOOOOOMM. |
| 709 class ModeBits: public BitField<OverwriteMode, 0, 2> {}; | 718 class ModeBits: public BitField<OverwriteMode, 0, 2> {}; |
| 710 class OpBits: public BitField<Token::Value, 2, 7> {}; | 719 class OpBits: public BitField<Token::Value, 2, 7> {}; |
| 711 class SSE3Bits: public BitField<bool, 9, 1> {}; | 720 class SSE3Bits: public BitField<bool, 9, 1> {}; |
| 712 class ArgsInRegistersBits: public BitField<bool, 10, 1> {}; | 721 class ArgsInRegistersBits: public BitField<bool, 10, 1> {}; |
| 713 class ArgsReversedBits: public BitField<bool, 11, 1> {}; | 722 class ArgsReversedBits: public BitField<bool, 11, 1> {}; |
| 714 class FlagBits: public BitField<GenericBinaryFlags, 12, 1> {}; | 723 class FlagBits: public BitField<GenericBinaryFlags, 12, 1> {}; |
| 715 class NumberInfoBits: public BitField<NumberInfo::Type, 13, 3> {}; | 724 class NumberInfoBits: public BitField<int, 13, 3> {}; |
| 716 | 725 |
| 717 Major MajorKey() { return GenericBinaryOp; } | 726 Major MajorKey() { return GenericBinaryOp; } |
| 718 int MinorKey() { | 727 int MinorKey() { |
| 719 // Encode the parameters in a unique 16 bit value. | 728 // Encode the parameters in a unique 16 bit value. |
| 720 return OpBits::encode(op_) | 729 return OpBits::encode(op_) |
| 721 | ModeBits::encode(mode_) | 730 | ModeBits::encode(mode_) |
| 722 | FlagBits::encode(flags_) | 731 | FlagBits::encode(flags_) |
| 723 | SSE3Bits::encode(use_sse3_) | 732 | SSE3Bits::encode(use_sse3_) |
| 724 | ArgsInRegistersBits::encode(args_in_registers_) | 733 | ArgsInRegistersBits::encode(args_in_registers_) |
| 725 | ArgsReversedBits::encode(args_reversed_) | 734 | ArgsReversedBits::encode(args_reversed_) |
| 726 | NumberInfoBits::encode(operands_type_); | 735 | NumberInfoBits::encode(operands_type_.ThreeBitRepresentation()); |
| 727 } | 736 } |
| 728 | 737 |
| 729 void Generate(MacroAssembler* masm); | 738 void Generate(MacroAssembler* masm); |
| 730 void GenerateSmiCode(MacroAssembler* masm, Label* slow); | 739 void GenerateSmiCode(MacroAssembler* masm, Label* slow); |
| 731 void GenerateLoadArguments(MacroAssembler* masm); | 740 void GenerateLoadArguments(MacroAssembler* masm); |
| 732 void GenerateReturn(MacroAssembler* masm); | 741 void GenerateReturn(MacroAssembler* masm); |
| 733 | 742 |
| 734 bool ArgsInRegistersSupported() { | 743 bool ArgsInRegistersSupported() { |
| 735 return (op_ == Token::ADD) || (op_ == Token::SUB) | 744 return (op_ == Token::ADD) || (op_ == Token::SUB) |
| 736 || (op_ == Token::MUL) || (op_ == Token::DIV); | 745 || (op_ == Token::MUL) || (op_ == Token::DIV); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 760 bool ascii); | 769 bool ascii); |
| 761 | 770 |
| 762 // Generate code for copying characters using the rep movs instruction. | 771 // Generate code for copying characters using the rep movs instruction. |
| 763 // Copies rcx characters from rsi to rdi. Copying of overlapping regions is | 772 // Copies rcx characters from rsi to rdi. Copying of overlapping regions is |
| 764 // not supported. | 773 // not supported. |
| 765 void GenerateCopyCharactersREP(MacroAssembler* masm, | 774 void GenerateCopyCharactersREP(MacroAssembler* masm, |
| 766 Register dest, // Must be rdi. | 775 Register dest, // Must be rdi. |
| 767 Register src, // Must be rsi. | 776 Register src, // Must be rsi. |
| 768 Register count, // Must be rcx. | 777 Register count, // Must be rcx. |
| 769 bool ascii); | 778 bool ascii); |
| 779 |
| 780 |
| 781 // Probe the symbol table for a two character string. If the string is |
| 782 // not found by probing a jump to the label not_found is performed. This jump |
| 783 // does not guarantee that the string is not in the symbol table. If the |
| 784 // string is found the code falls through with the string in register rax. |
| 785 void GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm, |
| 786 Register c1, |
| 787 Register c2, |
| 788 Register scratch1, |
| 789 Register scratch2, |
| 790 Register scratch3, |
| 791 Register scratch4, |
| 792 Label* not_found); |
| 793 |
| 794 // Generate string hash. |
| 795 void GenerateHashInit(MacroAssembler* masm, |
| 796 Register hash, |
| 797 Register character, |
| 798 Register scratch); |
| 799 void GenerateHashAddCharacter(MacroAssembler* masm, |
| 800 Register hash, |
| 801 Register character, |
| 802 Register scratch); |
| 803 void GenerateHashGetHash(MacroAssembler* masm, |
| 804 Register hash, |
| 805 Register scratch); |
| 770 }; | 806 }; |
| 771 | 807 |
| 772 | 808 |
| 773 // Flag that indicates how to generate code for the stub StringAddStub. | 809 // Flag that indicates how to generate code for the stub StringAddStub. |
| 774 enum StringAddFlags { | 810 enum StringAddFlags { |
| 775 NO_STRING_ADD_FLAGS = 0, | 811 NO_STRING_ADD_FLAGS = 0, |
| 776 NO_STRING_CHECK_IN_STUB = 1 << 0 // Omit string check in stub. | 812 NO_STRING_CHECK_IN_STUB = 1 << 0 // Omit string check in stub. |
| 777 }; | 813 }; |
| 778 | 814 |
| 779 | 815 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 Major MajorKey() { return StringCompare; } | 860 Major MajorKey() { return StringCompare; } |
| 825 int MinorKey() { return 0; } | 861 int MinorKey() { return 0; } |
| 826 | 862 |
| 827 void Generate(MacroAssembler* masm); | 863 void Generate(MacroAssembler* masm); |
| 828 }; | 864 }; |
| 829 | 865 |
| 830 | 866 |
| 831 } } // namespace v8::internal | 867 } } // namespace v8::internal |
| 832 | 868 |
| 833 #endif // V8_X64_CODEGEN_X64_H_ | 869 #endif // V8_X64_CODEGEN_X64_H_ |
| OLD | NEW |