| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 25 matching lines...) Expand all Loading... |
| 36 #include "regexp-macro-assembler.h" | 36 #include "regexp-macro-assembler.h" |
| 37 #include "runtime.h" | 37 #include "runtime.h" |
| 38 #include "stub-cache.h" | 38 #include "stub-cache.h" |
| 39 #include "codegen.h" | 39 #include "codegen.h" |
| 40 #include "runtime.h" | 40 #include "runtime.h" |
| 41 | 41 |
| 42 namespace v8 { | 42 namespace v8 { |
| 43 namespace internal { | 43 namespace internal { |
| 44 | 44 |
| 45 | 45 |
| 46 void FastNewClosureStub::InitializeInterfaceDescriptor( |
| 47 Isolate* isolate, |
| 48 CodeStubInterfaceDescriptor* descriptor) { |
| 49 static Register registers[] = { ebx }; |
| 50 descriptor->register_param_count_ = 1; |
| 51 descriptor->register_params_ = registers; |
| 52 descriptor->deoptimization_handler_ = |
| 53 Runtime::FunctionForId(Runtime::kNewClosureFromStubFailure)->entry; |
| 54 } |
| 55 |
| 56 |
| 46 void ToNumberStub::InitializeInterfaceDescriptor( | 57 void ToNumberStub::InitializeInterfaceDescriptor( |
| 47 Isolate* isolate, | 58 Isolate* isolate, |
| 48 CodeStubInterfaceDescriptor* descriptor) { | 59 CodeStubInterfaceDescriptor* descriptor) { |
| 49 static Register registers[] = { eax }; | 60 static Register registers[] = { eax }; |
| 50 descriptor->register_param_count_ = 1; | 61 descriptor->register_param_count_ = 1; |
| 51 descriptor->register_params_ = registers; | 62 descriptor->register_params_ = registers; |
| 52 descriptor->deoptimization_handler_ = NULL; | 63 descriptor->deoptimization_handler_ = NULL; |
| 53 } | 64 } |
| 54 | 65 |
| 55 | 66 |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 __ push(descriptor->register_params_[i]); | 303 __ push(descriptor->register_params_[i]); |
| 293 } | 304 } |
| 294 ExternalReference miss = descriptor->miss_handler(); | 305 ExternalReference miss = descriptor->miss_handler(); |
| 295 __ CallExternalReference(miss, descriptor->register_param_count_); | 306 __ CallExternalReference(miss, descriptor->register_param_count_); |
| 296 } | 307 } |
| 297 | 308 |
| 298 __ ret(0); | 309 __ ret(0); |
| 299 } | 310 } |
| 300 | 311 |
| 301 | 312 |
| 302 void FastNewClosureStub::Generate(MacroAssembler* masm) { | |
| 303 // Create a new closure from the given function info in new | |
| 304 // space. Set the context to the current context in esi. | |
| 305 Counters* counters = masm->isolate()->counters(); | |
| 306 | |
| 307 Label gc; | |
| 308 __ Allocate(JSFunction::kSize, eax, ebx, ecx, &gc, TAG_OBJECT); | |
| 309 | |
| 310 __ IncrementCounter(counters->fast_new_closure_total(), 1); | |
| 311 | |
| 312 // Get the function info from the stack. | |
| 313 __ mov(edx, Operand(esp, 1 * kPointerSize)); | |
| 314 | |
| 315 int map_index = Context::FunctionMapIndex(language_mode_, is_generator_); | |
| 316 | |
| 317 // Compute the function map in the current native context and set that | |
| 318 // as the map of the allocated object. | |
| 319 __ mov(ecx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); | |
| 320 __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); | |
| 321 __ mov(ebx, Operand(ecx, Context::SlotOffset(map_index))); | |
| 322 __ mov(FieldOperand(eax, JSObject::kMapOffset), ebx); | |
| 323 | |
| 324 // Initialize the rest of the function. We don't have to update the | |
| 325 // write barrier because the allocated object is in new space. | |
| 326 Factory* factory = masm->isolate()->factory(); | |
| 327 __ mov(ebx, Immediate(factory->empty_fixed_array())); | |
| 328 __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ebx); | |
| 329 __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); | |
| 330 __ mov(FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset), | |
| 331 Immediate(factory->the_hole_value())); | |
| 332 __ mov(FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset), edx); | |
| 333 __ mov(FieldOperand(eax, JSFunction::kContextOffset), esi); | |
| 334 __ mov(FieldOperand(eax, JSFunction::kLiteralsOffset), ebx); | |
| 335 | |
| 336 // Initialize the code pointer in the function to be the one | |
| 337 // found in the shared function info object. | |
| 338 // But first check if there is an optimized version for our context. | |
| 339 Label check_optimized; | |
| 340 Label install_unoptimized; | |
| 341 if (FLAG_cache_optimized_code) { | |
| 342 __ mov(ebx, FieldOperand(edx, SharedFunctionInfo::kOptimizedCodeMapOffset)); | |
| 343 __ test(ebx, ebx); | |
| 344 __ j(not_zero, &check_optimized, Label::kNear); | |
| 345 } | |
| 346 __ bind(&install_unoptimized); | |
| 347 __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), | |
| 348 Immediate(factory->undefined_value())); | |
| 349 __ mov(edx, FieldOperand(edx, SharedFunctionInfo::kCodeOffset)); | |
| 350 __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); | |
| 351 __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); | |
| 352 | |
| 353 // Return and remove the on-stack parameter. | |
| 354 __ ret(1 * kPointerSize); | |
| 355 | |
| 356 __ bind(&check_optimized); | |
| 357 | |
| 358 __ IncrementCounter(counters->fast_new_closure_try_optimized(), 1); | |
| 359 | |
| 360 // ecx holds native context, ebx points to fixed array of 3-element entries | |
| 361 // (native context, optimized code, literals). | |
| 362 // Map must never be empty, so check the first elements. | |
| 363 Label install_optimized; | |
| 364 // Speculatively move code object into edx. | |
| 365 __ mov(edx, FieldOperand(ebx, SharedFunctionInfo::kFirstCodeSlot)); | |
| 366 __ cmp(ecx, FieldOperand(ebx, SharedFunctionInfo::kFirstContextSlot)); | |
| 367 __ j(equal, &install_optimized); | |
| 368 | |
| 369 // Iterate through the rest of map backwards. edx holds an index as a Smi. | |
| 370 Label loop; | |
| 371 Label restore; | |
| 372 __ mov(edx, FieldOperand(ebx, FixedArray::kLengthOffset)); | |
| 373 __ bind(&loop); | |
| 374 // Do not double check first entry. | |
| 375 __ cmp(edx, Immediate(Smi::FromInt(SharedFunctionInfo::kSecondEntryIndex))); | |
| 376 __ j(equal, &restore); | |
| 377 __ sub(edx, Immediate(Smi::FromInt(SharedFunctionInfo::kEntryLength))); | |
| 378 __ cmp(ecx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 0)); | |
| 379 __ j(not_equal, &loop, Label::kNear); | |
| 380 // Hit: fetch the optimized code. | |
| 381 __ mov(edx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 1)); | |
| 382 | |
| 383 __ bind(&install_optimized); | |
| 384 __ IncrementCounter(counters->fast_new_closure_install_optimized(), 1); | |
| 385 | |
| 386 // TODO(fschneider): Idea: store proper code pointers in the optimized code | |
| 387 // map and either unmangle them on marking or do nothing as the whole map is | |
| 388 // discarded on major GC anyway. | |
| 389 __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); | |
| 390 __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); | |
| 391 | |
| 392 // Now link a function into a list of optimized functions. | |
| 393 __ mov(edx, ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST)); | |
| 394 | |
| 395 __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), edx); | |
| 396 // No need for write barrier as JSFunction (eax) is in the new space. | |
| 397 | |
| 398 __ mov(ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST), eax); | |
| 399 // Store JSFunction (eax) into edx before issuing write barrier as | |
| 400 // it clobbers all the registers passed. | |
| 401 __ mov(edx, eax); | |
| 402 __ RecordWriteContextSlot( | |
| 403 ecx, | |
| 404 Context::SlotOffset(Context::OPTIMIZED_FUNCTIONS_LIST), | |
| 405 edx, | |
| 406 ebx, | |
| 407 kDontSaveFPRegs); | |
| 408 | |
| 409 // Return and remove the on-stack parameter. | |
| 410 __ ret(1 * kPointerSize); | |
| 411 | |
| 412 __ bind(&restore); | |
| 413 // Restore SharedFunctionInfo into edx. | |
| 414 __ mov(edx, Operand(esp, 1 * kPointerSize)); | |
| 415 __ jmp(&install_unoptimized); | |
| 416 | |
| 417 // Create a new closure through the slower runtime call. | |
| 418 __ bind(&gc); | |
| 419 __ pop(ecx); // Temporarily remove return address. | |
| 420 __ pop(edx); | |
| 421 __ push(esi); | |
| 422 __ push(edx); | |
| 423 __ push(Immediate(factory->false_value())); | |
| 424 __ push(ecx); // Restore return address. | |
| 425 __ TailCallRuntime(Runtime::kNewClosure, 3, 1); | |
| 426 } | |
| 427 | |
| 428 | |
| 429 void FastNewContextStub::Generate(MacroAssembler* masm) { | 313 void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 430 // Try to allocate the context in new space. | 314 // Try to allocate the context in new space. |
| 431 Label gc; | 315 Label gc; |
| 432 int length = slots_ + Context::MIN_CONTEXT_SLOTS; | 316 int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 433 __ Allocate((length * kPointerSize) + FixedArray::kHeaderSize, | 317 __ Allocate((length * kPointerSize) + FixedArray::kHeaderSize, |
| 434 eax, ebx, ecx, &gc, TAG_OBJECT); | 318 eax, ebx, ecx, &gc, TAG_OBJECT); |
| 435 | 319 |
| 436 // Get the function from the stack. | 320 // Get the function from the stack. |
| 437 __ mov(ecx, Operand(esp, 1 * kPointerSize)); | 321 __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 438 | 322 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 Register scratch); | 490 Register scratch); |
| 607 | 491 |
| 608 // Takes the operands in edx and eax and loads them as integers in eax | 492 // Takes the operands in edx and eax and loads them as integers in eax |
| 609 // and ecx. | 493 // and ecx. |
| 610 static void LoadUnknownsAsIntegers(MacroAssembler* masm, | 494 static void LoadUnknownsAsIntegers(MacroAssembler* masm, |
| 611 bool use_sse3, | 495 bool use_sse3, |
| 612 BinaryOpIC::TypeInfo left_type, | 496 BinaryOpIC::TypeInfo left_type, |
| 613 BinaryOpIC::TypeInfo right_type, | 497 BinaryOpIC::TypeInfo right_type, |
| 614 Label* operand_conversion_failure); | 498 Label* operand_conversion_failure); |
| 615 | 499 |
| 616 // Assumes that operands are smis or heap numbers and loads them | |
| 617 // into xmm0 and xmm1. Operands are in edx and eax. | |
| 618 // Leaves operands unchanged. | |
| 619 static void LoadSSE2Operands(MacroAssembler* masm); | |
| 620 | |
| 621 // Test if operands are numbers (smi or HeapNumber objects), and load | 500 // Test if operands are numbers (smi or HeapNumber objects), and load |
| 622 // them into xmm0 and xmm1 if they are. Jump to label not_numbers if | 501 // them into xmm0 and xmm1 if they are. Jump to label not_numbers if |
| 623 // either operand is not a number. Operands are in edx and eax. | 502 // either operand is not a number. Operands are in edx and eax. |
| 624 // Leaves operands unchanged. | 503 // Leaves operands unchanged. |
| 625 static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers); | 504 static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers); |
| 626 | 505 |
| 627 // Similar to LoadSSE2Operands but assumes that both operands are smis. | 506 // Similar to LoadSSE2Operands but assumes that both operands are smis. |
| 628 // Expects operands in edx, eax. | 507 // Expects operands in edx, eax. |
| 629 static void LoadSSE2Smis(MacroAssembler* masm, Register scratch); | 508 static void LoadSSE2Smis(MacroAssembler* masm, Register scratch); |
| 630 | 509 |
| (...skipping 1823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2454 __ bind(&load_smi); | 2333 __ bind(&load_smi); |
| 2455 __ SmiUntag(number); | 2334 __ SmiUntag(number); |
| 2456 __ push(number); | 2335 __ push(number); |
| 2457 __ fild_s(Operand(esp, 0)); | 2336 __ fild_s(Operand(esp, 0)); |
| 2458 __ pop(number); | 2337 __ pop(number); |
| 2459 | 2338 |
| 2460 __ bind(&done); | 2339 __ bind(&done); |
| 2461 } | 2340 } |
| 2462 | 2341 |
| 2463 | 2342 |
| 2464 void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm) { | |
| 2465 Label load_smi_edx, load_eax, load_smi_eax, done; | |
| 2466 // Load operand in edx into xmm0. | |
| 2467 __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); | |
| 2468 __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); | |
| 2469 | |
| 2470 __ bind(&load_eax); | |
| 2471 // Load operand in eax into xmm1. | |
| 2472 __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); | |
| 2473 __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); | |
| 2474 __ jmp(&done, Label::kNear); | |
| 2475 | |
| 2476 __ bind(&load_smi_edx); | |
| 2477 __ SmiUntag(edx); // Untag smi before converting to float. | |
| 2478 __ cvtsi2sd(xmm0, edx); | |
| 2479 __ SmiTag(edx); // Retag smi for heap number overwriting test. | |
| 2480 __ jmp(&load_eax); | |
| 2481 | |
| 2482 __ bind(&load_smi_eax); | |
| 2483 __ SmiUntag(eax); // Untag smi before converting to float. | |
| 2484 __ cvtsi2sd(xmm1, eax); | |
| 2485 __ SmiTag(eax); // Retag smi for heap number overwriting test. | |
| 2486 | |
| 2487 __ bind(&done); | |
| 2488 } | |
| 2489 | |
| 2490 | |
| 2491 void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm, | 2343 void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm, |
| 2492 Label* not_numbers) { | 2344 Label* not_numbers) { |
| 2493 Label load_smi_edx, load_eax, load_smi_eax, load_float_eax, done; | 2345 Label load_smi_edx, load_eax, load_smi_eax, load_float_eax, done; |
| 2494 // Load operand in edx into xmm0, or branch to not_numbers. | 2346 // Load operand in edx into xmm0, or branch to not_numbers. |
| 2495 __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); | 2347 __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
| 2496 Factory* factory = masm->isolate()->factory(); | 2348 Factory* factory = masm->isolate()->factory(); |
| 2497 __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map()); | 2349 __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map()); |
| 2498 __ j(not_equal, not_numbers); // Argument in edx is not a number. | 2350 __ j(not_equal, not_numbers); // Argument in edx is not a number. |
| 2499 __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); | 2351 __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2500 __ bind(&load_eax); | 2352 __ bind(&load_eax); |
| (...skipping 5213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7714 __ bind(&fast_elements_case); | 7566 __ bind(&fast_elements_case); |
| 7715 GenerateCase(masm, FAST_ELEMENTS); | 7567 GenerateCase(masm, FAST_ELEMENTS); |
| 7716 } | 7568 } |
| 7717 | 7569 |
| 7718 | 7570 |
| 7719 #undef __ | 7571 #undef __ |
| 7720 | 7572 |
| 7721 } } // namespace v8::internal | 7573 } } // namespace v8::internal |
| 7722 | 7574 |
| 7723 #endif // V8_TARGET_ARCH_IA32 | 7575 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |