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_IA32 |
8 | 8 |
9 #include "codegen.h" | 9 #include "codegen.h" |
10 #include "deoptimizer.h" | 10 #include "deoptimizer.h" |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 if (!CpuFeatures::IsSupported(SSE2)) return; | |
213 for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) { | 212 for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) { |
214 double double_value = input_->GetDoubleRegister(i); | 213 double double_value = input_->GetDoubleRegister(i); |
215 output_frame->SetDoubleRegister(i, double_value); | 214 output_frame->SetDoubleRegister(i, double_value); |
216 } | 215 } |
217 } | 216 } |
218 | 217 |
219 | 218 |
220 bool Deoptimizer::HasAlignmentPadding(JSFunction* function) { | 219 bool Deoptimizer::HasAlignmentPadding(JSFunction* function) { |
221 int parameter_count = function->shared()->formal_parameter_count() + 1; | 220 int parameter_count = function->shared()->formal_parameter_count() + 1; |
222 unsigned input_frame_size = input_->GetFrameSize(); | 221 unsigned input_frame_size = input_->GetFrameSize(); |
223 unsigned alignment_state_offset = | 222 unsigned alignment_state_offset = |
224 input_frame_size - parameter_count * kPointerSize - | 223 input_frame_size - parameter_count * kPointerSize - |
225 StandardFrameConstants::kFixedFrameSize - | 224 StandardFrameConstants::kFixedFrameSize - |
226 kPointerSize; | 225 kPointerSize; |
227 ASSERT(JavaScriptFrameConstants::kDynamicAlignmentStateOffset == | 226 ASSERT(JavaScriptFrameConstants::kDynamicAlignmentStateOffset == |
228 JavaScriptFrameConstants::kLocal0Offset); | 227 JavaScriptFrameConstants::kLocal0Offset); |
229 int32_t alignment_state = input_->GetFrameSlot(alignment_state_offset); | 228 int32_t alignment_state = input_->GetFrameSlot(alignment_state_offset); |
230 return (alignment_state == kAlignmentPaddingPushed); | 229 return (alignment_state == kAlignmentPaddingPushed); |
231 } | 230 } |
232 | 231 |
233 | 232 |
234 Code* Deoptimizer::NotifyStubFailureBuiltin() { | |
235 Builtins::Name name = CpuFeatures::IsSupported(SSE2) ? | |
236 Builtins::kNotifyStubFailureSaveDoubles : Builtins::kNotifyStubFailure; | |
237 return isolate_->builtins()->builtin(name); | |
238 } | |
239 | |
240 | |
241 #define __ masm()-> | 233 #define __ masm()-> |
242 | 234 |
243 void Deoptimizer::EntryGenerator::Generate() { | 235 void Deoptimizer::EntryGenerator::Generate() { |
244 GeneratePrologue(); | 236 GeneratePrologue(); |
245 | 237 |
246 // Save all general purpose registers before messing with them. | 238 // Save all general purpose registers before messing with them. |
247 const int kNumberOfRegisters = Register::kNumRegisters; | 239 const int kNumberOfRegisters = Register::kNumRegisters; |
248 | 240 |
249 const int kDoubleRegsSize = kDoubleSize * | 241 const int kDoubleRegsSize = kDoubleSize * |
250 XMMRegister::kNumAllocatableRegisters; | 242 XMMRegister::kNumAllocatableRegisters; |
251 __ sub(esp, Immediate(kDoubleRegsSize)); | 243 __ sub(esp, Immediate(kDoubleRegsSize)); |
252 if (CpuFeatures::IsSupported(SSE2)) { | 244 for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) { |
253 CpuFeatureScope scope(masm(), SSE2); | 245 XMMRegister xmm_reg = XMMRegister::FromAllocationIndex(i); |
254 for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) { | 246 int offset = i * kDoubleSize; |
255 XMMRegister xmm_reg = XMMRegister::FromAllocationIndex(i); | 247 __ movsd(Operand(esp, offset), xmm_reg); |
256 int offset = i * kDoubleSize; | |
257 __ movsd(Operand(esp, offset), xmm_reg); | |
258 } | |
259 } | 248 } |
260 | 249 |
261 __ pushad(); | 250 __ pushad(); |
262 | 251 |
263 const int kSavedRegistersAreaSize = kNumberOfRegisters * kPointerSize + | 252 const int kSavedRegistersAreaSize = kNumberOfRegisters * kPointerSize + |
264 kDoubleRegsSize; | 253 kDoubleRegsSize; |
265 | 254 |
266 // Get the bailout id from the stack. | 255 // Get the bailout id from the stack. |
267 __ mov(ebx, Operand(esp, kSavedRegistersAreaSize)); | 256 __ mov(ebx, Operand(esp, kSavedRegistersAreaSize)); |
268 | 257 |
(...skipping 24 matching lines...) Expand all Loading... |
293 // frame descriptor pointer. | 282 // frame descriptor pointer. |
294 __ mov(ebx, Operand(eax, Deoptimizer::input_offset())); | 283 __ mov(ebx, Operand(eax, Deoptimizer::input_offset())); |
295 | 284 |
296 // Fill in the input registers. | 285 // Fill in the input registers. |
297 for (int i = kNumberOfRegisters - 1; i >= 0; i--) { | 286 for (int i = kNumberOfRegisters - 1; i >= 0; i--) { |
298 int offset = (i * kPointerSize) + FrameDescription::registers_offset(); | 287 int offset = (i * kPointerSize) + FrameDescription::registers_offset(); |
299 __ pop(Operand(ebx, offset)); | 288 __ pop(Operand(ebx, offset)); |
300 } | 289 } |
301 | 290 |
302 int double_regs_offset = FrameDescription::double_registers_offset(); | 291 int double_regs_offset = FrameDescription::double_registers_offset(); |
303 if (CpuFeatures::IsSupported(SSE2)) { | 292 // Fill in the double input registers. |
304 CpuFeatureScope scope(masm(), SSE2); | 293 for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) { |
305 // Fill in the double input registers. | 294 int dst_offset = i * kDoubleSize + double_regs_offset; |
306 for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) { | 295 int src_offset = i * kDoubleSize; |
307 int dst_offset = i * kDoubleSize + double_regs_offset; | 296 __ movsd(xmm0, Operand(esp, src_offset)); |
308 int src_offset = i * kDoubleSize; | 297 __ movsd(Operand(ebx, dst_offset), xmm0); |
309 __ movsd(xmm0, Operand(esp, src_offset)); | |
310 __ movsd(Operand(ebx, dst_offset), xmm0); | |
311 } | |
312 } | 298 } |
313 | 299 |
314 // Clear FPU all exceptions. | 300 // Clear FPU all exceptions. |
315 // TODO(ulan): Find out why the TOP register is not zero here in some cases, | 301 // TODO(ulan): Find out why the TOP register is not zero here in some cases, |
316 // and check that the generated code never deoptimizes with unbalanced stack. | 302 // and check that the generated code never deoptimizes with unbalanced stack. |
317 __ fnclex(); | 303 __ fnclex(); |
318 | 304 |
319 // Remove the bailout id, return address and the double registers. | 305 // Remove the bailout id, return address and the double registers. |
320 __ add(esp, Immediate(kDoubleRegsSize + 2 * kPointerSize)); | 306 __ add(esp, Immediate(kDoubleRegsSize + 2 * kPointerSize)); |
321 | 307 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 __ push(Operand(ebx, ecx, times_1, FrameDescription::frame_content_offset())); | 366 __ push(Operand(ebx, ecx, times_1, FrameDescription::frame_content_offset())); |
381 __ bind(&inner_loop_header); | 367 __ bind(&inner_loop_header); |
382 __ test(ecx, ecx); | 368 __ test(ecx, ecx); |
383 __ j(not_zero, &inner_push_loop); | 369 __ j(not_zero, &inner_push_loop); |
384 __ add(eax, Immediate(kPointerSize)); | 370 __ add(eax, Immediate(kPointerSize)); |
385 __ bind(&outer_loop_header); | 371 __ bind(&outer_loop_header); |
386 __ cmp(eax, edx); | 372 __ cmp(eax, edx); |
387 __ j(below, &outer_push_loop); | 373 __ j(below, &outer_push_loop); |
388 | 374 |
389 // In case of a failed STUB, we have to restore the XMM registers. | 375 // In case of a failed STUB, we have to restore the XMM registers. |
390 if (CpuFeatures::IsSupported(SSE2)) { | 376 for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) { |
391 CpuFeatureScope scope(masm(), SSE2); | 377 XMMRegister xmm_reg = XMMRegister::FromAllocationIndex(i); |
392 for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) { | 378 int src_offset = i * kDoubleSize + double_regs_offset; |
393 XMMRegister xmm_reg = XMMRegister::FromAllocationIndex(i); | 379 __ movsd(xmm_reg, Operand(ebx, src_offset)); |
394 int src_offset = i * kDoubleSize + double_regs_offset; | |
395 __ movsd(xmm_reg, Operand(ebx, src_offset)); | |
396 } | |
397 } | 380 } |
398 | 381 |
399 // Push state, pc, and continuation from the last output frame. | 382 // Push state, pc, and continuation from the last output frame. |
400 __ push(Operand(ebx, FrameDescription::state_offset())); | 383 __ push(Operand(ebx, FrameDescription::state_offset())); |
401 __ push(Operand(ebx, FrameDescription::pc_offset())); | 384 __ push(Operand(ebx, FrameDescription::pc_offset())); |
402 __ push(Operand(ebx, FrameDescription::continuation_offset())); | 385 __ push(Operand(ebx, FrameDescription::continuation_offset())); |
403 | 386 |
404 | 387 |
405 // Push the registers from the last output frame. | 388 // Push the registers from the last output frame. |
406 for (int i = 0; i < kNumberOfRegisters; i++) { | 389 for (int i = 0; i < kNumberOfRegisters; i++) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 UNREACHABLE(); | 428 UNREACHABLE(); |
446 } | 429 } |
447 | 430 |
448 | 431 |
449 #undef __ | 432 #undef __ |
450 | 433 |
451 | 434 |
452 } } // namespace v8::internal | 435 } } // namespace v8::internal |
453 | 436 |
454 #endif // V8_TARGET_ARCH_IA32 | 437 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |