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 #include "v8.h" | 5 #include "v8.h" |
6 | 6 |
7 #if V8_TARGET_ARCH_IA32 | 7 #if V8_TARGET_ARCH_X87 |
8 | 8 |
9 #include "codegen.h" | 9 #include "codegen.h" |
10 #include "deoptimizer.h" | 10 #include "deoptimizer.h" |
11 #include "full-codegen.h" | 11 #include "full-codegen.h" |
12 #include "safepoint-table.h" | 12 #include "safepoint-table.h" |
13 | 13 |
14 namespace v8 { | 14 namespace v8 { |
15 namespace internal { | 15 namespace internal { |
16 | 16 |
17 const int Deoptimizer::table_entry_size_ = 10; | 17 const int Deoptimizer::table_entry_size_ = 10; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 void Deoptimizer::FillInputFrame(Address tos, JavaScriptFrame* frame) { | 180 void Deoptimizer::FillInputFrame(Address tos, JavaScriptFrame* frame) { |
181 // Set the register values. The values are not important as there are no | 181 // Set the register values. The values are not important as there are no |
182 // callee saved registers in JavaScript frames, so all registers are | 182 // callee saved registers in JavaScript frames, so all registers are |
183 // spilled. Registers ebp and esp are set to the correct values though. | 183 // spilled. Registers ebp and esp are set to the correct values though. |
184 | 184 |
185 for (int i = 0; i < Register::kNumRegisters; i++) { | 185 for (int i = 0; i < Register::kNumRegisters; i++) { |
186 input_->SetRegister(i, i * 4); | 186 input_->SetRegister(i, i * 4); |
187 } | 187 } |
188 input_->SetRegister(esp.code(), reinterpret_cast<intptr_t>(frame->sp())); | 188 input_->SetRegister(esp.code(), reinterpret_cast<intptr_t>(frame->sp())); |
189 input_->SetRegister(ebp.code(), reinterpret_cast<intptr_t>(frame->fp())); | 189 input_->SetRegister(ebp.code(), reinterpret_cast<intptr_t>(frame->fp())); |
190 for (int i = 0; i < XMMRegister::kMaxNumAllocatableRegisters; i++) { | 190 for (int i = 0; i < DoubleRegister::NumAllocatableRegisters(); i++) { |
191 input_->SetDoubleRegister(i, 0.0); | 191 input_->SetDoubleRegister(i, 0.0); |
192 } | 192 } |
193 | 193 |
194 // Fill the frame content from the actual data on the frame. | 194 // Fill the frame content from the actual data on the frame. |
195 for (unsigned i = 0; i < input_->GetFrameSize(); i += kPointerSize) { | 195 for (unsigned i = 0; i < input_->GetFrameSize(); i += kPointerSize) { |
196 input_->SetFrameSlot(i, Memory::uint32_at(tos + i)); | 196 input_->SetFrameSlot(i, Memory::uint32_at(tos + i)); |
197 } | 197 } |
198 } | 198 } |
199 | 199 |
200 | 200 |
201 void Deoptimizer::SetPlatformCompiledStubRegisters( | 201 void Deoptimizer::SetPlatformCompiledStubRegisters( |
202 FrameDescription* output_frame, CodeStubInterfaceDescriptor* descriptor) { | 202 FrameDescription* output_frame, CodeStubInterfaceDescriptor* descriptor) { |
203 intptr_t handler = | 203 intptr_t handler = |
204 reinterpret_cast<intptr_t>(descriptor->deoptimization_handler_); | 204 reinterpret_cast<intptr_t>(descriptor->deoptimization_handler_); |
205 int params = descriptor->GetHandlerParameterCount(); | 205 int params = descriptor->GetHandlerParameterCount(); |
206 output_frame->SetRegister(eax.code(), params); | 206 output_frame->SetRegister(eax.code(), params); |
207 output_frame->SetRegister(ebx.code(), handler); | 207 output_frame->SetRegister(ebx.code(), handler); |
208 } | 208 } |
209 | 209 |
210 | 210 |
211 void Deoptimizer::CopyDoubleRegisters(FrameDescription* output_frame) { | 211 void Deoptimizer::CopyDoubleRegisters(FrameDescription* output_frame) { |
212 for (int i = 0; i < XMMRegister::kMaxNumAllocatableRegisters; ++i) { | 212 // Do nothing for X87. |
213 double double_value = input_->GetDoubleRegister(i); | 213 return; |
214 output_frame->SetDoubleRegister(i, double_value); | |
215 } | |
216 } | 214 } |
217 | 215 |
218 | 216 |
219 bool Deoptimizer::HasAlignmentPadding(JSFunction* function) { | 217 bool Deoptimizer::HasAlignmentPadding(JSFunction* function) { |
220 int parameter_count = function->shared()->formal_parameter_count() + 1; | 218 int parameter_count = function->shared()->formal_parameter_count() + 1; |
221 unsigned input_frame_size = input_->GetFrameSize(); | 219 unsigned input_frame_size = input_->GetFrameSize(); |
222 unsigned alignment_state_offset = | 220 unsigned alignment_state_offset = |
223 input_frame_size - parameter_count * kPointerSize - | 221 input_frame_size - parameter_count * kPointerSize - |
224 StandardFrameConstants::kFixedFrameSize - | 222 StandardFrameConstants::kFixedFrameSize - |
225 kPointerSize; | 223 kPointerSize; |
226 ASSERT(JavaScriptFrameConstants::kDynamicAlignmentStateOffset == | 224 ASSERT(JavaScriptFrameConstants::kDynamicAlignmentStateOffset == |
227 JavaScriptFrameConstants::kLocal0Offset); | 225 JavaScriptFrameConstants::kLocal0Offset); |
228 int32_t alignment_state = input_->GetFrameSlot(alignment_state_offset); | 226 int32_t alignment_state = input_->GetFrameSlot(alignment_state_offset); |
229 return (alignment_state == kAlignmentPaddingPushed); | 227 return (alignment_state == kAlignmentPaddingPushed); |
230 } | 228 } |
231 | 229 |
232 | 230 |
233 #define __ masm()-> | 231 #define __ masm()-> |
234 | 232 |
235 void Deoptimizer::EntryGenerator::Generate() { | 233 void Deoptimizer::EntryGenerator::Generate() { |
236 GeneratePrologue(); | 234 GeneratePrologue(); |
237 | 235 |
238 // Save all general purpose registers before messing with them. | 236 // Save all general purpose registers before messing with them. |
239 const int kNumberOfRegisters = Register::kNumRegisters; | 237 const int kNumberOfRegisters = Register::kNumRegisters; |
240 | |
241 const int kDoubleRegsSize = kDoubleSize * | |
242 XMMRegister::kMaxNumAllocatableRegisters; | |
243 __ sub(esp, Immediate(kDoubleRegsSize)); | |
244 for (int i = 0; i < XMMRegister::kMaxNumAllocatableRegisters; ++i) { | |
245 XMMRegister xmm_reg = XMMRegister::FromAllocationIndex(i); | |
246 int offset = i * kDoubleSize; | |
247 __ movsd(Operand(esp, offset), xmm_reg); | |
248 } | |
249 | |
250 __ pushad(); | 238 __ pushad(); |
251 | 239 |
252 const int kSavedRegistersAreaSize = kNumberOfRegisters * kPointerSize + | 240 const int kSavedRegistersAreaSize = kNumberOfRegisters * kPointerSize; |
253 kDoubleRegsSize; | |
254 | 241 |
255 // Get the bailout id from the stack. | 242 // Get the bailout id from the stack. |
256 __ mov(ebx, Operand(esp, kSavedRegistersAreaSize)); | 243 __ mov(ebx, Operand(esp, kSavedRegistersAreaSize)); |
257 | 244 |
258 // Get the address of the location in the code object | 245 // Get the address of the location in the code object |
259 // and compute the fp-to-sp delta in register edx. | 246 // and compute the fp-to-sp delta in register edx. |
260 __ mov(ecx, Operand(esp, kSavedRegistersAreaSize + 1 * kPointerSize)); | 247 __ mov(ecx, Operand(esp, kSavedRegistersAreaSize + 1 * kPointerSize)); |
261 __ lea(edx, Operand(esp, kSavedRegistersAreaSize + 2 * kPointerSize)); | 248 __ lea(edx, Operand(esp, kSavedRegistersAreaSize + 2 * kPointerSize)); |
262 | 249 |
263 __ sub(edx, ebp); | 250 __ sub(edx, ebp); |
(...skipping 17 matching lines...) Expand all Loading... |
281 // Preserve deoptimizer object in register eax and get the input | 268 // Preserve deoptimizer object in register eax and get the input |
282 // frame descriptor pointer. | 269 // frame descriptor pointer. |
283 __ mov(ebx, Operand(eax, Deoptimizer::input_offset())); | 270 __ mov(ebx, Operand(eax, Deoptimizer::input_offset())); |
284 | 271 |
285 // Fill in the input registers. | 272 // Fill in the input registers. |
286 for (int i = kNumberOfRegisters - 1; i >= 0; i--) { | 273 for (int i = kNumberOfRegisters - 1; i >= 0; i--) { |
287 int offset = (i * kPointerSize) + FrameDescription::registers_offset(); | 274 int offset = (i * kPointerSize) + FrameDescription::registers_offset(); |
288 __ pop(Operand(ebx, offset)); | 275 __ pop(Operand(ebx, offset)); |
289 } | 276 } |
290 | 277 |
291 int double_regs_offset = FrameDescription::double_registers_offset(); | |
292 // Fill in the double input registers. | |
293 for (int i = 0; i < XMMRegister::kMaxNumAllocatableRegisters; ++i) { | |
294 int dst_offset = i * kDoubleSize + double_regs_offset; | |
295 int src_offset = i * kDoubleSize; | |
296 __ movsd(xmm0, Operand(esp, src_offset)); | |
297 __ movsd(Operand(ebx, dst_offset), xmm0); | |
298 } | |
299 | |
300 // Clear FPU all exceptions. | 278 // Clear FPU all exceptions. |
301 // TODO(ulan): Find out why the TOP register is not zero here in some cases, | 279 // TODO(ulan): Find out why the TOP register is not zero here in some cases, |
302 // and check that the generated code never deoptimizes with unbalanced stack. | 280 // and check that the generated code never deoptimizes with unbalanced stack. |
303 __ fnclex(); | 281 __ fnclex(); |
304 | 282 |
305 // Remove the bailout id, return address and the double registers. | 283 // Remove the bailout id, return address and the double registers. |
306 __ add(esp, Immediate(kDoubleRegsSize + 2 * kPointerSize)); | 284 __ add(esp, Immediate(2 * kPointerSize)); |
307 | 285 |
308 // Compute a pointer to the unwinding limit in register ecx; that is | 286 // Compute a pointer to the unwinding limit in register ecx; that is |
309 // the first stack slot not part of the input frame. | 287 // the first stack slot not part of the input frame. |
310 __ mov(ecx, Operand(ebx, FrameDescription::frame_size_offset())); | 288 __ mov(ecx, Operand(ebx, FrameDescription::frame_size_offset())); |
311 __ add(ecx, esp); | 289 __ add(ecx, esp); |
312 | 290 |
313 // Unwind the stack down to - but not including - the unwinding | 291 // Unwind the stack down to - but not including - the unwinding |
314 // limit and copy the contents of the activation frame to the input | 292 // limit and copy the contents of the activation frame to the input |
315 // frame description. | 293 // frame description. |
316 __ lea(edx, Operand(ebx, FrameDescription::frame_content_offset())); | 294 __ lea(edx, Operand(ebx, FrameDescription::frame_content_offset())); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 __ sub(ecx, Immediate(sizeof(uint32_t))); | 343 __ sub(ecx, Immediate(sizeof(uint32_t))); |
366 __ push(Operand(ebx, ecx, times_1, FrameDescription::frame_content_offset())); | 344 __ push(Operand(ebx, ecx, times_1, FrameDescription::frame_content_offset())); |
367 __ bind(&inner_loop_header); | 345 __ bind(&inner_loop_header); |
368 __ test(ecx, ecx); | 346 __ test(ecx, ecx); |
369 __ j(not_zero, &inner_push_loop); | 347 __ j(not_zero, &inner_push_loop); |
370 __ add(eax, Immediate(kPointerSize)); | 348 __ add(eax, Immediate(kPointerSize)); |
371 __ bind(&outer_loop_header); | 349 __ bind(&outer_loop_header); |
372 __ cmp(eax, edx); | 350 __ cmp(eax, edx); |
373 __ j(below, &outer_push_loop); | 351 __ j(below, &outer_push_loop); |
374 | 352 |
375 // In case of a failed STUB, we have to restore the XMM registers. | |
376 for (int i = 0; i < XMMRegister::kMaxNumAllocatableRegisters; ++i) { | |
377 XMMRegister xmm_reg = XMMRegister::FromAllocationIndex(i); | |
378 int src_offset = i * kDoubleSize + double_regs_offset; | |
379 __ movsd(xmm_reg, Operand(ebx, src_offset)); | |
380 } | |
381 | |
382 // Push state, pc, and continuation from the last output frame. | 353 // Push state, pc, and continuation from the last output frame. |
383 __ push(Operand(ebx, FrameDescription::state_offset())); | 354 __ push(Operand(ebx, FrameDescription::state_offset())); |
384 __ push(Operand(ebx, FrameDescription::pc_offset())); | 355 __ push(Operand(ebx, FrameDescription::pc_offset())); |
385 __ push(Operand(ebx, FrameDescription::continuation_offset())); | 356 __ push(Operand(ebx, FrameDescription::continuation_offset())); |
386 | 357 |
387 | 358 |
388 // Push the registers from the last output frame. | 359 // Push the registers from the last output frame. |
389 for (int i = 0; i < kNumberOfRegisters; i++) { | 360 for (int i = 0; i < kNumberOfRegisters; i++) { |
390 int offset = (i * kPointerSize) + FrameDescription::registers_offset(); | 361 int offset = (i * kPointerSize) + FrameDescription::registers_offset(); |
391 __ push(Operand(ebx, offset)); | 362 __ push(Operand(ebx, offset)); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 // No out-of-line constant pool support. | 398 // No out-of-line constant pool support. |
428 UNREACHABLE(); | 399 UNREACHABLE(); |
429 } | 400 } |
430 | 401 |
431 | 402 |
432 #undef __ | 403 #undef __ |
433 | 404 |
434 | 405 |
435 } } // namespace v8::internal | 406 } } // namespace v8::internal |
436 | 407 |
437 #endif // V8_TARGET_ARCH_IA32 | 408 #endif // V8_TARGET_ARCH_X87 |
OLD | NEW |