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

Unified Diff: src/s390/code-stubs-s390.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/ppc/code-stubs-ppc.cc ('k') | src/x64/code-stubs-x64.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/s390/code-stubs-s390.cc
diff --git a/src/s390/code-stubs-s390.cc b/src/s390/code-stubs-s390.cc
index 111b317bd77e02cb4dfb5bbd1ee46e2359d6bebc..e867bf9e113f943e55c4eb630615763bc22f947b 100644
--- a/src/s390/code-stubs-s390.cc
+++ b/src/s390/code-stubs-s390.cc
@@ -2202,235 +2202,6 @@ void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, Register dest,
__ bind(&done);
}
-void SubStringStub::Generate(MacroAssembler* masm) {
- Label runtime;
-
- // Stack frame on entry.
- // lr: 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;
-
- __ LoadP(r4, MemOperand(sp, kToOffset));
- __ LoadP(r5, MemOperand(sp, kFromOffset));
-
- // If either to or from had the smi tag bit set, then fail to generic runtime
- __ JumpIfNotSmi(r4, &runtime);
- __ JumpIfNotSmi(r5, &runtime);
- __ SmiUntag(r4);
- __ SmiUntag(r5);
- // Both r4 and r5 are untagged integers.
-
- // We want to bailout to runtime here if From is negative.
- __ blt(&runtime); // From < 0.
-
- __ CmpLogicalP(r5, r4);
- __ bgt(&runtime); // Fail if from > to.
- __ SubP(r4, r4, r5);
-
- // Make sure first argument is a string.
- __ LoadP(r2, MemOperand(sp, kStringOffset));
- __ JumpIfSmi(r2, &runtime);
- Condition is_string = masm->IsObjectStringType(r2, r3);
- __ b(NegateCondition(is_string), &runtime);
-
- Label single_char;
- __ CmpP(r4, Operand(1));
- __ b(eq, &single_char);
-
- // Short-cut for the case of trivial substring.
- Label return_r2;
- // r2: original string
- // r4: result string length
- __ LoadP(r6, FieldMemOperand(r2, String::kLengthOffset));
- __ SmiUntag(r0, r6);
- __ CmpLogicalP(r4, r0);
- // Return original string.
- __ beq(&return_r2);
- // Longer than original string's length or negative: unsafe arguments.
- __ bgt(&runtime);
- // 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 r7.
- // r2: original string
- // r3: instance type
- // r4: length
- // r5: 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);
- __ mov(r0, Operand(kIsIndirectStringMask));
- __ AndP(r0, r3);
- __ beq(&seq_or_external_string);
-
- __ mov(r0, Operand(kSlicedNotConsMask));
- __ AndP(r0, r3);
- __ bne(&sliced_string);
- // Cons string. Check whether it is flat, then fetch first part.
- __ LoadP(r7, FieldMemOperand(r2, ConsString::kSecondOffset));
- __ CompareRoot(r7, Heap::kempty_stringRootIndex);
- __ bne(&runtime);
- __ LoadP(r7, FieldMemOperand(r2, ConsString::kFirstOffset));
- // Update instance type.
- __ LoadP(r3, FieldMemOperand(r7, HeapObject::kMapOffset));
- __ LoadlB(r3, FieldMemOperand(r3, Map::kInstanceTypeOffset));
- __ b(&underlying_unpacked);
-
- __ bind(&sliced_string);
- // Sliced string. Fetch parent and correct start index by offset.
- __ LoadP(r7, FieldMemOperand(r2, SlicedString::kParentOffset));
- __ LoadP(r6, FieldMemOperand(r2, SlicedString::kOffsetOffset));
- __ SmiUntag(r3, r6);
- __ AddP(r5, r3); // Add offset to index.
- // Update instance type.
- __ LoadP(r3, FieldMemOperand(r7, HeapObject::kMapOffset));
- __ LoadlB(r3, FieldMemOperand(r3, Map::kInstanceTypeOffset));
- __ b(&underlying_unpacked);
-
- __ bind(&seq_or_external_string);
- // Sequential or external string. Just move string to the expected register.
- __ LoadRR(r7, r2);
-
- __ bind(&underlying_unpacked);
-
- if (FLAG_string_slices) {
- Label copy_routine;
- // r7: underlying subject string
- // r3: instance type of underlying subject string
- // r4: length
- // r5: adjusted start index (untagged)
- __ CmpP(r4, Operand(SlicedString::kMinLength));
- // Short slice. Copy instead of slicing.
- __ blt(&copy_routine);
- // 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);
- __ mov(r0, Operand(kStringEncodingMask));
- __ AndP(r0, r3);
- __ beq(&two_byte_slice);
- __ AllocateOneByteSlicedString(r2, r4, r8, r9, &runtime);
- __ b(&set_slice_header);
- __ bind(&two_byte_slice);
- __ AllocateTwoByteSlicedString(r2, r4, r8, r9, &runtime);
- __ bind(&set_slice_header);
- __ SmiTag(r5);
- __ StoreP(r7, FieldMemOperand(r2, SlicedString::kParentOffset));
- __ StoreP(r5, FieldMemOperand(r2, SlicedString::kOffsetOffset));
- __ b(&return_r2);
-
- __ bind(&copy_routine);
- }
-
- // r7: underlying subject string
- // r3: instance type of underlying subject string
- // r4: length
- // r5: adjusted start index (untagged)
- Label two_byte_sequential, sequential_string, allocate_result;
- STATIC_ASSERT(kExternalStringTag != 0);
- STATIC_ASSERT(kSeqStringTag == 0);
- __ mov(r0, Operand(kExternalStringTag));
- __ AndP(r0, r3);
- __ beq(&sequential_string);
-
- // Handle external string.
- // Rule out short external strings.
- STATIC_ASSERT(kShortExternalStringTag != 0);
- __ mov(r0, Operand(kShortExternalStringTag));
- __ AndP(r0, r3);
- __ bne(&runtime);
- __ LoadP(r7, FieldMemOperand(r7, ExternalString::kResourceDataOffset));
- // r7 already points to the first character of underlying string.
- __ b(&allocate_result);
-
- __ bind(&sequential_string);
- // Locate first character of underlying subject string.
- STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
- __ AddP(r7, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
-
- __ bind(&allocate_result);
- // Sequential acii string. Allocate the result.
- STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
- __ mov(r0, Operand(kStringEncodingMask));
- __ AndP(r0, r3);
- __ beq(&two_byte_sequential);
-
- // Allocate and copy the resulting one-byte string.
- __ AllocateOneByteString(r2, r4, r6, r8, r9, &runtime);
-
- // Locate first character of substring to copy.
- __ AddP(r7, r5);
- // Locate first character of result.
- __ AddP(r3, r2, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
-
- // r2: result string
- // r3: first character of result string
- // r4: result string length
- // r7: first character of substring to copy
- STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
- StringHelper::GenerateCopyCharacters(masm, r3, r7, r4, r5,
- String::ONE_BYTE_ENCODING);
- __ b(&return_r2);
-
- // Allocate and copy the resulting two-byte string.
- __ bind(&two_byte_sequential);
- __ AllocateTwoByteString(r2, r4, r6, r8, r9, &runtime);
-
- // Locate first character of substring to copy.
- __ ShiftLeftP(r3, r5, Operand(1));
- __ AddP(r7, r3);
- // Locate first character of result.
- __ AddP(r3, r2, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
-
- // r2: result string.
- // r3: first character of result.
- // r4: result length.
- // r7: first character of substring to copy.
- STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
- StringHelper::GenerateCopyCharacters(masm, r3, r7, r4, r5,
- String::TWO_BYTE_ENCODING);
-
- __ bind(&return_r2);
- Counters* counters = isolate()->counters();
- __ IncrementCounter(counters->sub_string_native(), 1, r5, r6);
- __ Drop(3);
- __ Ret();
-
- // Just jump to runtime to create the sub string.
- __ bind(&runtime);
- __ TailCallRuntime(Runtime::kSubString);
-
- __ bind(&single_char);
- // r2: original string
- // r3: instance type
- // r4: length
- // r5: from index (untagged)
- __ SmiTag(r5, r5);
- StringCharAtGenerator generator(r2, r5, r4, r2, &runtime, &runtime, &runtime,
- RECEIVER_IS_STRING);
- generator.GenerateFast(masm);
- __ Drop(3);
- __ Ret();
- generator.SkipSlow(masm, &runtime);
-}
-
void ToStringStub::Generate(MacroAssembler* masm) {
// The ToString stub takes one argument in r2.
Label done;
« no previous file with comments | « src/ppc/code-stubs-ppc.cc ('k') | src/x64/code-stubs-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698