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/base/bits.h" | 7 #include "src/base/bits.h" |
8 #include "src/base/division-by-constant.h" | 8 #include "src/base/division-by-constant.h" |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
(...skipping 1968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1979 jmp(done, done_near); | 1979 jmp(done, done_near); |
1980 } | 1980 } |
1981 } else { | 1981 } else { |
1982 jmp(adaptor, RelocInfo::CODE_TARGET); | 1982 jmp(adaptor, RelocInfo::CODE_TARGET); |
1983 } | 1983 } |
1984 bind(&invoke); | 1984 bind(&invoke); |
1985 } | 1985 } |
1986 } | 1986 } |
1987 | 1987 |
1988 | 1988 |
1989 void MacroAssembler::FloodFunctionIfStepping(Register fun, Register new_target, | 1989 void MacroAssembler::InvokeCode(const Operand& code, |
1990 const ParameterCount& expected, | 1990 Register new_target, |
1991 const ParameterCount& actual) { | 1991 const ParameterCount& expected, |
1992 Label skip_flooding; | 1992 const ParameterCount& actual, |
1993 ExternalReference debug_step_action = | 1993 InvokeFlag flag, |
1994 ExternalReference::debug_last_step_action_address(isolate()); | 1994 const CallWrapper& call_wrapper) { |
1995 cmpb(Operand::StaticVariable(debug_step_action), StepIn); | |
1996 j(not_equal, &skip_flooding); | |
1997 { | |
1998 FrameScope frame(this, | |
1999 has_frame() ? StackFrame::NONE : StackFrame::INTERNAL); | |
2000 if (expected.is_reg()) { | |
2001 SmiTag(expected.reg()); | |
2002 Push(expected.reg()); | |
2003 } | |
2004 if (actual.is_reg()) { | |
2005 SmiTag(actual.reg()); | |
2006 Push(actual.reg()); | |
2007 } | |
2008 if (new_target.is_valid()) { | |
2009 Push(new_target); | |
2010 } | |
2011 Push(fun); | |
2012 Push(fun); | |
2013 CallRuntime(Runtime::kDebugPrepareStepInIfStepping, 1); | |
2014 Pop(fun); | |
2015 if (new_target.is_valid()) { | |
2016 Pop(new_target); | |
2017 } | |
2018 if (actual.is_reg()) { | |
2019 Pop(actual.reg()); | |
2020 SmiUntag(actual.reg()); | |
2021 } | |
2022 if (expected.is_reg()) { | |
2023 Pop(expected.reg()); | |
2024 SmiUntag(expected.reg()); | |
2025 } | |
2026 } | |
2027 bind(&skip_flooding); | |
2028 } | |
2029 | |
2030 | |
2031 void MacroAssembler::InvokeFunctionCode(Register function, Register new_target, | |
2032 const ParameterCount& expected, | |
2033 const ParameterCount& actual, | |
2034 InvokeFlag flag, | |
2035 const CallWrapper& call_wrapper) { | |
2036 // You can't call a function without a valid frame. | 1995 // You can't call a function without a valid frame. |
2037 DCHECK(flag == JUMP_FUNCTION || has_frame()); | 1996 DCHECK(flag == JUMP_FUNCTION || has_frame()); |
2038 DCHECK(function.is(edi)); | 1997 |
| 1998 // Ensure new target is passed in the correct register. Otherwise clear the |
| 1999 // appropriate register in case new target is not given. |
2039 DCHECK_IMPLIES(new_target.is_valid(), new_target.is(edx)); | 2000 DCHECK_IMPLIES(new_target.is_valid(), new_target.is(edx)); |
2040 | |
2041 if (call_wrapper.NeedsDebugStepCheck()) { | |
2042 FloodFunctionIfStepping(function, new_target, expected, actual); | |
2043 } | |
2044 | |
2045 // Clear the new.target register if not given. | |
2046 if (!new_target.is_valid()) { | 2001 if (!new_target.is_valid()) { |
2047 mov(edx, isolate()->factory()->undefined_value()); | 2002 mov(edx, isolate()->factory()->undefined_value()); |
2048 } | 2003 } |
2049 | 2004 |
2050 Label done; | 2005 Label done; |
2051 bool definitely_mismatches = false; | 2006 bool definitely_mismatches = false; |
2052 InvokePrologue(expected, actual, &done, &definitely_mismatches, flag, | 2007 InvokePrologue(expected, actual, &done, &definitely_mismatches, flag, |
2053 Label::kNear, call_wrapper); | 2008 Label::kNear, call_wrapper); |
2054 if (!definitely_mismatches) { | 2009 if (!definitely_mismatches) { |
2055 // We call indirectly through the code field in the function to | |
2056 // allow recompilation to take effect without changing any of the | |
2057 // call sites. | |
2058 Operand code = FieldOperand(function, JSFunction::kCodeEntryOffset); | |
2059 if (flag == CALL_FUNCTION) { | 2010 if (flag == CALL_FUNCTION) { |
2060 call_wrapper.BeforeCall(CallSize(code)); | 2011 call_wrapper.BeforeCall(CallSize(code)); |
2061 call(code); | 2012 call(code); |
2062 call_wrapper.AfterCall(); | 2013 call_wrapper.AfterCall(); |
2063 } else { | 2014 } else { |
2064 DCHECK(flag == JUMP_FUNCTION); | 2015 DCHECK(flag == JUMP_FUNCTION); |
2065 jmp(code); | 2016 jmp(code); |
2066 } | 2017 } |
2067 bind(&done); | 2018 bind(&done); |
2068 } | 2019 } |
2069 } | 2020 } |
2070 | 2021 |
2071 | 2022 |
2072 void MacroAssembler::InvokeFunction(Register fun, | 2023 void MacroAssembler::InvokeFunction(Register fun, |
2073 Register new_target, | 2024 Register new_target, |
2074 const ParameterCount& actual, | 2025 const ParameterCount& actual, |
2075 InvokeFlag flag, | 2026 InvokeFlag flag, |
2076 const CallWrapper& call_wrapper) { | 2027 const CallWrapper& call_wrapper) { |
2077 // You can't call a function without a valid frame. | 2028 // You can't call a function without a valid frame. |
2078 DCHECK(flag == JUMP_FUNCTION || has_frame()); | 2029 DCHECK(flag == JUMP_FUNCTION || has_frame()); |
2079 | 2030 |
2080 DCHECK(fun.is(edi)); | 2031 DCHECK(fun.is(edi)); |
2081 mov(ebx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); | 2032 mov(ebx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
2082 mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); | 2033 mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
2083 mov(ebx, FieldOperand(ebx, SharedFunctionInfo::kFormalParameterCountOffset)); | 2034 mov(ebx, FieldOperand(ebx, SharedFunctionInfo::kFormalParameterCountOffset)); |
2084 SmiUntag(ebx); | 2035 SmiUntag(ebx); |
2085 | 2036 |
2086 ParameterCount expected(ebx); | 2037 ParameterCount expected(ebx); |
2087 InvokeFunctionCode(edi, new_target, expected, actual, flag, call_wrapper); | 2038 InvokeCode(FieldOperand(edi, JSFunction::kCodeEntryOffset), new_target, |
| 2039 expected, actual, flag, call_wrapper); |
2088 } | 2040 } |
2089 | 2041 |
2090 | 2042 |
2091 void MacroAssembler::InvokeFunction(Register fun, | 2043 void MacroAssembler::InvokeFunction(Register fun, |
2092 const ParameterCount& expected, | 2044 const ParameterCount& expected, |
2093 const ParameterCount& actual, | 2045 const ParameterCount& actual, |
2094 InvokeFlag flag, | 2046 InvokeFlag flag, |
2095 const CallWrapper& call_wrapper) { | 2047 const CallWrapper& call_wrapper) { |
2096 // You can't call a function without a valid frame. | 2048 // You can't call a function without a valid frame. |
2097 DCHECK(flag == JUMP_FUNCTION || has_frame()); | 2049 DCHECK(flag == JUMP_FUNCTION || has_frame()); |
2098 | 2050 |
2099 DCHECK(fun.is(edi)); | 2051 DCHECK(fun.is(edi)); |
2100 mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); | 2052 mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
2101 | 2053 |
2102 InvokeFunctionCode(edi, no_reg, expected, actual, flag, call_wrapper); | 2054 InvokeCode(FieldOperand(edi, JSFunction::kCodeEntryOffset), no_reg, |
| 2055 expected, actual, flag, call_wrapper); |
2103 } | 2056 } |
2104 | 2057 |
2105 | 2058 |
2106 void MacroAssembler::InvokeFunction(Handle<JSFunction> function, | 2059 void MacroAssembler::InvokeFunction(Handle<JSFunction> function, |
2107 const ParameterCount& expected, | 2060 const ParameterCount& expected, |
2108 const ParameterCount& actual, | 2061 const ParameterCount& actual, |
2109 InvokeFlag flag, | 2062 InvokeFlag flag, |
2110 const CallWrapper& call_wrapper) { | 2063 const CallWrapper& call_wrapper) { |
2111 LoadHeapObject(edi, function); | 2064 LoadHeapObject(edi, function); |
2112 InvokeFunction(edi, expected, actual, flag, call_wrapper); | 2065 InvokeFunction(edi, expected, actual, flag, call_wrapper); |
2113 } | 2066 } |
2114 | 2067 |
2115 | 2068 |
2116 void MacroAssembler::InvokeBuiltin(int native_context_index, InvokeFlag flag, | 2069 void MacroAssembler::InvokeBuiltin(int native_context_index, InvokeFlag flag, |
2117 const CallWrapper& call_wrapper) { | 2070 const CallWrapper& call_wrapper) { |
2118 // You can't call a builtin without a valid frame. | 2071 // You can't call a builtin without a valid frame. |
2119 DCHECK(flag == JUMP_FUNCTION || has_frame()); | 2072 DCHECK(flag == JUMP_FUNCTION || has_frame()); |
2120 | 2073 |
2121 // Rely on the assertion to check that the number of provided | 2074 // Rely on the assertion to check that the number of provided |
2122 // arguments match the expected number of arguments. Fake a | 2075 // arguments match the expected number of arguments. Fake a |
2123 // parameter count to avoid emitting code to do the check. | 2076 // parameter count to avoid emitting code to do the check. |
2124 ParameterCount expected(0); | 2077 ParameterCount expected(0); |
2125 GetBuiltinFunction(edi, native_context_index); | 2078 GetBuiltinFunction(edi, native_context_index); |
2126 InvokeFunctionCode(edi, no_reg, expected, expected, flag, call_wrapper); | 2079 InvokeCode(FieldOperand(edi, JSFunction::kCodeEntryOffset), no_reg, |
| 2080 expected, expected, flag, call_wrapper); |
2127 } | 2081 } |
2128 | 2082 |
2129 | 2083 |
2130 void MacroAssembler::GetBuiltinFunction(Register target, | 2084 void MacroAssembler::GetBuiltinFunction(Register target, |
2131 int native_context_index) { | 2085 int native_context_index) { |
2132 // Load the JavaScript builtin function from the builtins object. | 2086 // Load the JavaScript builtin function from the builtins object. |
2133 mov(target, GlobalObjectOperand()); | 2087 mov(target, GlobalObjectOperand()); |
2134 mov(target, FieldOperand(target, JSGlobalObject::kNativeContextOffset)); | 2088 mov(target, FieldOperand(target, JSGlobalObject::kNativeContextOffset)); |
2135 mov(target, ContextOperand(target, native_context_index)); | 2089 mov(target, ContextOperand(target, native_context_index)); |
2136 } | 2090 } |
2137 | 2091 |
2138 | 2092 |
| 2093 void MacroAssembler::GetBuiltinEntry(Register target, |
| 2094 int native_context_index) { |
| 2095 DCHECK(!target.is(edi)); |
| 2096 // Load the JavaScript builtin function from the builtins object. |
| 2097 GetBuiltinFunction(edi, native_context_index); |
| 2098 // Load the code entry point from the function into the target register. |
| 2099 mov(target, FieldOperand(edi, JSFunction::kCodeEntryOffset)); |
| 2100 } |
| 2101 |
| 2102 |
2139 void MacroAssembler::LoadContext(Register dst, int context_chain_length) { | 2103 void MacroAssembler::LoadContext(Register dst, int context_chain_length) { |
2140 if (context_chain_length > 0) { | 2104 if (context_chain_length > 0) { |
2141 // Move up the chain of contexts to the context containing the slot. | 2105 // Move up the chain of contexts to the context containing the slot. |
2142 mov(dst, Operand(esi, Context::SlotOffset(Context::PREVIOUS_INDEX))); | 2106 mov(dst, Operand(esi, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
2143 for (int i = 1; i < context_chain_length; i++) { | 2107 for (int i = 1; i < context_chain_length; i++) { |
2144 mov(dst, Operand(dst, Context::SlotOffset(Context::PREVIOUS_INDEX))); | 2108 mov(dst, Operand(dst, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
2145 } | 2109 } |
2146 } else { | 2110 } else { |
2147 // Slot is in the current function context. Move it into the | 2111 // Slot is in the current function context. Move it into the |
2148 // destination register in case we store into it (the write barrier | 2112 // destination register in case we store into it (the write barrier |
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3182 mov(eax, dividend); | 3146 mov(eax, dividend); |
3183 shr(eax, 31); | 3147 shr(eax, 31); |
3184 add(edx, eax); | 3148 add(edx, eax); |
3185 } | 3149 } |
3186 | 3150 |
3187 | 3151 |
3188 } // namespace internal | 3152 } // namespace internal |
3189 } // namespace v8 | 3153 } // namespace v8 |
3190 | 3154 |
3191 #endif // V8_TARGET_ARCH_IA32 | 3155 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |