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 4722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4733 // If result is not supposed to be flat, allocate a cons string object. If | 4733 // If result is not supposed to be flat, allocate a cons string object. If |
4734 // both strings are ASCII the result is an ASCII cons string. | 4734 // both strings are ASCII the result is an ASCII cons string. |
4735 // rax: first string | 4735 // rax: first string |
4736 // rbx: length of resulting flat string | 4736 // rbx: length of resulting flat string |
4737 // rdx: second string | 4737 // rdx: second string |
4738 // r8: instance type of first string | 4738 // r8: instance type of first string |
4739 // r9: instance type of second string | 4739 // r9: instance type of second string |
4740 Label non_ascii, allocated, ascii_data; | 4740 Label non_ascii, allocated, ascii_data; |
4741 __ movl(rcx, r8); | 4741 __ movl(rcx, r8); |
4742 __ and_(rcx, r9); | 4742 __ and_(rcx, r9); |
4743 STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); | 4743 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
4744 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); | 4744 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
4745 __ testl(rcx, Immediate(kStringEncodingMask)); | 4745 __ testl(rcx, Immediate(kStringEncodingMask)); |
4746 __ j(zero, &non_ascii); | 4746 __ j(zero, &non_ascii); |
4747 __ bind(&ascii_data); | 4747 __ bind(&ascii_data); |
4748 // Allocate an ASCII cons string. | 4748 // Allocate an ASCII cons string. |
4749 __ AllocateAsciiConsString(rcx, rdi, no_reg, &call_runtime); | 4749 __ AllocateAsciiConsString(rcx, rdi, no_reg, &call_runtime); |
4750 __ bind(&allocated); | 4750 __ bind(&allocated); |
4751 // Fill the fields of the cons string. | 4751 // Fill the fields of the cons string. |
4752 __ movq(FieldOperand(rcx, ConsString::kLengthOffset), rbx); | 4752 __ movq(FieldOperand(rcx, ConsString::kLengthOffset), rbx); |
4753 __ movq(FieldOperand(rcx, ConsString::kHashFieldOffset), | 4753 __ movq(FieldOperand(rcx, ConsString::kHashFieldOffset), |
4754 Immediate(String::kEmptyHashField)); | 4754 Immediate(String::kEmptyHashField)); |
4755 __ movq(FieldOperand(rcx, ConsString::kFirstOffset), rax); | 4755 __ movq(FieldOperand(rcx, ConsString::kFirstOffset), rax); |
4756 __ movq(FieldOperand(rcx, ConsString::kSecondOffset), rdx); | 4756 __ movq(FieldOperand(rcx, ConsString::kSecondOffset), rdx); |
4757 __ movq(rax, rcx); | 4757 __ movq(rax, rcx); |
4758 __ IncrementCounter(counters->string_add_native(), 1); | 4758 __ IncrementCounter(counters->string_add_native(), 1); |
4759 __ ret(2 * kPointerSize); | 4759 __ ret(2 * kPointerSize); |
4760 __ bind(&non_ascii); | 4760 __ bind(&non_ascii); |
4761 // At least one of the strings is two-byte. Check whether it happens | 4761 // At least one of the strings is two-byte. Check whether it happens |
4762 // to contain only ASCII characters. | 4762 // to contain only ASCII characters. |
4763 // rcx: first instance type AND second instance type. | 4763 // rcx: first instance type AND second instance type. |
4764 // r8: first instance type. | 4764 // r8: first instance type. |
4765 // r9: second instance type. | 4765 // r9: second instance type. |
4766 __ testb(rcx, Immediate(kAsciiDataHintMask)); | 4766 __ testb(rcx, Immediate(kAsciiDataHintMask)); |
4767 __ j(not_zero, &ascii_data); | 4767 __ j(not_zero, &ascii_data); |
4768 __ xor_(r8, r9); | 4768 __ xor_(r8, r9); |
4769 STATIC_ASSERT(kAsciiStringTag != 0 && kAsciiDataHintTag != 0); | 4769 STATIC_ASSERT(kOneByteStringTag != 0 && kAsciiDataHintTag != 0); |
4770 __ andb(r8, Immediate(kAsciiStringTag | kAsciiDataHintTag)); | 4770 __ andb(r8, Immediate(kOneByteStringTag | kAsciiDataHintTag)); |
4771 __ cmpb(r8, Immediate(kAsciiStringTag | kAsciiDataHintTag)); | 4771 __ cmpb(r8, Immediate(kOneByteStringTag | kAsciiDataHintTag)); |
4772 __ j(equal, &ascii_data); | 4772 __ j(equal, &ascii_data); |
4773 // Allocate a two byte cons string. | 4773 // Allocate a two byte cons string. |
4774 __ AllocateTwoByteConsString(rcx, rdi, no_reg, &call_runtime); | 4774 __ AllocateTwoByteConsString(rcx, rdi, no_reg, &call_runtime); |
4775 __ jmp(&allocated); | 4775 __ jmp(&allocated); |
4776 | 4776 |
4777 // We cannot encounter sliced strings or cons strings here since: | 4777 // We cannot encounter sliced strings or cons strings here since: |
4778 STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); | 4778 STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); |
4779 // Handle creating a flat result from either external or sequential strings. | 4779 // Handle creating a flat result from either external or sequential strings. |
4780 // Locate the first characters' locations. | 4780 // Locate the first characters' locations. |
4781 // rax: first string | 4781 // rax: first string |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5281 // is too short to be sliced anyways. | 5281 // is too short to be sliced anyways. |
5282 __ cmpq(rcx, Immediate(SlicedString::kMinLength)); | 5282 __ cmpq(rcx, Immediate(SlicedString::kMinLength)); |
5283 // Short slice. Copy instead of slicing. | 5283 // Short slice. Copy instead of slicing. |
5284 __ j(less, ©_routine); | 5284 __ j(less, ©_routine); |
5285 // Allocate new sliced string. At this point we do not reload the instance | 5285 // Allocate new sliced string. At this point we do not reload the instance |
5286 // type including the string encoding because we simply rely on the info | 5286 // type including the string encoding because we simply rely on the info |
5287 // provided by the original string. It does not matter if the original | 5287 // provided by the original string. It does not matter if the original |
5288 // string's encoding is wrong because we always have to recheck encoding of | 5288 // string's encoding is wrong because we always have to recheck encoding of |
5289 // the newly created string's parent anyways due to externalized strings. | 5289 // the newly created string's parent anyways due to externalized strings. |
5290 Label two_byte_slice, set_slice_header; | 5290 Label two_byte_slice, set_slice_header; |
5291 STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); | 5291 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
5292 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); | 5292 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
5293 __ testb(rbx, Immediate(kStringEncodingMask)); | 5293 __ testb(rbx, Immediate(kStringEncodingMask)); |
5294 __ j(zero, &two_byte_slice, Label::kNear); | 5294 __ j(zero, &two_byte_slice, Label::kNear); |
5295 __ AllocateAsciiSlicedString(rax, rbx, r14, &runtime); | 5295 __ AllocateAsciiSlicedString(rax, rbx, r14, &runtime); |
5296 __ jmp(&set_slice_header, Label::kNear); | 5296 __ jmp(&set_slice_header, Label::kNear); |
5297 __ bind(&two_byte_slice); | 5297 __ bind(&two_byte_slice); |
5298 __ AllocateTwoByteSlicedString(rax, rbx, r14, &runtime); | 5298 __ AllocateTwoByteSlicedString(rax, rbx, r14, &runtime); |
5299 __ bind(&set_slice_header); | 5299 __ bind(&set_slice_header); |
5300 __ Integer32ToSmi(rcx, rcx); | 5300 __ Integer32ToSmi(rcx, rcx); |
5301 __ movq(FieldOperand(rax, SlicedString::kLengthOffset), rcx); | 5301 __ movq(FieldOperand(rax, SlicedString::kLengthOffset), rcx); |
(...skipping 23 matching lines...) Expand all Loading... |
5325 // Rule out short external strings. | 5325 // Rule out short external strings. |
5326 STATIC_CHECK(kShortExternalStringTag != 0); | 5326 STATIC_CHECK(kShortExternalStringTag != 0); |
5327 __ testb(rbx, Immediate(kShortExternalStringMask)); | 5327 __ testb(rbx, Immediate(kShortExternalStringMask)); |
5328 __ j(not_zero, &runtime); | 5328 __ j(not_zero, &runtime); |
5329 __ movq(rdi, FieldOperand(rdi, ExternalString::kResourceDataOffset)); | 5329 __ movq(rdi, FieldOperand(rdi, ExternalString::kResourceDataOffset)); |
5330 // Move the pointer so that offset-wise, it looks like a sequential string. | 5330 // Move the pointer so that offset-wise, it looks like a sequential string. |
5331 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqAsciiString::kHeaderSize); | 5331 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqAsciiString::kHeaderSize); |
5332 __ subq(rdi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); | 5332 __ subq(rdi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
5333 | 5333 |
5334 __ bind(&sequential_string); | 5334 __ bind(&sequential_string); |
5335 STATIC_ASSERT((kAsciiStringTag & kStringEncodingMask) != 0); | 5335 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
5336 __ testb(rbx, Immediate(kStringEncodingMask)); | 5336 __ testb(rbx, Immediate(kStringEncodingMask)); |
5337 __ j(zero, &two_byte_sequential); | 5337 __ j(zero, &two_byte_sequential); |
5338 | 5338 |
5339 // Allocate the result. | 5339 // Allocate the result. |
5340 __ AllocateAsciiString(rax, rcx, r11, r14, r15, &runtime); | 5340 __ AllocateAsciiString(rax, rcx, r11, r14, r15, &runtime); |
5341 | 5341 |
5342 // rax: result string | 5342 // rax: result string |
5343 // rcx: result string length | 5343 // rcx: result string length |
5344 __ movq(r14, rsi); // esi used by following code. | 5344 __ movq(r14, rsi); // esi used by following code. |
5345 { // Locate character of sub string start. | 5345 { // Locate character of sub string start. |
(...skipping 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6499 #endif | 6499 #endif |
6500 | 6500 |
6501 __ Ret(); | 6501 __ Ret(); |
6502 } | 6502 } |
6503 | 6503 |
6504 #undef __ | 6504 #undef __ |
6505 | 6505 |
6506 } } // namespace v8::internal | 6506 } } // namespace v8::internal |
6507 | 6507 |
6508 #endif // V8_TARGET_ARCH_X64 | 6508 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |