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

Unified Diff: src/x64/code-stubs-x64.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: Included Vitaly's suggestions. 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/x64/code-stubs-x64.cc
diff --git a/src/x64/code-stubs-x64.cc b/src/x64/code-stubs-x64.cc
index 1a6efcbd61acc781addb3f175e7c5e7f6cd1dd6b..c0d6c89732b37e85fe94917075bba5e8e2b3eaab 100644
--- a/src/x64/code-stubs-x64.cc
+++ b/src/x64/code-stubs-x64.cc
@@ -2303,7 +2303,6 @@ void RegExpExecStub::Generate(MacroAssembler* masm) {
__ testq(kScratchRegister, kScratchRegister);
__ j(zero, &runtime);
-
// Check that the first argument is a JSRegExp object.
__ movq(rax, Operand(rsp, kJSRegExpOffset));
__ JumpIfSmi(rax, &runtime);
@@ -2374,6 +2373,11 @@ void RegExpExecStub::Generate(MacroAssembler* masm) {
__ cmpl(rdx, rdi);
__ 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.
+ const int64_t kNotAStringSlice = -1;
+ __ Set(r14, kNotAStringSlice);
// rax: RegExp data (FixedArray)
// Check the representation and encoding of the subject string.
Label seq_ascii_string, seq_two_byte_string, check_code;
@@ -2386,28 +2390,42 @@ void RegExpExecStub::Generate(MacroAssembler* masm) {
STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0);
__ j(zero, &seq_two_byte_string, Label::kNear);
// Any other flat string must be a flat ascii string.
- __ testb(rbx, Immediate(kIsNotStringMask | kStringRepresentationMask));
+ __ andb(rbx, Immediate(kIsNotStringMask | kStringRepresentationMask));
__ j(zero, &seq_ascii_string, Label::kNear);
- // Check for flat cons string.
+ // Check for flat cons string or 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);
- __ testb(rbx, Immediate(kIsNotStringMask | kExternalStringTag));
- __ j(not_zero, &runtime);
- // String is a cons string.
+ // In the case of a sliced string its offset has to be taken into account.
+ Label cons_string, check_encoding;
+ __ cmpq(rbx, Immediate(kConsStringTag));
+ __ j(equal, &cons_string, Label::kNear);
+ __ cmpq(rbx, 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.
+ __ SmiToInteger32(r14, FieldOperand(rdi, SlicedString::kOffsetOffset));
+ __ SmiToInteger32(r15, FieldOperand(rdi, SlicedString::kLengthOffset));
+ __ addq(r15, r14); // Add offset to length to get input end.
+ __ movq(rdi, FieldOperand(rdi, SlicedString::kParentOffset));
+ // r14: offset of sliced string
+ // r15: length of sliced string + slice offset
+ // rdi: parent string.
+ __ jmp(&check_encoding, Label::kNear);
+ // String is a cons string, check whether it is flat.
+ __ bind(&cons_string);
__ CompareRoot(FieldOperand(rdi, ConsString::kSecondOffset),
Heap::kEmptyStringRootIndex);
__ j(not_equal, &runtime);
__ movq(rdi, FieldOperand(rdi, ConsString::kFirstOffset));
+ // rdi: first part of cons string or parent of sliced string.
+ // rbx: 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);
__ movq(rbx, FieldOperand(rdi, HeapObject::kMapOffset));
- // String is a cons string with empty second part.
- // rdi: first part of cons string.
- // rbx: map of first part of cons string.
- // Is first part a flat two byte string?
__ testb(FieldOperand(rbx, Map::kInstanceTypeOffset),
Immediate(kStringRepresentationMask | kStringEncodingMask));
STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0);
@@ -2504,33 +2522,43 @@ void RegExpExecStub::Generate(MacroAssembler* masm) {
// rbx: previous index
// rcx: encoding of subject string (1 if ascii 0 if two_byte);
// r11: code
+ // r14: slice offset or NOT_SLICE
+ // r15: slice length + slice offset if r14 == NOTS_SLICE
+
+ // Argument 2: Previous index.
+ __ movq(arg2, rbx);
// Argument 4: End of string data
// Argument 3: Start of string data
- Label setup_two_byte, setup_rest;
+ Label setup_two_byte, setup_rest, got_length, length_not_from_slice;
+ // Prepare start and end index of the input.
+ // Load the length from the original sliced string if that is the case.
+ __ cmpq(r14, Immediate(kNotAStringSlice));
+ __ j(equal, &length_not_from_slice, Label::kNear);
+ __ addq(rbx, r14);
+ __ jmp(&got_length);
+ __ bind(&length_not_from_slice);
+ __ SmiToInteger32(r15, FieldOperand(rdi, String::kLengthOffset));
+ __ bind(&got_length);
+
+ // rbx: start index of the input
+ // r15: end index of the input
__ testb(rcx, rcx); // Last use of rcx as encoding of subject string.
__ j(zero, &setup_two_byte, Label::kNear);
- __ SmiToInteger32(rcx, FieldOperand(rdi, String::kLengthOffset));
- __ lea(arg4, FieldOperand(rdi, rcx, times_1, SeqAsciiString::kHeaderSize));
+ __ lea(arg4, FieldOperand(rdi, r15, times_1, SeqAsciiString::kHeaderSize));
__ lea(arg3, FieldOperand(rdi, rbx, times_1, SeqAsciiString::kHeaderSize));
__ jmp(&setup_rest, Label::kNear);
__ bind(&setup_two_byte);
- __ SmiToInteger32(rcx, FieldOperand(rdi, String::kLengthOffset));
- __ lea(arg4, FieldOperand(rdi, rcx, times_2, SeqTwoByteString::kHeaderSize));
+ __ lea(arg4, FieldOperand(rdi, r15, times_2, SeqTwoByteString::kHeaderSize));
__ lea(arg3, FieldOperand(rdi, rbx, times_2, SeqTwoByteString::kHeaderSize));
-
__ bind(&setup_rest);
- // Argument 2: Previous index.
- __ movq(arg2, rbx);
- // Argument 1: Subject string.
-#ifdef _WIN64
- __ movq(arg1, rdi);
-#else
- // Already there in AMD64 calling convention.
- ASSERT(arg1.is(rdi));
- USE(arg1);
-#endif
+ // Argument 1: Original subject string.
+ // The original subject is in the previous stack frame. Therefore we have to
+ // use rbp, which points exactly to one pointer size below the previous rsp.
+ // (Because creating a new stack frame pushes the previous rbp onto the stack
+ // and thereby moves up rsp by one kPointerSize.)
+ __ movq(arg1, Operand(rbp, kSubjectOffset + kPointerSize));
// Locate the code entry and call it.
__ addq(r11, Immediate(Code::kHeaderSize - kHeapObjectTag));
@@ -3780,6 +3808,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.
__ JumpIfSmi(object_, receiver_not_string_);
@@ -3808,8 +3837,11 @@ void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
__ j(zero, &flat_string);
// Handle non-flat strings.
- __ testb(result_, Immediate(kIsConsStringMask));
- __ j(zero, &call_runtime_);
+ __ and_(result_, Immediate(kStringRepresentationMask));
+ __ cmpb(result_, Immediate(kSlicedStringTag));
+ __ j(equal, &sliced_string);
+ __ cmpb(result_, Immediate(kExternalStringTag));
+ __ j(equal, &call_runtime_);
// ConsString.
// Check whether the right hand side is the empty string (i.e. if
@@ -3827,6 +3859,14 @@ void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
STATIC_ASSERT(kSeqStringTag == 0);
__ testb(result_, Immediate(kStringRepresentationMask));
__ j(not_zero, &call_runtime_);
+ __ jmp(&flat_string);
+
+ // SlicedString, unpack and add offset.
+ __ bind(&sliced_string);
+ __ addq(scratch_, FieldOperand(object_, SlicedString::kOffsetOffset));
+ __ movq(object_, FieldOperand(object_, SlicedString::kParentOffset));
+ __ movq(result_, FieldOperand(object_, HeapObject::kMapOffset));
+ __ movzxbl(result_, FieldOperand(result_, Map::kInstanceTypeOffset));
// Check for 1-byte or 2-byte string.
__ bind(&flat_string);
@@ -4137,6 +4177,8 @@ void StringAddStub::Generate(MacroAssembler* masm) {
__ and_(rcx, Immediate(kStringRepresentationMask));
__ cmpl(rcx, Immediate(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.
// rax: first string
// rbx: length of resulting flat string
@@ -4529,6 +4571,9 @@ 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
« src/objects-inl.h ('K') | « src/runtime.cc ('k') | src/x64/lithium-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698