OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #if V8_TARGET_ARCH_IA32 | 5 #if V8_TARGET_ARCH_IA32 |
6 | 6 |
7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
8 #include "src/codegen.h" | 8 #include "src/codegen.h" |
9 #include "src/deoptimizer.h" | 9 #include "src/deoptimizer.h" |
10 #include "src/full-codegen/full-codegen.h" | 10 #include "src/full-codegen/full-codegen.h" |
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 __ sub(scratch1, Immediate(1)); | 838 __ sub(scratch1, Immediate(1)); |
839 __ bind(&loop_check); | 839 __ bind(&loop_check); |
840 __ cmp(scratch1, Immediate(0)); | 840 __ cmp(scratch1, Immediate(0)); |
841 __ j(greater, &loop_header, Label::kNear); | 841 __ j(greater, &loop_header, Label::kNear); |
842 } | 842 } |
843 | 843 |
844 } // end anonymous namespace | 844 } // end anonymous namespace |
845 | 845 |
846 // static | 846 // static |
847 void Builtins::Generate_InterpreterPushArgsAndConstructImpl( | 847 void Builtins::Generate_InterpreterPushArgsAndConstructImpl( |
848 MacroAssembler* masm, CallableType construct_type) { | 848 MacroAssembler* masm, PushArgsConstructMode mode) { |
849 // ----------- S t a t e ------------- | 849 // ----------- S t a t e ------------- |
850 // -- eax : the number of arguments (not including the receiver) | 850 // -- eax : the number of arguments (not including the receiver) |
851 // -- edx : the new target | 851 // -- edx : the new target |
852 // -- edi : the constructor | 852 // -- edi : the constructor |
853 // -- ebx : allocation site feedback (if available or undefined) | 853 // -- ebx : allocation site feedback (if available or undefined) |
854 // -- ecx : the address of the first argument to be pushed. Subsequent | 854 // -- ecx : the address of the first argument to be pushed. Subsequent |
855 // arguments should be consecutive above this, in the same order as | 855 // arguments should be consecutive above this, in the same order as |
856 // they are to be pushed onto the stack. | 856 // they are to be pushed onto the stack. |
857 // ----------------------------------- | 857 // ----------------------------------- |
858 Label stack_overflow; | 858 Label stack_overflow; |
859 // We need two scratch registers. Push edi and edx onto stack. | 859 // We need two scratch registers. Push edi and edx onto stack. |
860 __ Push(edi); | 860 __ Push(edi); |
861 __ Push(edx); | 861 __ Push(edx); |
862 | 862 |
863 // Push arguments and move return address to the top of stack. | 863 // Push arguments and move return address to the top of stack. |
864 // The eax register is readonly. The ecx register will be modified. The edx | 864 // The eax register is readonly. The ecx register will be modified. The edx |
865 // and edi registers will be modified but restored to their original values. | 865 // and edi registers will be modified but restored to their original values. |
866 Generate_InterpreterPushArgsAndReturnAddress(masm, eax, ecx, edx, edi, false, | 866 Generate_InterpreterPushArgsAndReturnAddress(masm, eax, ecx, edx, edi, false, |
867 2, &stack_overflow); | 867 2, &stack_overflow); |
868 | 868 |
869 // Restore edi and edx | 869 // Restore edi and edx |
870 __ Pop(edx); | 870 __ Pop(edx); |
871 __ Pop(edi); | 871 __ Pop(edi); |
872 | 872 |
873 __ AssertUndefinedOrAllocationSite(ebx); | 873 __ AssertUndefinedOrAllocationSite(ebx); |
874 if (construct_type == CallableType::kJSFunction) { | 874 if (mode == PushArgsConstructMode::kJSFunction) { |
875 // Tail call to the function-specific construct stub (still in the caller | 875 // Tail call to the function-specific construct stub (still in the caller |
876 // context at this point). | 876 // context at this point). |
877 __ AssertFunction(edi); | 877 __ AssertFunction(edi); |
878 | 878 |
879 __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); | 879 __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
880 __ mov(ecx, FieldOperand(ecx, SharedFunctionInfo::kConstructStubOffset)); | 880 __ mov(ecx, FieldOperand(ecx, SharedFunctionInfo::kConstructStubOffset)); |
881 __ lea(ecx, FieldOperand(ecx, Code::kHeaderSize)); | 881 __ lea(ecx, FieldOperand(ecx, Code::kHeaderSize)); |
882 __ jmp(ecx); | 882 __ jmp(ecx); |
| 883 } else if (mode == PushArgsConstructMode::kWithFinalSpread) { |
| 884 // Call the constructor with unmodified eax, edi, edx values. |
| 885 __ Jump(masm->isolate()->builtins()->ConstructWithSpread(), |
| 886 RelocInfo::CODE_TARGET); |
883 } else { | 887 } else { |
884 DCHECK_EQ(construct_type, CallableType::kAny); | 888 DCHECK_EQ(PushArgsConstructMode::kOther, mode); |
885 | |
886 // Call the constructor with unmodified eax, edi, edx values. | 889 // Call the constructor with unmodified eax, edi, edx values. |
887 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); | 890 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); |
888 } | 891 } |
889 | 892 |
890 __ bind(&stack_overflow); | 893 __ bind(&stack_overflow); |
891 { | 894 { |
892 // Pop the temporary registers, so that return address is on top of stack. | 895 // Pop the temporary registers, so that return address is on top of stack. |
893 __ Pop(edx); | 896 __ Pop(edx); |
894 __ Pop(edi); | 897 __ Pop(edi); |
895 | 898 |
(...skipping 1892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2788 } | 2791 } |
2789 | 2792 |
2790 // Called Construct on an Object that doesn't have a [[Construct]] internal | 2793 // Called Construct on an Object that doesn't have a [[Construct]] internal |
2791 // method. | 2794 // method. |
2792 __ bind(&non_constructor); | 2795 __ bind(&non_constructor); |
2793 __ Jump(masm->isolate()->builtins()->ConstructedNonConstructable(), | 2796 __ Jump(masm->isolate()->builtins()->ConstructedNonConstructable(), |
2794 RelocInfo::CODE_TARGET); | 2797 RelocInfo::CODE_TARGET); |
2795 } | 2798 } |
2796 | 2799 |
2797 // static | 2800 // static |
| 2801 void Builtins::Generate_ConstructWithSpread(MacroAssembler* masm) { |
| 2802 // ----------- S t a t e ------------- |
| 2803 // -- eax : the number of arguments (not including the receiver) |
| 2804 // -- edx : the new target (either the same as the constructor or |
| 2805 // the JSFunction on which new was invoked initially) |
| 2806 // -- edi : the constructor to call (can be any Object) |
| 2807 // ----------------------------------- |
| 2808 |
| 2809 // Free up some registers. |
| 2810 __ movd(xmm0, edx); |
| 2811 __ movd(xmm1, edi); |
| 2812 |
| 2813 Register argc = eax; |
| 2814 |
| 2815 Register scratch = ecx; |
| 2816 Register scratch2 = edi; |
| 2817 |
| 2818 Register spread = ebx; |
| 2819 Register spread_map = edx; |
| 2820 |
| 2821 __ mov(spread, Operand(esp, kPointerSize)); |
| 2822 __ mov(spread_map, FieldOperand(spread, HeapObject::kMapOffset)); |
| 2823 |
| 2824 Label runtime_call, push_args; |
| 2825 // Check that the spread is an array. |
| 2826 __ CmpInstanceType(spread_map, JS_ARRAY_TYPE); |
| 2827 __ j(not_equal, &runtime_call); |
| 2828 |
| 2829 // Check that we have the original ArrayPrototype. |
| 2830 __ mov(scratch, FieldOperand(spread_map, Map::kPrototypeOffset)); |
| 2831 __ mov(scratch2, NativeContextOperand()); |
| 2832 __ cmp(scratch, |
| 2833 ContextOperand(scratch2, Context::INITIAL_ARRAY_PROTOTYPE_INDEX)); |
| 2834 __ j(not_equal, &runtime_call); |
| 2835 |
| 2836 // Check that the ArrayPrototype hasn't been modified in a way that would |
| 2837 // affect iteration. |
| 2838 __ LoadRoot(scratch, Heap::kArrayIteratorProtectorRootIndex); |
| 2839 __ cmp(FieldOperand(scratch, Cell::kValueOffset), |
| 2840 Immediate(Smi::FromInt(Isolate::kProtectorValid))); |
| 2841 __ j(not_equal, &runtime_call); |
| 2842 |
| 2843 // Check that the map of the initial array iterator hasn't changed. |
| 2844 __ mov(scratch2, NativeContextOperand()); |
| 2845 __ mov(scratch, |
| 2846 ContextOperand(scratch2, |
| 2847 Context::INITIAL_ARRAY_ITERATOR_PROTOTYPE_INDEX)); |
| 2848 __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 2849 __ cmp(scratch, |
| 2850 ContextOperand(scratch2, |
| 2851 Context::INITIAL_ARRAY_ITERATOR_PROTOTYPE_MAP_INDEX)); |
| 2852 __ j(not_equal, &runtime_call); |
| 2853 |
| 2854 // For FastPacked kinds, iteration will have the same effect as simply |
| 2855 // accessing each property in order. |
| 2856 Label no_protector_check; |
| 2857 __ mov(scratch, FieldOperand(spread_map, Map::kBitField2Offset)); |
| 2858 __ DecodeField<Map::ElementsKindBits>(scratch); |
| 2859 __ cmp(scratch, Immediate(LAST_FAST_ELEMENTS_KIND)); |
| 2860 __ j(above, &runtime_call); |
| 2861 // For non-FastHoley kinds, we can skip the protector check. |
| 2862 __ cmp(scratch, Immediate(FAST_SMI_ELEMENTS)); |
| 2863 __ j(equal, &no_protector_check); |
| 2864 __ cmp(scratch, Immediate(FAST_ELEMENTS)); |
| 2865 __ j(equal, &no_protector_check); |
| 2866 __ cmp(scratch, Immediate(FAST_DOUBLE_ELEMENTS)); |
| 2867 __ j(equal, &no_protector_check); |
| 2868 // Check the ArrayProtector cell. |
| 2869 __ LoadRoot(scratch, Heap::kArrayProtectorRootIndex); |
| 2870 __ cmp(FieldOperand(scratch, PropertyCell::kValueOffset), |
| 2871 Immediate(Smi::FromInt(Isolate::kProtectorValid))); |
| 2872 __ j(not_equal, &runtime_call); |
| 2873 |
| 2874 __ bind(&no_protector_check); |
| 2875 // Load the FixedArray backing store. |
| 2876 __ mov(spread, FieldOperand(spread, JSArray::kElementsOffset)); |
| 2877 // Free up some registers. |
| 2878 __ jmp(&push_args); |
| 2879 |
| 2880 __ bind(&runtime_call); |
| 2881 { |
| 2882 // Call the builtin for the result of the spread. |
| 2883 FrameScope scope(masm, StackFrame::INTERNAL); |
| 2884 // Need to save these on the stack. |
| 2885 __ movd(edi, xmm1); |
| 2886 __ movd(edx, xmm0); |
| 2887 __ Push(edi); |
| 2888 __ Push(edx); |
| 2889 __ SmiTag(argc); |
| 2890 __ Push(argc); |
| 2891 __ Push(spread); |
| 2892 __ CallRuntime(Runtime::kSpreadIterableFixed); |
| 2893 __ mov(spread, eax); |
| 2894 __ Pop(argc); |
| 2895 __ SmiUntag(argc); |
| 2896 __ Pop(edx); |
| 2897 __ Pop(edi); |
| 2898 // Free up some registers. |
| 2899 __ movd(xmm0, edx); |
| 2900 __ movd(xmm1, edi); |
| 2901 } |
| 2902 |
| 2903 Register spread_len = edx; |
| 2904 Register return_address = edi; |
| 2905 __ bind(&push_args); |
| 2906 { |
| 2907 // Pop the return address and spread argument. |
| 2908 __ PopReturnAddressTo(return_address); |
| 2909 __ Pop(scratch); |
| 2910 |
| 2911 // Calculate the new nargs including the result of the spread. |
| 2912 __ mov(spread_len, FieldOperand(spread, FixedArray::kLengthOffset)); |
| 2913 __ SmiUntag(spread_len); |
| 2914 // argc += spread_len - 1. Subtract 1 for the spread itself. |
| 2915 __ lea(argc, Operand(argc, spread_len, times_1, -1)); |
| 2916 } |
| 2917 |
| 2918 // Check for stack overflow. |
| 2919 { |
| 2920 // Check the stack for overflow. We are not trying to catch interruptions |
| 2921 // (i.e. debug break and preemption) here, so check the "real stack limit". |
| 2922 Label done; |
| 2923 __ LoadRoot(scratch, Heap::kRealStackLimitRootIndex); |
| 2924 // Make scratch the space we have left. The stack might already be |
| 2925 // overflowed here which will cause scratch to become negative. |
| 2926 __ neg(scratch); |
| 2927 __ add(scratch, esp); |
| 2928 __ sar(scratch, kPointerSizeLog2); |
| 2929 // Check if the arguments will overflow the stack. |
| 2930 __ cmp(scratch, spread_len); |
| 2931 __ j(greater, &done, Label::kNear); // Signed comparison. |
| 2932 __ TailCallRuntime(Runtime::kThrowStackOverflow); |
| 2933 __ bind(&done); |
| 2934 } |
| 2935 |
| 2936 // Put the evaluated spread onto the stack as additional arguments. |
| 2937 { |
| 2938 Register scratch2 = esi; |
| 2939 __ movd(xmm2, esi); |
| 2940 |
| 2941 __ mov(scratch, Immediate(0)); |
| 2942 Label done, loop; |
| 2943 __ bind(&loop); |
| 2944 __ cmp(scratch, spread_len); |
| 2945 __ j(equal, &done, Label::kNear); |
| 2946 __ mov(scratch2, FieldOperand(spread, scratch, times_pointer_size, |
| 2947 FixedArray::kHeaderSize)); |
| 2948 __ Push(scratch2); |
| 2949 __ inc(scratch); |
| 2950 __ jmp(&loop); |
| 2951 __ bind(&done); |
| 2952 __ PushReturnAddressFrom(return_address); |
| 2953 __ movd(esi, xmm2); |
| 2954 __ movd(edi, xmm1); |
| 2955 __ movd(edx, xmm0); |
| 2956 } |
| 2957 |
| 2958 // Dispatch. |
| 2959 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); |
| 2960 } |
| 2961 |
| 2962 // static |
2798 void Builtins::Generate_AllocateInNewSpace(MacroAssembler* masm) { | 2963 void Builtins::Generate_AllocateInNewSpace(MacroAssembler* masm) { |
2799 // ----------- S t a t e ------------- | 2964 // ----------- S t a t e ------------- |
2800 // -- edx : requested object size (untagged) | 2965 // -- edx : requested object size (untagged) |
2801 // -- esp[0] : return address | 2966 // -- esp[0] : return address |
2802 // ----------------------------------- | 2967 // ----------------------------------- |
2803 __ SmiTag(edx); | 2968 __ SmiTag(edx); |
2804 __ PopReturnAddressTo(ecx); | 2969 __ PopReturnAddressTo(ecx); |
2805 __ Push(edx); | 2970 __ Push(edx); |
2806 __ PushReturnAddressFrom(ecx); | 2971 __ PushReturnAddressFrom(ecx); |
2807 __ Move(esi, Smi::kZero); | 2972 __ Move(esi, Smi::kZero); |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3109 | 3274 |
3110 void Builtins::Generate_InterpreterOnStackReplacement(MacroAssembler* masm) { | 3275 void Builtins::Generate_InterpreterOnStackReplacement(MacroAssembler* masm) { |
3111 Generate_OnStackReplacementHelper(masm, true); | 3276 Generate_OnStackReplacementHelper(masm, true); |
3112 } | 3277 } |
3113 | 3278 |
3114 #undef __ | 3279 #undef __ |
3115 } // namespace internal | 3280 } // namespace internal |
3116 } // namespace v8 | 3281 } // namespace v8 |
3117 | 3282 |
3118 #endif // V8_TARGET_ARCH_IA32 | 3283 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |