Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Unified Diff: src/ia32/code-stubs-ia32.cc

Issue 7477045: Tentative implementation of string slices (hidden under the flag --string-slices). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Patched RegExp for string slices. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..b2f535e517570e2e0b620b7b0ecd8a2a342ed443 100644
--- a/src/ia32/code-stubs-ia32.cc
+++ b/src/ia32/code-stubs-ia32.cc
@@ -3399,30 +3399,43 @@ 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.
// 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, 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, check whether it is truncated.
+ __ mov(ebx, FieldOperand(eax, SlicedString::kLengthOffset));
+ __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset));
+ // ebx: length of sliced string.
+ // eax: parent string.
+ __ cmp(ebx, FieldOperand(eax, String::kLengthOffset));
+ __ j(not_equal, &runtime);
+ __ jmp(&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(&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);
@@ -4827,6 +4840,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 +4871,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 +4893,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 +5226,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 +5639,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

Powered by Google App Engine
This is Rietveld 408576698