Index: src/x64/code-stubs-x64.cc |
diff --git a/src/x64/code-stubs-x64.cc b/src/x64/code-stubs-x64.cc |
index 9237a0a36496a813e7fff686798621bfaa39e6b4..2ae4d9f7ab01cc207a19685f96e6204fd8edc0df 100644 |
--- a/src/x64/code-stubs-x64.cc |
+++ b/src/x64/code-stubs-x64.cc |
@@ -3938,7 +3938,8 @@ void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
// Check for 1-byte or 2-byte string. |
__ bind(&flat_string); |
- STATIC_ASSERT(kAsciiStringTag != 0); |
+ STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); |
+ STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
__ testb(result_, Immediate(kStringEncodingMask)); |
__ j(not_zero, &ascii_string); |
@@ -4195,8 +4196,9 @@ void StringAddStub::Generate(MacroAssembler* masm) { |
Label non_ascii, allocated, ascii_data; |
__ movl(rcx, r8); |
__ and_(rcx, r9); |
- STATIC_ASSERT(kStringEncodingMask == kAsciiStringTag); |
- __ testl(rcx, Immediate(kAsciiStringTag)); |
+ STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); |
+ STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
+ __ testl(rcx, Immediate(kStringEncodingMask)); |
__ j(zero, &non_ascii); |
__ bind(&ascii_data); |
// Allocate an acsii cons string. |
@@ -4225,7 +4227,7 @@ void StringAddStub::Generate(MacroAssembler* masm) { |
__ cmpb(r8, Immediate(kAsciiStringTag | kAsciiDataHintTag)); |
__ j(equal, &ascii_data); |
// Allocate a two byte cons string. |
- __ AllocateConsString(rcx, rdi, no_reg, &string_add_runtime); |
+ __ AllocateTwoByteConsString(rcx, rdi, no_reg, &string_add_runtime); |
__ jmp(&allocated); |
// Handle creating a flat result. First check that both strings are not |
@@ -4254,10 +4256,11 @@ void StringAddStub::Generate(MacroAssembler* masm) { |
// r8: instance type of first string |
// r9: instance type of second string |
Label non_ascii_string_add_flat_result; |
- STATIC_ASSERT(kStringEncodingMask == kAsciiStringTag); |
- __ testl(r8, Immediate(kAsciiStringTag)); |
+ STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); |
+ STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
+ __ testl(r8, Immediate(kStringEncodingMask)); |
__ j(zero, &non_ascii_string_add_flat_result); |
- __ testl(r9, Immediate(kAsciiStringTag)); |
+ __ testl(r9, Immediate(kStringEncodingMask)); |
__ j(zero, &string_add_runtime); |
__ bind(&make_flat_ascii_string); |
@@ -4295,7 +4298,9 @@ void StringAddStub::Generate(MacroAssembler* masm) { |
// r8: instance type of first string |
// r9: instance type of first string |
__ bind(&non_ascii_string_add_flat_result); |
- __ and_(r9, Immediate(kAsciiStringTag)); |
+ STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); |
+ STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
+ __ and_(r9, Immediate(kStringEncodingMask)); |
__ j(not_zero, &string_add_runtime); |
// Both strings are two byte strings. As they are short they are both |
// flat. |
@@ -4639,9 +4644,6 @@ void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
void SubStringStub::Generate(MacroAssembler* masm) { |
Label runtime; |
- if (FLAG_string_slices) { |
- __ jmp(&runtime); |
- } |
// Stack frame on entry. |
// rsp[0]: return address |
// rsp[8]: to |
@@ -4707,7 +4709,82 @@ void SubStringStub::Generate(MacroAssembler* masm) { |
__ movzxbl(rbx, FieldOperand(rbx, Map::kInstanceTypeOffset)); |
__ Set(rcx, 2); |
- __ bind(&result_longer_than_two); |
+ if (FLAG_string_slices) { |
+ Label copy_routine; |
+ // If coming from the make_two_character_string path, the string |
+ // is too short to be sliced anyways. |
+ STATIC_ASSERT(2 < SlicedString::kMinLength); |
+ __ jmp(©_routine); |
+ __ bind(&result_longer_than_two); |
+ |
+ // rax: string |
+ // rbx: instance type |
+ // rcx: sub string length |
+ // rdx: from index (smi) |
+ Label allocate_slice, sliced_string, seq_string; |
+ __ cmpq(rcx, Immediate(SlicedString::kMinLength)); |
+ // Short slice. Copy instead of slicing. |
+ __ j(less, ©_routine); |
+ STATIC_ASSERT(kSeqStringTag == 0); |
+ __ testb(rbx, Immediate(kStringRepresentationMask)); |
+ __ j(zero, &seq_string, Label::kNear); |
+ STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
+ STATIC_ASSERT(kIsIndirectStringMask != 0); |
+ __ testb(rbx, Immediate(kIsIndirectStringMask)); |
+ // External string. Jump to runtime. |
+ __ j(zero, &runtime); |
+ |
+ __ testb(rbx, Immediate(kSlicedNotConsMask)); |
+ __ j(not_zero, &sliced_string, Label::kNear); |
+ // Cons string. Check whether it is flat, then fetch first part. |
+ __ CompareRoot(FieldOperand(rax, ConsString::kSecondOffset), |
+ Heap::kEmptyStringRootIndex); |
+ __ j(not_equal, &runtime); |
+ __ movq(rdi, FieldOperand(rax, ConsString::kFirstOffset)); |
+ __ jmp(&allocate_slice, Label::kNear); |
+ |
+ __ bind(&sliced_string); |
+ // Sliced string. Fetch parent and correct start index by offset. |
+ __ addq(rdx, FieldOperand(rax, SlicedString::kOffsetOffset)); |
+ __ movq(rdi, FieldOperand(rax, SlicedString::kParentOffset)); |
+ __ jmp(&allocate_slice, Label::kNear); |
+ |
+ __ bind(&seq_string); |
+ // Sequential string. Just move string to the right register. |
+ __ movq(rdi, rax); |
+ |
+ __ bind(&allocate_slice); |
+ // edi: underlying subject string |
+ // ebx: instance type of original subject string |
+ // edx: offset |
+ // ecx: length |
+ // Allocate new sliced string. At this point we do not reload the instance |
+ // type including the string encoding because we simply rely on the info |
+ // provided by the original string. It does not matter if the original |
+ // string's encoding is wrong because we always have to recheck encoding of |
+ // the newly created string's parent anyways due to externalized strings. |
+ Label two_byte_slice, set_slice_header; |
+ STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); |
+ STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
+ __ testb(rbx, Immediate(kStringEncodingMask)); |
+ __ j(zero, &two_byte_slice, Label::kNear); |
+ __ AllocateAsciiSlicedString(rax, rbx, no_reg, &runtime); |
+ __ jmp(&set_slice_header, Label::kNear); |
+ __ bind(&two_byte_slice); |
+ __ AllocateTwoByteSlicedString(rax, rbx, no_reg, &runtime); |
+ __ bind(&set_slice_header); |
+ __ movq(FieldOperand(rax, SlicedString::kOffsetOffset), rdx); |
+ __ Integer32ToSmi(rcx, rcx); |
+ __ movq(FieldOperand(rax, SlicedString::kLengthOffset), rcx); |
+ __ movq(FieldOperand(rax, SlicedString::kParentOffset), rdi); |
+ __ movq(FieldOperand(rax, SlicedString::kHashFieldOffset), |
+ Immediate(String::kEmptyHashField)); |
+ __ jmp(&return_rax); |
+ |
+ __ bind(©_routine); |
+ } else { |
+ __ bind(&result_longer_than_two); |
+ } |
// rax: string |
// rbx: instance type |