| 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_X64 | 5 #if V8_TARGET_ARCH_X64 |
| 6 | 6 |
| 7 #include "src/codegen.h" | 7 #include "src/codegen.h" |
| 8 #include "src/ic/ic.h" | 8 #include "src/ic/ic.h" |
| 9 #include "src/ic/ic-compiler.h" | 9 #include "src/ic/ic-compiler.h" |
| 10 #include "src/ic/stub-cache.h" | 10 #include "src/ic/stub-cache.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 FieldOperand(map, Map::kBitFieldOffset), | 160 FieldOperand(map, Map::kBitFieldOffset), |
| 161 Immediate((1 << Map::kIsAccessCheckNeeded) | (1 << interceptor_bit))); | 161 Immediate((1 << Map::kIsAccessCheckNeeded) | (1 << interceptor_bit))); |
| 162 __ j(not_zero, slow); | 162 __ j(not_zero, slow); |
| 163 } | 163 } |
| 164 | 164 |
| 165 | 165 |
| 166 // Loads an indexed element from a fast case array. | 166 // Loads an indexed element from a fast case array. |
| 167 static void GenerateFastArrayLoad(MacroAssembler* masm, Register receiver, | 167 static void GenerateFastArrayLoad(MacroAssembler* masm, Register receiver, |
| 168 Register key, Register elements, | 168 Register key, Register elements, |
| 169 Register scratch, Register result, | 169 Register scratch, Register result, |
| 170 Label* slow, LanguageMode language_mode) { | 170 Label* slow) { |
| 171 // Register use: | 171 // Register use: |
| 172 // | 172 // |
| 173 // receiver - holds the receiver on entry. | 173 // receiver - holds the receiver on entry. |
| 174 // Unchanged unless 'result' is the same register. | 174 // Unchanged unless 'result' is the same register. |
| 175 // | 175 // |
| 176 // key - holds the smi key on entry. | 176 // key - holds the smi key on entry. |
| 177 // Unchanged unless 'result' is the same register. | 177 // Unchanged unless 'result' is the same register. |
| 178 // | 178 // |
| 179 // result - holds the result on exit if the load succeeded. | 179 // result - holds the result on exit if the load succeeded. |
| 180 // Allowed to be the the same as 'receiver' or 'key'. | 180 // Allowed to be the the same as 'receiver' or 'key'. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 __ j(below, slow); | 215 __ j(below, slow); |
| 216 __ testb(FieldOperand(scratch, Map::kBitFieldOffset), | 216 __ testb(FieldOperand(scratch, Map::kBitFieldOffset), |
| 217 Immediate((1 << Map::kIsAccessCheckNeeded) | | 217 Immediate((1 << Map::kIsAccessCheckNeeded) | |
| 218 (1 << Map::kHasIndexedInterceptor))); | 218 (1 << Map::kHasIndexedInterceptor))); |
| 219 __ j(not_zero, slow); | 219 __ j(not_zero, slow); |
| 220 __ CompareRoot(elements, Heap::kEmptyFixedArrayRootIndex); | 220 __ CompareRoot(elements, Heap::kEmptyFixedArrayRootIndex); |
| 221 __ j(not_equal, slow); | 221 __ j(not_equal, slow); |
| 222 __ jmp(&check_next_prototype); | 222 __ jmp(&check_next_prototype); |
| 223 | 223 |
| 224 __ bind(&absent); | 224 __ bind(&absent); |
| 225 if (is_strong(language_mode)) { | 225 __ LoadRoot(result, Heap::kUndefinedValueRootIndex); |
| 226 // Strong mode accesses must throw in this case, so call the runtime. | 226 __ jmp(&done); |
| 227 __ jmp(slow); | |
| 228 } else { | |
| 229 __ LoadRoot(result, Heap::kUndefinedValueRootIndex); | |
| 230 __ jmp(&done); | |
| 231 } | |
| 232 | 227 |
| 233 __ bind(&in_bounds); | 228 __ bind(&in_bounds); |
| 234 // Fast case: Do the load. | 229 // Fast case: Do the load. |
| 235 SmiIndex index = masm->SmiToIndex(scratch, key, kPointerSizeLog2); | 230 SmiIndex index = masm->SmiToIndex(scratch, key, kPointerSizeLog2); |
| 236 __ movp(scratch, FieldOperand(elements, index.reg, index.scale, | 231 __ movp(scratch, FieldOperand(elements, index.reg, index.scale, |
| 237 FixedArray::kHeaderSize)); | 232 FixedArray::kHeaderSize)); |
| 238 __ CompareRoot(scratch, Heap::kTheHoleValueRootIndex); | 233 __ CompareRoot(scratch, Heap::kTheHoleValueRootIndex); |
| 239 // In case the loaded value is the_hole we have to check the prototype chain. | 234 // In case the loaded value is the_hole we have to check the prototype chain. |
| 240 __ j(equal, &check_prototypes); | 235 __ j(equal, &check_prototypes); |
| 241 __ Move(result, scratch); | 236 __ Move(result, scratch); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 267 // Is the string internalized? We already know it's a string so a single | 262 // Is the string internalized? We already know it's a string so a single |
| 268 // bit test is enough. | 263 // bit test is enough. |
| 269 STATIC_ASSERT(kNotInternalizedTag != 0); | 264 STATIC_ASSERT(kNotInternalizedTag != 0); |
| 270 __ testb(FieldOperand(map, Map::kInstanceTypeOffset), | 265 __ testb(FieldOperand(map, Map::kInstanceTypeOffset), |
| 271 Immediate(kIsNotInternalizedMask)); | 266 Immediate(kIsNotInternalizedMask)); |
| 272 __ j(not_zero, not_unique); | 267 __ j(not_zero, not_unique); |
| 273 | 268 |
| 274 __ bind(&unique); | 269 __ bind(&unique); |
| 275 } | 270 } |
| 276 | 271 |
| 277 | 272 void KeyedLoadIC::GenerateMegamorphic(MacroAssembler* masm) { |
| 278 void KeyedLoadIC::GenerateMegamorphic(MacroAssembler* masm, | |
| 279 LanguageMode language_mode) { | |
| 280 // The return address is on the stack. | 273 // The return address is on the stack. |
| 281 Label slow, check_name, index_smi, index_name, property_array_property; | 274 Label slow, check_name, index_smi, index_name, property_array_property; |
| 282 Label probe_dictionary, check_number_dictionary; | 275 Label probe_dictionary, check_number_dictionary; |
| 283 | 276 |
| 284 Register receiver = LoadDescriptor::ReceiverRegister(); | 277 Register receiver = LoadDescriptor::ReceiverRegister(); |
| 285 Register key = LoadDescriptor::NameRegister(); | 278 Register key = LoadDescriptor::NameRegister(); |
| 286 DCHECK(receiver.is(rdx)); | 279 DCHECK(receiver.is(rdx)); |
| 287 DCHECK(key.is(rcx)); | 280 DCHECK(key.is(rcx)); |
| 288 | 281 |
| 289 // Check that the key is a smi. | 282 // Check that the key is a smi. |
| 290 __ JumpIfNotSmi(key, &check_name); | 283 __ JumpIfNotSmi(key, &check_name); |
| 291 __ bind(&index_smi); | 284 __ bind(&index_smi); |
| 292 // Now the key is known to be a smi. This place is also jumped to from below | 285 // Now the key is known to be a smi. This place is also jumped to from below |
| 293 // where a numeric string is converted to a smi. | 286 // where a numeric string is converted to a smi. |
| 294 | 287 |
| 295 GenerateKeyedLoadReceiverCheck(masm, receiver, rax, | 288 GenerateKeyedLoadReceiverCheck(masm, receiver, rax, |
| 296 Map::kHasIndexedInterceptor, &slow); | 289 Map::kHasIndexedInterceptor, &slow); |
| 297 | 290 |
| 298 // Check the receiver's map to see if it has fast elements. | 291 // Check the receiver's map to see if it has fast elements. |
| 299 __ CheckFastElements(rax, &check_number_dictionary); | 292 __ CheckFastElements(rax, &check_number_dictionary); |
| 300 | 293 |
| 301 GenerateFastArrayLoad(masm, receiver, key, rax, rbx, rax, &slow, | 294 GenerateFastArrayLoad(masm, receiver, key, rax, rbx, rax, &slow); |
| 302 language_mode); | |
| 303 Counters* counters = masm->isolate()->counters(); | 295 Counters* counters = masm->isolate()->counters(); |
| 304 __ IncrementCounter(counters->ic_keyed_load_generic_smi(), 1); | 296 __ IncrementCounter(counters->ic_keyed_load_generic_smi(), 1); |
| 305 __ ret(0); | 297 __ ret(0); |
| 306 | 298 |
| 307 __ bind(&check_number_dictionary); | 299 __ bind(&check_number_dictionary); |
| 308 __ SmiToInteger32(rbx, key); | 300 __ SmiToInteger32(rbx, key); |
| 309 __ movp(rax, FieldOperand(receiver, JSObject::kElementsOffset)); | 301 __ movp(rax, FieldOperand(receiver, JSObject::kElementsOffset)); |
| 310 | 302 |
| 311 // Check whether the elements is a number dictionary. | 303 // Check whether the elements is a number dictionary. |
| 312 // rbx: key as untagged int32 | 304 // rbx: key as untagged int32 |
| 313 // rax: elements | 305 // rax: elements |
| 314 __ CompareRoot(FieldOperand(rax, HeapObject::kMapOffset), | 306 __ CompareRoot(FieldOperand(rax, HeapObject::kMapOffset), |
| 315 Heap::kHashTableMapRootIndex); | 307 Heap::kHashTableMapRootIndex); |
| 316 __ j(not_equal, &slow); | 308 __ j(not_equal, &slow); |
| 317 __ LoadFromNumberDictionary(&slow, rax, key, rbx, r9, rdi, rax); | 309 __ LoadFromNumberDictionary(&slow, rax, key, rbx, r9, rdi, rax); |
| 318 __ ret(0); | 310 __ ret(0); |
| 319 | 311 |
| 320 __ bind(&slow); | 312 __ bind(&slow); |
| 321 // Slow case: Jump to runtime. | 313 // Slow case: Jump to runtime. |
| 322 __ IncrementCounter(counters->ic_keyed_load_generic_slow(), 1); | 314 __ IncrementCounter(counters->ic_keyed_load_generic_slow(), 1); |
| 323 KeyedLoadIC::GenerateRuntimeGetProperty(masm, language_mode); | 315 KeyedLoadIC::GenerateRuntimeGetProperty(masm); |
| 324 | 316 |
| 325 __ bind(&check_name); | 317 __ bind(&check_name); |
| 326 GenerateKeyNameCheck(masm, key, rax, rbx, &index_name, &slow); | 318 GenerateKeyNameCheck(masm, key, rax, rbx, &index_name, &slow); |
| 327 | 319 |
| 328 GenerateKeyedLoadReceiverCheck(masm, receiver, rax, Map::kHasNamedInterceptor, | 320 GenerateKeyedLoadReceiverCheck(masm, receiver, rax, Map::kHasNamedInterceptor, |
| 329 &slow); | 321 &slow); |
| 330 | 322 |
| 331 // If the receiver is a fast-case object, check the stub cache. Otherwise | 323 // If the receiver is a fast-case object, check the stub cache. Otherwise |
| 332 // probe the dictionary. | 324 // probe the dictionary. |
| 333 __ movp(rbx, FieldOperand(receiver, JSObject::kPropertiesOffset)); | 325 __ movp(rbx, FieldOperand(receiver, JSObject::kPropertiesOffset)); |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 KeyedStoreGenerateMegamorphicHelper(masm, &fast_object, &fast_double, &slow, | 611 KeyedStoreGenerateMegamorphicHelper(masm, &fast_object, &fast_double, &slow, |
| 620 kCheckMap, kDontIncrementLength); | 612 kCheckMap, kDontIncrementLength); |
| 621 KeyedStoreGenerateMegamorphicHelper(masm, &fast_object_grow, | 613 KeyedStoreGenerateMegamorphicHelper(masm, &fast_object_grow, |
| 622 &fast_double_grow, &slow, kDontCheckMap, | 614 &fast_double_grow, &slow, kDontCheckMap, |
| 623 kIncrementLength); | 615 kIncrementLength); |
| 624 | 616 |
| 625 __ bind(&miss); | 617 __ bind(&miss); |
| 626 GenerateMiss(masm); | 618 GenerateMiss(masm); |
| 627 } | 619 } |
| 628 | 620 |
| 629 | 621 void LoadIC::GenerateNormal(MacroAssembler* masm) { |
| 630 void LoadIC::GenerateNormal(MacroAssembler* masm, LanguageMode language_mode) { | |
| 631 Register dictionary = rax; | 622 Register dictionary = rax; |
| 632 DCHECK(!dictionary.is(LoadDescriptor::ReceiverRegister())); | 623 DCHECK(!dictionary.is(LoadDescriptor::ReceiverRegister())); |
| 633 DCHECK(!dictionary.is(LoadDescriptor::NameRegister())); | 624 DCHECK(!dictionary.is(LoadDescriptor::NameRegister())); |
| 634 | 625 |
| 635 Label slow; | 626 Label slow; |
| 636 | 627 |
| 637 __ movp(dictionary, FieldOperand(LoadDescriptor::ReceiverRegister(), | 628 __ movp(dictionary, FieldOperand(LoadDescriptor::ReceiverRegister(), |
| 638 JSObject::kPropertiesOffset)); | 629 JSObject::kPropertiesOffset)); |
| 639 GenerateDictionaryLoad(masm, &slow, dictionary, | 630 GenerateDictionaryLoad(masm, &slow, dictionary, |
| 640 LoadDescriptor::NameRegister(), rbx, rdi, rax); | 631 LoadDescriptor::NameRegister(), rbx, rdi, rax); |
| 641 __ ret(0); | 632 __ ret(0); |
| 642 | 633 |
| 643 // Dictionary load failed, go slow (but don't miss). | 634 // Dictionary load failed, go slow (but don't miss). |
| 644 __ bind(&slow); | 635 __ bind(&slow); |
| 645 LoadIC::GenerateRuntimeGetProperty(masm, language_mode); | 636 LoadIC::GenerateRuntimeGetProperty(masm); |
| 646 } | 637 } |
| 647 | 638 |
| 648 | 639 |
| 649 static void LoadIC_PushArgs(MacroAssembler* masm) { | 640 static void LoadIC_PushArgs(MacroAssembler* masm) { |
| 650 Register receiver = LoadDescriptor::ReceiverRegister(); | 641 Register receiver = LoadDescriptor::ReceiverRegister(); |
| 651 Register name = LoadDescriptor::NameRegister(); | 642 Register name = LoadDescriptor::NameRegister(); |
| 652 Register slot = LoadDescriptor::SlotRegister(); | 643 Register slot = LoadDescriptor::SlotRegister(); |
| 653 Register vector = LoadWithVectorDescriptor::VectorRegister(); | 644 Register vector = LoadWithVectorDescriptor::VectorRegister(); |
| 654 DCHECK(!rdi.is(receiver) && !rdi.is(name) && !rdi.is(slot) && | 645 DCHECK(!rdi.is(receiver) && !rdi.is(name) && !rdi.is(slot) && |
| 655 !rdi.is(vector)); | 646 !rdi.is(vector)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 668 | 659 |
| 669 Counters* counters = masm->isolate()->counters(); | 660 Counters* counters = masm->isolate()->counters(); |
| 670 __ IncrementCounter(counters->ic_load_miss(), 1); | 661 __ IncrementCounter(counters->ic_load_miss(), 1); |
| 671 | 662 |
| 672 LoadIC_PushArgs(masm); | 663 LoadIC_PushArgs(masm); |
| 673 | 664 |
| 674 // Perform tail call to the entry. | 665 // Perform tail call to the entry. |
| 675 __ TailCallRuntime(Runtime::kLoadIC_Miss); | 666 __ TailCallRuntime(Runtime::kLoadIC_Miss); |
| 676 } | 667 } |
| 677 | 668 |
| 678 | 669 void LoadIC::GenerateRuntimeGetProperty(MacroAssembler* masm) { |
| 679 void LoadIC::GenerateRuntimeGetProperty(MacroAssembler* masm, | |
| 680 LanguageMode language_mode) { | |
| 681 // The return address is on the stack. | 670 // The return address is on the stack. |
| 682 Register receiver = LoadDescriptor::ReceiverRegister(); | 671 Register receiver = LoadDescriptor::ReceiverRegister(); |
| 683 Register name = LoadDescriptor::NameRegister(); | 672 Register name = LoadDescriptor::NameRegister(); |
| 684 | 673 |
| 685 DCHECK(!rbx.is(receiver) && !rbx.is(name)); | 674 DCHECK(!rbx.is(receiver) && !rbx.is(name)); |
| 686 | 675 |
| 687 __ PopReturnAddressTo(rbx); | 676 __ PopReturnAddressTo(rbx); |
| 688 __ Push(receiver); | 677 __ Push(receiver); |
| 689 __ Push(name); | 678 __ Push(name); |
| 690 __ PushReturnAddressFrom(rbx); | 679 __ PushReturnAddressFrom(rbx); |
| 691 | 680 |
| 692 // Do tail-call to runtime routine. | 681 // Do tail-call to runtime routine. |
| 693 __ TailCallRuntime(is_strong(language_mode) ? Runtime::kGetPropertyStrong | 682 __ TailCallRuntime(Runtime::kGetProperty); |
| 694 : Runtime::kGetProperty); | |
| 695 } | 683 } |
| 696 | 684 |
| 697 | 685 |
| 698 void KeyedLoadIC::GenerateMiss(MacroAssembler* masm) { | 686 void KeyedLoadIC::GenerateMiss(MacroAssembler* masm) { |
| 699 // The return address is on the stack. | 687 // The return address is on the stack. |
| 700 Counters* counters = masm->isolate()->counters(); | 688 Counters* counters = masm->isolate()->counters(); |
| 701 __ IncrementCounter(counters->ic_keyed_load_miss(), 1); | 689 __ IncrementCounter(counters->ic_keyed_load_miss(), 1); |
| 702 | 690 |
| 703 LoadIC_PushArgs(masm); | 691 LoadIC_PushArgs(masm); |
| 704 | 692 |
| 705 // Perform tail call to the entry. | 693 // Perform tail call to the entry. |
| 706 __ TailCallRuntime(Runtime::kKeyedLoadIC_Miss); | 694 __ TailCallRuntime(Runtime::kKeyedLoadIC_Miss); |
| 707 } | 695 } |
| 708 | 696 |
| 709 | 697 void KeyedLoadIC::GenerateRuntimeGetProperty(MacroAssembler* masm) { |
| 710 void KeyedLoadIC::GenerateRuntimeGetProperty(MacroAssembler* masm, | |
| 711 LanguageMode language_mode) { | |
| 712 // The return address is on the stack. | 698 // The return address is on the stack. |
| 713 Register receiver = LoadDescriptor::ReceiverRegister(); | 699 Register receiver = LoadDescriptor::ReceiverRegister(); |
| 714 Register name = LoadDescriptor::NameRegister(); | 700 Register name = LoadDescriptor::NameRegister(); |
| 715 | 701 |
| 716 DCHECK(!rbx.is(receiver) && !rbx.is(name)); | 702 DCHECK(!rbx.is(receiver) && !rbx.is(name)); |
| 717 | 703 |
| 718 __ PopReturnAddressTo(rbx); | 704 __ PopReturnAddressTo(rbx); |
| 719 __ Push(receiver); | 705 __ Push(receiver); |
| 720 __ Push(name); | 706 __ Push(name); |
| 721 __ PushReturnAddressFrom(rbx); | 707 __ PushReturnAddressFrom(rbx); |
| 722 | 708 |
| 723 // Do tail-call to runtime routine. | 709 // Do tail-call to runtime routine. |
| 724 __ TailCallRuntime(is_strong(language_mode) ? Runtime::kKeyedGetPropertyStrong | 710 __ TailCallRuntime(Runtime::kKeyedGetProperty); |
| 725 : Runtime::kKeyedGetProperty); | |
| 726 } | 711 } |
| 727 | 712 |
| 728 | 713 |
| 729 void StoreIC::GenerateMegamorphic(MacroAssembler* masm) { | 714 void StoreIC::GenerateMegamorphic(MacroAssembler* masm) { |
| 730 // This shouldn't be called. | 715 // This shouldn't be called. |
| 731 __ int3(); | 716 __ int3(); |
| 732 } | 717 } |
| 733 | 718 |
| 734 | 719 |
| 735 static void StoreIC_PushArgs(MacroAssembler* masm) { | 720 static void StoreIC_PushArgs(MacroAssembler* masm) { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 Condition cc = | 845 Condition cc = |
| 861 (check == ENABLE_INLINED_SMI_CHECK) | 846 (check == ENABLE_INLINED_SMI_CHECK) |
| 862 ? (*jmp_address == Assembler::kJncShortOpcode ? not_zero : zero) | 847 ? (*jmp_address == Assembler::kJncShortOpcode ? not_zero : zero) |
| 863 : (*jmp_address == Assembler::kJnzShortOpcode ? not_carry : carry); | 848 : (*jmp_address == Assembler::kJnzShortOpcode ? not_carry : carry); |
| 864 *jmp_address = static_cast<byte>(Assembler::kJccShortPrefix | cc); | 849 *jmp_address = static_cast<byte>(Assembler::kJccShortPrefix | cc); |
| 865 } | 850 } |
| 866 } // namespace internal | 851 } // namespace internal |
| 867 } // namespace v8 | 852 } // namespace v8 |
| 868 | 853 |
| 869 #endif // V8_TARGET_ARCH_X64 | 854 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |