OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 3762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3773 } | 3773 } |
3774 | 3774 |
3775 | 3775 |
3776 // ------------------------------------------------------------------------- | 3776 // ------------------------------------------------------------------------- |
3777 // StringCharCodeAtGenerator | 3777 // StringCharCodeAtGenerator |
3778 | 3778 |
3779 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { | 3779 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
3780 Label flat_string; | 3780 Label flat_string; |
3781 Label ascii_string; | 3781 Label ascii_string; |
3782 Label got_char_code; | 3782 Label got_char_code; |
3783 Label sliced_string; | |
3783 | 3784 |
3784 // If the receiver is a smi trigger the non-string case. | 3785 // If the receiver is a smi trigger the non-string case. |
3785 __ JumpIfSmi(object_, receiver_not_string_); | 3786 __ JumpIfSmi(object_, receiver_not_string_); |
3786 | 3787 |
3787 // Fetch the instance type of the receiver into result register. | 3788 // Fetch the instance type of the receiver into result register. |
3788 __ movq(result_, FieldOperand(object_, HeapObject::kMapOffset)); | 3789 __ movq(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
3789 __ movzxbl(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); | 3790 __ movzxbl(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
3790 // If the receiver is not a string trigger the non-string case. | 3791 // If the receiver is not a string trigger the non-string case. |
3791 __ testb(result_, Immediate(kIsNotStringMask)); | 3792 __ testb(result_, Immediate(kIsNotStringMask)); |
3792 __ j(not_zero, receiver_not_string_); | 3793 __ j(not_zero, receiver_not_string_); |
3793 | 3794 |
3794 // If the index is non-smi trigger the non-smi case. | 3795 // If the index is non-smi trigger the non-smi case. |
3795 __ JumpIfNotSmi(index_, &index_not_smi_); | 3796 __ JumpIfNotSmi(index_, &index_not_smi_); |
3796 | 3797 |
3797 // Put smi-tagged index into scratch register. | 3798 // Put smi-tagged index into scratch register. |
3798 __ movq(scratch_, index_); | 3799 __ movq(scratch_, index_); |
3799 __ bind(&got_smi_index_); | 3800 __ bind(&got_smi_index_); |
3800 | 3801 |
3801 // Check for index out of range. | 3802 // Check for index out of range. |
3802 __ SmiCompare(scratch_, FieldOperand(object_, String::kLengthOffset)); | 3803 __ SmiCompare(scratch_, FieldOperand(object_, String::kLengthOffset)); |
3803 __ j(above_equal, index_out_of_range_); | 3804 __ j(above_equal, index_out_of_range_); |
3804 | 3805 |
3805 // We need special handling for non-flat strings. | 3806 // We need special handling for non-flat strings. |
3806 STATIC_ASSERT(kSeqStringTag == 0); | 3807 STATIC_ASSERT(kSeqStringTag == 0); |
3807 __ testb(result_, Immediate(kStringRepresentationMask)); | 3808 __ testb(result_, Immediate(kStringRepresentationMask)); |
3808 __ j(zero, &flat_string); | 3809 __ j(zero, &flat_string); |
3809 | 3810 |
3810 // Handle non-flat strings. | 3811 // Handle non-flat strings. |
3811 __ testb(result_, Immediate(kIsConsStringMask)); | 3812 __ and_(result_, Immediate(kStringRepresentationMask)); |
3812 __ j(zero, &call_runtime_); | 3813 __ cmpb(result_, Immediate(kSlicedStringTag)); |
3814 __ j(equal, &sliced_string); | |
3815 __ cmpb(result_, Immediate(kExternalStringTag)); | |
3816 __ j(equal, &call_runtime_); | |
3813 | 3817 |
3814 // ConsString. | 3818 // ConsString. |
3815 // Check whether the right hand side is the empty string (i.e. if | 3819 // Check whether the right hand side is the empty string (i.e. if |
3816 // this is really a flat string in a cons string). If that is not | 3820 // this is really a flat string in a cons string). If that is not |
3817 // the case we would rather go to the runtime system now to flatten | 3821 // the case we would rather go to the runtime system now to flatten |
3818 // the string. | 3822 // the string. |
3819 __ CompareRoot(FieldOperand(object_, ConsString::kSecondOffset), | 3823 __ CompareRoot(FieldOperand(object_, ConsString::kSecondOffset), |
3820 Heap::kEmptyStringRootIndex); | 3824 Heap::kEmptyStringRootIndex); |
3821 __ j(not_equal, &call_runtime_); | 3825 __ j(not_equal, &call_runtime_); |
3822 // Get the first of the two strings and load its instance type. | 3826 // Get the first of the two strings and load its instance type. |
3823 __ movq(object_, FieldOperand(object_, ConsString::kFirstOffset)); | 3827 __ movq(object_, FieldOperand(object_, ConsString::kFirstOffset)); |
3824 __ movq(result_, FieldOperand(object_, HeapObject::kMapOffset)); | 3828 __ movq(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
3825 __ movzxbl(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); | 3829 __ movzxbl(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
3826 // If the first cons component is also non-flat, then go to runtime. | 3830 // If the first cons component is also non-flat, then go to runtime. |
3827 STATIC_ASSERT(kSeqStringTag == 0); | 3831 STATIC_ASSERT(kSeqStringTag == 0); |
3828 __ testb(result_, Immediate(kStringRepresentationMask)); | 3832 __ testb(result_, Immediate(kStringRepresentationMask)); |
3829 __ j(not_zero, &call_runtime_); | 3833 __ j(not_zero, &call_runtime_); |
3834 __ jmp(&flat_string); | |
3835 | |
3836 // SlicedString, unpack and add offset. | |
3837 __ bind(&sliced_string); | |
3838 __ addq(scratch_, FieldOperand(object_, SlicedString::kOffsetOffset)); | |
3839 __ movq(object_, FieldOperand(object_, SlicedString::kParentOffset)); | |
3840 __ movq(result_, FieldOperand(object_, HeapObject::kMapOffset)); | |
3841 __ movzxbl(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); | |
3830 | 3842 |
3831 // Check for 1-byte or 2-byte string. | 3843 // Check for 1-byte or 2-byte string. |
3832 __ bind(&flat_string); | 3844 __ bind(&flat_string); |
3833 STATIC_ASSERT(kAsciiStringTag != 0); | 3845 STATIC_ASSERT(kAsciiStringTag != 0); |
3834 __ testb(result_, Immediate(kStringEncodingMask)); | 3846 __ testb(result_, Immediate(kStringEncodingMask)); |
3835 __ j(not_zero, &ascii_string); | 3847 __ j(not_zero, &ascii_string); |
3836 | 3848 |
3837 // 2-byte string. | 3849 // 2-byte string. |
3838 // Load the 2-byte character code into the result register. | 3850 // Load the 2-byte character code into the result register. |
3839 __ SmiToInteger32(scratch_, scratch_); | 3851 __ SmiToInteger32(scratch_, scratch_); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4130 __ bind(&string_add_flat_result); | 4142 __ bind(&string_add_flat_result); |
4131 __ SmiToInteger32(rbx, rbx); | 4143 __ SmiToInteger32(rbx, rbx); |
4132 __ movl(rcx, r8); | 4144 __ movl(rcx, r8); |
4133 __ and_(rcx, Immediate(kStringRepresentationMask)); | 4145 __ and_(rcx, Immediate(kStringRepresentationMask)); |
4134 __ cmpl(rcx, Immediate(kExternalStringTag)); | 4146 __ cmpl(rcx, Immediate(kExternalStringTag)); |
4135 __ j(equal, &string_add_runtime); | 4147 __ j(equal, &string_add_runtime); |
4136 __ movl(rcx, r9); | 4148 __ movl(rcx, r9); |
4137 __ and_(rcx, Immediate(kStringRepresentationMask)); | 4149 __ and_(rcx, Immediate(kStringRepresentationMask)); |
4138 __ cmpl(rcx, Immediate(kExternalStringTag)); | 4150 __ cmpl(rcx, Immediate(kExternalStringTag)); |
4139 __ j(equal, &string_add_runtime); | 4151 __ j(equal, &string_add_runtime); |
4152 // We cannot encounter sliced strings here since: | |
4153 STATIC_ASSERT(SlicedString::kMinLength >= String::kMinNonFlatLength); | |
4140 // Now check if both strings are ascii strings. | 4154 // Now check if both strings are ascii strings. |
4141 // rax: first string | 4155 // rax: first string |
4142 // rbx: length of resulting flat string | 4156 // rbx: length of resulting flat string |
4143 // rdx: second string | 4157 // rdx: second string |
4144 // r8: instance type of first string | 4158 // r8: instance type of first string |
4145 // r9: instance type of second string | 4159 // r9: instance type of second string |
4146 Label non_ascii_string_add_flat_result; | 4160 Label non_ascii_string_add_flat_result; |
4147 STATIC_ASSERT(kStringEncodingMask == kAsciiStringTag); | 4161 STATIC_ASSERT(kStringEncodingMask == kAsciiStringTag); |
4148 __ testl(r8, Immediate(kAsciiStringTag)); | 4162 __ testl(r8, Immediate(kAsciiStringTag)); |
4149 __ j(zero, &non_ascii_string_add_flat_result); | 4163 __ j(zero, &non_ascii_string_add_flat_result); |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4521 | 4535 |
4522 // if (hash == 0) hash = 27; | 4536 // if (hash == 0) hash = 27; |
4523 Label hash_not_zero; | 4537 Label hash_not_zero; |
4524 __ j(not_zero, &hash_not_zero); | 4538 __ j(not_zero, &hash_not_zero); |
4525 __ Set(hash, 27); | 4539 __ Set(hash, 27); |
4526 __ bind(&hash_not_zero); | 4540 __ bind(&hash_not_zero); |
4527 } | 4541 } |
4528 | 4542 |
4529 void SubStringStub::Generate(MacroAssembler* masm) { | 4543 void SubStringStub::Generate(MacroAssembler* masm) { |
4530 Label runtime; | 4544 Label runtime; |
4531 | 4545 |
Yang
2011/07/27 11:51:58
Do not create string slice unless experimental fla
| |
4546 if (FLAG_string_slices) { | |
4547 __ jmp(&runtime); | |
4548 } | |
4532 // Stack frame on entry. | 4549 // Stack frame on entry. |
4533 // rsp[0]: return address | 4550 // rsp[0]: return address |
4534 // rsp[8]: to | 4551 // rsp[8]: to |
4535 // rsp[16]: from | 4552 // rsp[16]: from |
4536 // rsp[24]: string | 4553 // rsp[24]: string |
4537 | 4554 |
4538 const int kToOffset = 1 * kPointerSize; | 4555 const int kToOffset = 1 * kPointerSize; |
4539 const int kFromOffset = kToOffset + kPointerSize; | 4556 const int kFromOffset = kToOffset + kPointerSize; |
4540 const int kStringOffset = kFromOffset + kPointerSize; | 4557 const int kStringOffset = kFromOffset + kPointerSize; |
4541 const int kArgumentsSize = (kStringOffset + kPointerSize) - kToOffset; | 4558 const int kArgumentsSize = (kStringOffset + kPointerSize) - kToOffset; |
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5283 __ Drop(1); | 5300 __ Drop(1); |
5284 __ ret(2 * kPointerSize); | 5301 __ ret(2 * kPointerSize); |
5285 } | 5302 } |
5286 | 5303 |
5287 | 5304 |
5288 #undef __ | 5305 #undef __ |
5289 | 5306 |
5290 } } // namespace v8::internal | 5307 } } // namespace v8::internal |
5291 | 5308 |
5292 #endif // V8_TARGET_ARCH_X64 | 5309 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |