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

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

Issue 2355793003: [stubs] Port SubStringStub to TurboFan (Closed)
Patch Set: Address comments Created 4 years, 3 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
« no previous file with comments | « src/mips/code-stubs-mips.cc ('k') | src/ppc/code-stubs-ppc.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/mips64/code-stubs-mips64.cc
diff --git a/src/mips64/code-stubs-mips64.cc b/src/mips64/code-stubs-mips64.cc
index c0c05747df22f643df78c0eb8509c04fc9fd3646..b9356c9e928697c8f227e4a816b55c58d2680d97 100644
--- a/src/mips64/code-stubs-mips64.cc
+++ b/src/mips64/code-stubs-mips64.cc
@@ -2271,229 +2271,6 @@ void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
__ bind(&done);
}
-
-void SubStringStub::Generate(MacroAssembler* masm) {
- Label runtime;
- // Stack frame on entry.
- // ra: return address
- // sp[0]: to
- // sp[4]: from
- // sp[8]: string
-
- // This stub is called from the native-call %_SubString(...), so
- // nothing can be assumed about the arguments. It is tested that:
- // "string" is a sequential string,
- // both "from" and "to" are smis, and
- // 0 <= from <= to <= string.length.
- // If any of these assumptions fail, we call the runtime system.
-
- const int kToOffset = 0 * kPointerSize;
- const int kFromOffset = 1 * kPointerSize;
- const int kStringOffset = 2 * kPointerSize;
-
- __ ld(a2, MemOperand(sp, kToOffset));
- __ ld(a3, MemOperand(sp, kFromOffset));
-
- STATIC_ASSERT(kSmiTag == 0);
-
- // Utilize delay slots. SmiUntag doesn't emit a jump, everything else is
- // safe in this case.
- __ JumpIfNotSmi(a2, &runtime);
- __ JumpIfNotSmi(a3, &runtime);
- // Both a2 and a3 are untagged integers.
-
- __ SmiUntag(a2, a2);
- __ SmiUntag(a3, a3);
- __ Branch(&runtime, lt, a3, Operand(zero_reg)); // From < 0.
-
- __ Branch(&runtime, gt, a3, Operand(a2)); // Fail if from > to.
- __ Dsubu(a2, a2, a3);
-
- // Make sure first argument is a string.
- __ ld(v0, MemOperand(sp, kStringOffset));
- __ JumpIfSmi(v0, &runtime);
- __ ld(a1, FieldMemOperand(v0, HeapObject::kMapOffset));
- __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
- __ And(a4, a1, Operand(kIsNotStringMask));
-
- __ Branch(&runtime, ne, a4, Operand(zero_reg));
-
- Label single_char;
- __ Branch(&single_char, eq, a2, Operand(1));
-
- // Short-cut for the case of trivial substring.
- Label return_v0;
- // v0: original string
- // a2: result string length
- __ ld(a4, FieldMemOperand(v0, String::kLengthOffset));
- __ SmiUntag(a4);
- // Return original string.
- __ Branch(&return_v0, eq, a2, Operand(a4));
- // Longer than original string's length or negative: unsafe arguments.
- __ Branch(&runtime, hi, a2, Operand(a4));
- // Shorter than original string's length: an actual substring.
-
- // Deal with different string types: update the index if necessary
- // and put the underlying string into a5.
- // v0: original string
- // a1: instance type
- // a2: length
- // a3: from index (untagged)
- Label underlying_unpacked, sliced_string, seq_or_external_string;
- // If the string is not indirect, it can only be sequential or external.
- STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
- STATIC_ASSERT(kIsIndirectStringMask != 0);
- __ And(a4, a1, Operand(kIsIndirectStringMask));
- __ Branch(USE_DELAY_SLOT, &seq_or_external_string, eq, a4, Operand(zero_reg));
- // a4 is used as a scratch register and can be overwritten in either case.
- __ And(a4, a1, Operand(kSlicedNotConsMask));
- __ Branch(&sliced_string, ne, a4, Operand(zero_reg));
- // Cons string. Check whether it is flat, then fetch first part.
- __ ld(a5, FieldMemOperand(v0, ConsString::kSecondOffset));
- __ LoadRoot(a4, Heap::kempty_stringRootIndex);
- __ Branch(&runtime, ne, a5, Operand(a4));
- __ ld(a5, FieldMemOperand(v0, ConsString::kFirstOffset));
- // Update instance type.
- __ ld(a1, FieldMemOperand(a5, HeapObject::kMapOffset));
- __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
- __ jmp(&underlying_unpacked);
-
- __ bind(&sliced_string);
- // Sliced string. Fetch parent and correct start index by offset.
- __ ld(a5, FieldMemOperand(v0, SlicedString::kParentOffset));
- __ ld(a4, FieldMemOperand(v0, SlicedString::kOffsetOffset));
- __ SmiUntag(a4); // Add offset to index.
- __ Daddu(a3, a3, a4);
- // Update instance type.
- __ ld(a1, FieldMemOperand(a5, HeapObject::kMapOffset));
- __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
- __ jmp(&underlying_unpacked);
-
- __ bind(&seq_or_external_string);
- // Sequential or external string. Just move string to the expected register.
- __ mov(a5, v0);
-
- __ bind(&underlying_unpacked);
-
- if (FLAG_string_slices) {
- Label copy_routine;
- // a5: underlying subject string
- // a1: instance type of underlying subject string
- // a2: length
- // a3: adjusted start index (untagged)
- // Short slice. Copy instead of slicing.
- __ Branch(&copy_routine, lt, a2, Operand(SlicedString::kMinLength));
- // 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 & kOneByteStringTag) != 0);
- STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
- __ And(a4, a1, Operand(kStringEncodingMask));
- __ Branch(&two_byte_slice, eq, a4, Operand(zero_reg));
- __ AllocateOneByteSlicedString(v0, a2, a6, a7, &runtime);
- __ jmp(&set_slice_header);
- __ bind(&two_byte_slice);
- __ AllocateTwoByteSlicedString(v0, a2, a6, a7, &runtime);
- __ bind(&set_slice_header);
- __ SmiTag(a3);
- __ sd(a5, FieldMemOperand(v0, SlicedString::kParentOffset));
- __ sd(a3, FieldMemOperand(v0, SlicedString::kOffsetOffset));
- __ jmp(&return_v0);
-
- __ bind(&copy_routine);
- }
-
- // a5: underlying subject string
- // a1: instance type of underlying subject string
- // a2: length
- // a3: adjusted start index (untagged)
- Label two_byte_sequential, sequential_string, allocate_result;
- STATIC_ASSERT(kExternalStringTag != 0);
- STATIC_ASSERT(kSeqStringTag == 0);
- __ And(a4, a1, Operand(kExternalStringTag));
- __ Branch(&sequential_string, eq, a4, Operand(zero_reg));
-
- // Handle external string.
- // Rule out short external strings.
- STATIC_ASSERT(kShortExternalStringTag != 0);
- __ And(a4, a1, Operand(kShortExternalStringTag));
- __ Branch(&runtime, ne, a4, Operand(zero_reg));
- __ ld(a5, FieldMemOperand(a5, ExternalString::kResourceDataOffset));
- // a5 already points to the first character of underlying string.
- __ jmp(&allocate_result);
-
- __ bind(&sequential_string);
- // Locate first character of underlying subject string.
- STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
- __ Daddu(a5, a5, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
-
- __ bind(&allocate_result);
- // Sequential acii string. Allocate the result.
- STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
- __ And(a4, a1, Operand(kStringEncodingMask));
- __ Branch(&two_byte_sequential, eq, a4, Operand(zero_reg));
-
- // Allocate and copy the resulting one_byte string.
- __ AllocateOneByteString(v0, a2, a4, a6, a7, &runtime);
-
- // Locate first character of substring to copy.
- __ Daddu(a5, a5, a3);
-
- // Locate first character of result.
- __ Daddu(a1, v0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
-
- // v0: result string
- // a1: first character of result string
- // a2: result string length
- // a5: first character of substring to copy
- STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
- StringHelper::GenerateCopyCharacters(
- masm, a1, a5, a2, a3, String::ONE_BYTE_ENCODING);
- __ jmp(&return_v0);
-
- // Allocate and copy the resulting two-byte string.
- __ bind(&two_byte_sequential);
- __ AllocateTwoByteString(v0, a2, a4, a6, a7, &runtime);
-
- // Locate first character of substring to copy.
- STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
- __ Dlsa(a5, a5, a3, 1);
- // Locate first character of result.
- __ Daddu(a1, v0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
-
- // v0: result string.
- // a1: first character of result.
- // a2: result length.
- // a5: first character of substring to copy.
- STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
- StringHelper::GenerateCopyCharacters(
- masm, a1, a5, a2, a3, String::TWO_BYTE_ENCODING);
-
- __ bind(&return_v0);
- Counters* counters = isolate()->counters();
- __ IncrementCounter(counters->sub_string_native(), 1, a3, a4);
- __ DropAndRet(3);
-
- // Just jump to runtime to create the sub string.
- __ bind(&runtime);
- __ TailCallRuntime(Runtime::kSubString);
-
- __ bind(&single_char);
- // v0: original string
- // a1: instance type
- // a2: length
- // a3: from index (untagged)
- __ SmiTag(a3);
- StringCharAtGenerator generator(v0, a3, a2, v0, &runtime, &runtime, &runtime,
- RECEIVER_IS_STRING);
- generator.GenerateFast(masm);
- __ DropAndRet(3);
- generator.SkipSlow(masm, &runtime);
-}
-
void ToStringStub::Generate(MacroAssembler* masm) {
// The ToString stub takes on argument in a0.
Label is_number;
« no previous file with comments | « src/mips/code-stubs-mips.cc ('k') | src/ppc/code-stubs-ppc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698