Chromium Code Reviews| Index: src/ia32/code-stubs-ia32.cc |
| diff --git a/src/ia32/code-stubs-ia32.cc b/src/ia32/code-stubs-ia32.cc |
| index 3a33c9e6f91c53979a41cbfbda043837ddd6f455..00dc4cb45bec816ea74ab31aaf3a5302342b66ad 100644 |
| --- a/src/ia32/code-stubs-ia32.cc |
| +++ b/src/ia32/code-stubs-ia32.cc |
| @@ -3387,6 +3387,11 @@ void RegExpExecStub::Generate(MacroAssembler* masm) { |
| __ cmp(edx, Operand(eax)); |
| __ j(greater, &runtime); |
| + // Reset offset for possibly sliced string. This also serves as indicator |
| + // whether the subject string is a sliced string. 0 is not suitable for this |
| + // purpose because a slice can start at offset 0 but have a shorter length. |
| +#define NOT_SLICED -1 |
|
Vitaly Repeshko
2011/08/12 19:01:00
Ugh, use a constant instead.
|
| + __ Set(edi, Immediate(NOT_SLICED)); |
| // ecx: RegExp data (FixedArray) |
| // Check the representation and encoding of the subject string. |
| Label seq_ascii_string, seq_two_byte_string, check_code; |
| @@ -3399,30 +3404,41 @@ void RegExpExecStub::Generate(MacroAssembler* masm) { |
| STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
| __ j(zero, &seq_two_byte_string); |
| // Any other flat string must be a flat ascii string. |
| - __ test(Operand(ebx), |
| + __ and_(Operand(ebx), |
| Immediate(kIsNotStringMask | kStringRepresentationMask)); |
| __ j(zero, &seq_ascii_string); |
| - // Check for flat cons string. |
| + // Check for flat cons string or truncated sliced string. |
|
Vitaly Repeshko
2011/08/12 19:01:00
Update the comment.
|
| // A flat cons string is a cons string where the second part is the empty |
| // string. In that case the subject string is just the first part of the cons |
| // string. Also in this case the first part of the cons string is known to be |
| // a sequential string or an external string. |
| - STATIC_ASSERT(kExternalStringTag != 0); |
| - STATIC_ASSERT((kConsStringTag & kExternalStringTag) == 0); |
| - __ test(Operand(ebx), |
| - Immediate(kIsNotStringMask | kExternalStringTag)); |
| - __ j(not_zero, &runtime); |
| - // String is a cons string. |
| - __ mov(edx, FieldOperand(eax, ConsString::kSecondOffset)); |
| - __ cmp(Operand(edx), factory->empty_string()); |
| + // A truncated sliced string has the offset 0 and the same length as the |
| + // parent string. |
| + Label cons_string, check_encoding; |
| + __ cmp(Operand(ebx), Immediate(kConsStringTag)); |
| + __ j(equal, &cons_string); |
| + __ cmp(Operand(ebx), Immediate(kSlicedStringTag)); |
| + // If subject is not a sliced string, it can only be a non-string or an |
| + // external string. |
| + __ j(not_equal, &runtime); |
| + // String is sliced. |
| + __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| + __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); |
| + // edi: offset of sliced string, smi-tagged. |
| + // eax: parent string. |
| + __ jmp(&check_encoding); |
| + // String is a cons string, check whether it is flat. |
| + __ bind(&cons_string); |
| + __ mov(ebx, FieldOperand(eax, ConsString::kSecondOffset)); |
| + __ cmp(Operand(ebx), factory->empty_string()); |
| __ j(not_equal, &runtime); |
| __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); |
| + // eax: first part of cons string or parent of sliced string. |
| + // edx: map of first part of cons string or map of parent of sliced string. |
| + // Is first part of cons or parent of slice a flat two byte string? |
| + __ bind(&check_encoding); |
| __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| - // String is a cons string with empty second part. |
| - // eax: first part of cons string. |
| - // ebx: map of first part of cons string. |
| - // Is first part a flat two byte string? |
| __ test_b(FieldOperand(ebx, Map::kInstanceTypeOffset), |
| kStringRepresentationMask | kStringEncodingMask); |
| STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
| @@ -3436,14 +3452,14 @@ void RegExpExecStub::Generate(MacroAssembler* masm) { |
| // eax: subject string (flat ascii) |
| // ecx: RegExp data (FixedArray) |
| __ mov(edx, FieldOperand(ecx, JSRegExp::kDataAsciiCodeOffset)); |
| - __ Set(edi, Immediate(1)); // Type is ascii. |
| + __ Set(ecx, Immediate(1)); // Type is ascii. |
| __ jmp(&check_code); |
| __ bind(&seq_two_byte_string); |
| // eax: subject string (flat two byte) |
| // ecx: RegExp data (FixedArray) |
| __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); |
| - __ Set(edi, Immediate(0)); // Type is two byte. |
| + __ Set(ecx, Immediate(0)); // Type is two byte. |
| __ bind(&check_code); |
| // Check that the irregexp code has been generated for the actual string |
| @@ -3479,23 +3495,50 @@ void RegExpExecStub::Generate(MacroAssembler* masm) { |
| __ mov(Operand(esp, 6 * kPointerSize), Immediate(1)); |
| // Argument 6: Start (high end) of backtracking stack memory area. |
| - __ mov(ecx, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| - __ add(ecx, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
| - __ mov(Operand(esp, 5 * kPointerSize), ecx); |
| + __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| + __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
| + __ mov(Operand(esp, 5 * kPointerSize), esi); |
| // Argument 5: static offsets vector buffer. |
| __ mov(Operand(esp, 4 * kPointerSize), |
| Immediate(ExternalReference::address_of_static_offsets_vector( |
| masm->isolate()))); |
| + // Argument 2: Previous index. |
| + __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| + |
| + // Argument 1: Original subject string. |
| + // The original subject is in the previous stack frame. Therefore we have to |
| + // use ebp, which points exactly to one pointer size below the previous esp. |
| + // (Because creating a new stack frame pushes the previous ebp onto the stack |
| + // and thereby moves up esp by one kPointerSize.) |
| + __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize)); |
| + __ mov(Operand(esp, 0 * kPointerSize), esi); |
| + // esi: original subject string |
| + // eax: underlying subject string |
| + |
| // Argument 4: End of string data |
| // Argument 3: Start of string data |
| - Label setup_two_byte, setup_rest; |
| - __ test(edi, Operand(edi)); |
| - __ mov(edi, FieldOperand(eax, String::kLengthOffset)); |
| - __ j(zero, &setup_two_byte, Label::kNear); |
| + Label setup_two_byte, setup_rest, length_not_from_slice, got_length; |
| + // Prepare start and end index of the input. |
| + // Load the length from the original sliced string if that is the case. |
| + __ cmp(edi, NOT_SLICED); |
| + __ j(equal, &length_not_from_slice); |
| + __ mov(esi, FieldOperand(esi, String::kLengthOffset)); |
| + __ add(esi, Operand(edi)); // Calculate input end wrt offset. |
| __ SmiUntag(edi); |
| - __ lea(ecx, FieldOperand(eax, edi, times_1, SeqAsciiString::kHeaderSize)); |
| + __ add(ebx, Operand(edi)); // Calculate input start wrt offset. |
| + __ jmp(&got_length); |
| + __ bind(&length_not_from_slice); |
| + __ mov(esi, FieldOperand(eax, String::kLengthOffset)); |
| + __ bind(&got_length); |
| + |
| + // ebx: start index of the input string |
| + // esi: end index of the input string |
| + __ test(ecx, Operand(ecx)); |
| + __ j(zero, &setup_two_byte, Label::kNear); |
| + __ SmiUntag(esi); |
| + __ lea(ecx, FieldOperand(eax, esi, times_1, SeqAsciiString::kHeaderSize)); |
| __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqAsciiString::kHeaderSize)); |
| __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| @@ -3503,20 +3546,14 @@ void RegExpExecStub::Generate(MacroAssembler* masm) { |
| __ bind(&setup_two_byte); |
| STATIC_ASSERT(kSmiTag == 0); |
| - STATIC_ASSERT(kSmiTagSize == 1); // edi is smi (powered by 2). |
| - __ lea(ecx, FieldOperand(eax, edi, times_1, SeqTwoByteString::kHeaderSize)); |
| + STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2). |
| + __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize)); |
| __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize)); |
| __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| __ bind(&setup_rest); |
| - // Argument 2: Previous index. |
| - __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| - |
| - // Argument 1: Subject string. |
| - __ mov(Operand(esp, 0 * kPointerSize), eax); |
| - |
| // Locate the code entry and call it. |
| __ add(Operand(edx), Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| __ call(Operand(edx)); |
| @@ -4827,6 +4864,7 @@ void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
| Label flat_string; |
| Label ascii_string; |
| Label got_char_code; |
| + Label sliced_string; |
| // If the receiver is a smi trigger the non-string case. |
| STATIC_ASSERT(kSmiTag == 0); |
| @@ -4857,8 +4895,11 @@ void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
| __ j(zero, &flat_string); |
| // Handle non-flat strings. |
| - __ test(result_, Immediate(kIsConsStringMask)); |
| - __ j(zero, &call_runtime_); |
| + __ and_(result_, kStringRepresentationMask); |
| + __ cmp(result_, kSlicedStringTag); |
| + __ j(equal, &sliced_string); |
| + __ cmp(result_, kExternalStringTag); |
| + __ j(equal, &call_runtime_); |
| // ConsString. |
| // Check whether the right hand side is the empty string (i.e. if |
| @@ -4876,6 +4917,14 @@ void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
| STATIC_ASSERT(kSeqStringTag == 0); |
| __ test(result_, Immediate(kStringRepresentationMask)); |
| __ j(not_zero, &call_runtime_); |
| + __ jmp(&flat_string); |
| + |
| + // SlicedString, unpack and add offset. |
| + __ bind(&sliced_string); |
| + __ add(scratch_, FieldOperand(object_, SlicedString::kOffsetOffset)); |
| + __ mov(object_, FieldOperand(object_, SlicedString::kParentOffset)); |
| + __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| + __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| // Check for 1-byte or 2-byte string. |
| __ bind(&flat_string); |
| @@ -5201,6 +5250,8 @@ void StringAddStub::Generate(MacroAssembler* masm) { |
| __ and_(ecx, kStringRepresentationMask); |
| __ cmp(ecx, kExternalStringTag); |
| __ j(equal, &string_add_runtime); |
| + // We cannot encounter sliced strings here since: |
| + STATIC_ASSERT(SlicedString::kMinLength >= String::kMinNonFlatLength); |
| // Now check if both strings are ascii strings. |
| // eax: first string |
| // ebx: length of resulting flat string as a smi |
| @@ -5612,6 +5663,9 @@ void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| void SubStringStub::Generate(MacroAssembler* masm) { |
| Label runtime; |
| + if (FLAG_string_slices) { |
| + __ jmp(&runtime); |
| + } |
| // Stack frame on entry. |
| // esp[0]: return address |
| // esp[4]: to |