OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 5954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5965 __ li(at, Operand(kHashShiftCutOffMask)); | 5965 __ li(at, Operand(kHashShiftCutOffMask)); |
5966 __ and_(hash, hash, at); | 5966 __ and_(hash, hash, at); |
5967 | 5967 |
5968 // if (hash == 0) hash = 27; | 5968 // if (hash == 0) hash = 27; |
5969 __ ori(at, zero_reg, 27); | 5969 __ ori(at, zero_reg, 27); |
5970 __ movz(hash, at, hash); | 5970 __ movz(hash, at, hash); |
5971 } | 5971 } |
5972 | 5972 |
5973 | 5973 |
5974 void SubStringStub::Generate(MacroAssembler* masm) { | 5974 void SubStringStub::Generate(MacroAssembler* masm) { |
5975 Label sub_string_runtime; | 5975 Label runtime; |
5976 // Stack frame on entry. | 5976 // Stack frame on entry. |
5977 // ra: return address | 5977 // ra: return address |
5978 // sp[0]: to | 5978 // sp[0]: to |
5979 // sp[4]: from | 5979 // sp[4]: from |
5980 // sp[8]: string | 5980 // sp[8]: string |
5981 | 5981 |
5982 // This stub is called from the native-call %_SubString(...), so | 5982 // This stub is called from the native-call %_SubString(...), so |
5983 // nothing can be assumed about the arguments. It is tested that: | 5983 // nothing can be assumed about the arguments. It is tested that: |
5984 // "string" is a sequential string, | 5984 // "string" is a sequential string, |
5985 // both "from" and "to" are smis, and | 5985 // both "from" and "to" are smis, and |
5986 // 0 <= from <= to <= string.length. | 5986 // 0 <= from <= to <= string.length. |
5987 // If any of these assumptions fail, we call the runtime system. | 5987 // If any of these assumptions fail, we call the runtime system. |
5988 | 5988 |
5989 static const int kToOffset = 0 * kPointerSize; | 5989 static const int kToOffset = 0 * kPointerSize; |
5990 static const int kFromOffset = 1 * kPointerSize; | 5990 static const int kFromOffset = 1 * kPointerSize; |
5991 static const int kStringOffset = 2 * kPointerSize; | 5991 static const int kStringOffset = 2 * kPointerSize; |
5992 | 5992 |
5993 Register to = t2; | 5993 __ lw(a2, MemOperand(sp, kToOffset)); |
5994 Register from = t3; | 5994 __ lw(a3, MemOperand(sp, kFromOffset)); |
5995 | |
5996 // Check bounds and smi-ness. | |
5997 __ lw(to, MemOperand(sp, kToOffset)); | |
5998 __ lw(from, MemOperand(sp, kFromOffset)); | |
5999 STATIC_ASSERT(kFromOffset == kToOffset + 4); | 5995 STATIC_ASSERT(kFromOffset == kToOffset + 4); |
6000 STATIC_ASSERT(kSmiTag == 0); | 5996 STATIC_ASSERT(kSmiTag == 0); |
6001 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); | 5997 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
6002 | 5998 |
6003 __ JumpIfNotSmi(from, &sub_string_runtime); | 5999 // Utilize delay slots. SmiUntag doesn't emit a jump, everything else is |
6004 __ JumpIfNotSmi(to, &sub_string_runtime); | 6000 // safe in this case. |
| 6001 __ JumpIfSmi(a2, &runtime, at, USE_DELAY_SLOT); |
| 6002 __ SmiUntag(a2); |
| 6003 __ JumpIfSmi(a3, &runtime, at, USE_DELAY_SLOT); |
| 6004 __ SmiUntag(a3); |
6005 | 6005 |
6006 __ sra(a3, from, kSmiTagSize); // Remove smi tag. | 6006 // Both a2 and a3 are untagged integers. |
6007 __ sra(t5, to, kSmiTagSize); // Remove smi tag. | |
6008 | 6007 |
6009 // a3: from index (untagged smi) | 6008 __ Branch(&runtime, lt, a3, Operand(zero_reg)); // From < 0. |
6010 // t5: to index (untagged smi) | |
6011 | |
6012 __ Branch(&sub_string_runtime, lt, a3, Operand(zero_reg)); // From < 0. | |
6013 | 6009 |
6014 __ subu(a2, t5, a3); | 6010 __ subu(a2, t5, a3); |
6015 __ Branch(&sub_string_runtime, gt, a3, Operand(t5)); // Fail if from > to. | 6011 __ Branch(&runtime, gt, a3, Operand(t5)); // Fail if from > to. |
6016 | 6012 |
6017 // Special handling of sub-strings of length 1 and 2. One character strings | 6013 // Make sure first argument is a string. |
6018 // are handled in the runtime system (looked up in the single character | |
6019 // cache). Two character strings are looked for in the symbol cache in | |
6020 // generated code. | |
6021 __ Branch(&sub_string_runtime, lt, a2, Operand(2)); | |
6022 | |
6023 // Both to and from are smis. | |
6024 | |
6025 // a2: result string length | |
6026 // a3: from index (untagged smi) | |
6027 // t2: (a.k.a. to): to (smi) | |
6028 // t3: (a.k.a. from): from offset (smi) | |
6029 // t5: to index (untagged smi) | |
6030 | |
6031 // Make sure first argument is a sequential (or flat) string. | |
6032 __ lw(v0, MemOperand(sp, kStringOffset)); | 6014 __ lw(v0, MemOperand(sp, kStringOffset)); |
6033 __ Branch(&sub_string_runtime, eq, v0, Operand(kSmiTagMask)); | 6015 __ Branch(&runtime, eq, v0, Operand(kSmiTagMask)); |
6034 | 6016 |
6035 __ lw(a1, FieldMemOperand(v0, HeapObject::kMapOffset)); | 6017 __ lw(a1, FieldMemOperand(v0, HeapObject::kMapOffset)); |
6036 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset)); | 6018 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset)); |
6037 __ And(t4, v0, Operand(kIsNotStringMask)); | 6019 __ And(t4, v0, Operand(kIsNotStringMask)); |
6038 | 6020 |
6039 __ Branch(&sub_string_runtime, ne, t4, Operand(zero_reg)); | 6021 __ Branch(&runtime, ne, t4, Operand(zero_reg)); |
6040 | 6022 |
6041 // Short-cut for the case of trivial substring. | 6023 // Short-cut for the case of trivial substring. |
6042 Label return_v0; | 6024 Label return_v0; |
6043 // v0: original string | 6025 // v0: original string |
6044 // a2: result string length | 6026 // a2: result string length |
6045 __ lw(t0, FieldMemOperand(v0, String::kLengthOffset)); | 6027 __ lw(t0, FieldMemOperand(v0, String::kLengthOffset)); |
6046 __ sra(t0, t0, 1); | 6028 __ sra(t0, t0, 1); |
6047 __ Branch(&return_v0, eq, a2, Operand(t0)); | 6029 __ Branch(&return_v0, eq, a2, Operand(t0)); |
6048 | 6030 |
6049 Label create_slice; | |
6050 if (FLAG_string_slices) { | |
6051 __ Branch(&create_slice, ge, a2, Operand(SlicedString::kMinLength)); | |
6052 } | |
6053 | |
6054 // v0: original string | |
6055 // a1: instance type | |
6056 // a2: result string length | |
6057 // a3: from index (untagged smi) | |
6058 // t2: (a.k.a. to): to (smi) | |
6059 // t3: (a.k.a. from): from offset (smi) | |
6060 // t5: to index (untagged smi) | |
6061 | |
6062 Label seq_string; | |
6063 __ And(t0, a1, Operand(kStringRepresentationMask)); | |
6064 STATIC_ASSERT(kSeqStringTag < kConsStringTag); | |
6065 STATIC_ASSERT(kConsStringTag < kExternalStringTag); | |
6066 STATIC_ASSERT(kConsStringTag < kSlicedStringTag); | |
6067 | |
6068 // Slices and external strings go to runtime. | |
6069 __ Branch(&sub_string_runtime, gt, t0, Operand(kConsStringTag)); | |
6070 | |
6071 // Sequential strings are handled directly. | |
6072 __ Branch(&seq_string, lt, t0, Operand(kConsStringTag)); | |
6073 | |
6074 // Cons string. Try to recurse (once) on the first substring. | |
6075 // (This adds a little more generality than necessary to handle flattened | |
6076 // cons strings, but not much). | |
6077 __ lw(v0, FieldMemOperand(v0, ConsString::kFirstOffset)); | |
6078 __ lw(t0, FieldMemOperand(v0, HeapObject::kMapOffset)); | |
6079 __ lbu(a1, FieldMemOperand(t0, Map::kInstanceTypeOffset)); | |
6080 STATIC_ASSERT(kSeqStringTag == 0); | |
6081 // Cons, slices and external strings go to runtime. | |
6082 __ Branch(&sub_string_runtime, ne, a1, Operand(kStringRepresentationMask)); | |
6083 | |
6084 // Definitly a sequential string. | |
6085 __ bind(&seq_string); | |
6086 | |
6087 // v0: original string | |
6088 // a1: instance type | |
6089 // a2: result string length | |
6090 // a3: from index (untagged smi) | |
6091 // t2: (a.k.a. to): to (smi) | |
6092 // t3: (a.k.a. from): from offset (smi) | |
6093 // t5: to index (untagged smi) | |
6094 | |
6095 __ lw(t0, FieldMemOperand(v0, String::kLengthOffset)); | |
6096 __ Branch(&sub_string_runtime, lt, t0, Operand(to)); // Fail if to > length. | |
6097 to = no_reg; | |
6098 | |
6099 // v0: original string or left hand side of the original cons string. | |
6100 // a1: instance type | |
6101 // a2: result string length | |
6102 // a3: from index (untagged smi) | |
6103 // t3: (a.k.a. from): from offset (smi) | |
6104 // t5: to index (untagged smi) | |
6105 | |
6106 // Check for flat ASCII string. | |
6107 Label non_ascii_flat; | |
6108 STATIC_ASSERT(kTwoByteStringTag == 0); | |
6109 | |
6110 __ And(t4, a1, Operand(kStringEncodingMask)); | |
6111 __ Branch(&non_ascii_flat, eq, t4, Operand(zero_reg)); | |
6112 | 6031 |
6113 Label result_longer_than_two; | 6032 Label result_longer_than_two; |
6114 __ Branch(&result_longer_than_two, gt, a2, Operand(2)); | 6033 // Check for special case of two character ascii string, in which case |
| 6034 // we do a lookup in the symbol table first. |
| 6035 __ li(t0, 2); |
| 6036 __ Branch(&result_longer_than_two, gt, a2, Operand(t0)); |
| 6037 __ Branch(&runtime, lt, a2, Operand(t0)); |
6115 | 6038 |
6116 // Sub string of length 2 requested. | 6039 __ JumpIfInstanceTypeIsNotSequentialAscii(a1, a1, &runtime); |
| 6040 |
6117 // Get the two characters forming the sub string. | 6041 // Get the two characters forming the sub string. |
6118 __ Addu(v0, v0, Operand(a3)); | 6042 __ Addu(v0, v0, Operand(a3)); |
6119 __ lbu(a3, FieldMemOperand(v0, SeqAsciiString::kHeaderSize)); | 6043 __ lbu(a3, FieldMemOperand(v0, SeqAsciiString::kHeaderSize)); |
6120 __ lbu(t0, FieldMemOperand(v0, SeqAsciiString::kHeaderSize + 1)); | 6044 __ lbu(t0, FieldMemOperand(v0, SeqAsciiString::kHeaderSize + 1)); |
6121 | 6045 |
6122 // Try to lookup two character string in symbol table. | 6046 // Try to lookup two character string in symbol table. |
6123 Label make_two_character_string; | 6047 Label make_two_character_string; |
6124 StringHelper::GenerateTwoCharacterSymbolTableProbe( | 6048 StringHelper::GenerateTwoCharacterSymbolTableProbe( |
6125 masm, a3, t0, a1, t1, t2, t3, t4, &make_two_character_string); | 6049 masm, a3, t0, a1, t1, t2, t3, t4, &make_two_character_string); |
6126 Counters* counters = masm->isolate()->counters(); | |
6127 __ jmp(&return_v0); | 6050 __ jmp(&return_v0); |
6128 | 6051 |
6129 // a2: result string length. | 6052 // a2: result string length. |
6130 // a3: two characters combined into halfword in little endian byte order. | 6053 // a3: two characters combined into halfword in little endian byte order. |
6131 __ bind(&make_two_character_string); | 6054 __ bind(&make_two_character_string); |
6132 __ AllocateAsciiString(v0, a2, t0, t1, t4, &sub_string_runtime); | 6055 __ AllocateAsciiString(v0, a2, t0, t1, t4, &runtime); |
6133 __ sh(a3, FieldMemOperand(v0, SeqAsciiString::kHeaderSize)); | 6056 __ sh(a3, FieldMemOperand(v0, SeqAsciiString::kHeaderSize)); |
6134 __ jmp(&return_v0); | 6057 __ jmp(&return_v0); |
6135 | 6058 |
6136 __ bind(&result_longer_than_two); | 6059 __ bind(&result_longer_than_two); |
6137 | 6060 |
6138 // Locate 'from' character of string. | 6061 // Deal with different string types: update the index if necessary |
6139 __ Addu(t1, v0, Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); | 6062 // and put the underlying string into t1. |
6140 __ sra(t4, from, 1); | 6063 // v0: original string |
6141 __ Addu(t1, t1, t4); | 6064 // a1: instance type |
| 6065 // a2: length |
| 6066 // a3: from index (untagged) |
| 6067 Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 6068 // If the string is not indirect, it can only be sequential or external. |
| 6069 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 6070 STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 6071 __ And(t0, a1, Operand(kIsIndirectStringMask)); |
| 6072 __ Branch(USE_DELAY_SLOT, &seq_or_external_string, eq, t0, Operand(zero_reg)); |
6142 | 6073 |
6143 // Allocate the result. | 6074 __ And(t0, a1, Operand(kSlicedNotConsMask)); |
6144 __ AllocateAsciiString(v0, a2, t4, t0, a1, &sub_string_runtime); | 6075 __ Branch(&sliced_string, ne, t0, Operand(zero_reg)); |
| 6076 // Cons string. Check whether it is flat, then fetch first part. |
| 6077 __ lw(t1, FieldMemOperand(v0, ConsString::kSecondOffset)); |
| 6078 __ LoadRoot(t0, Heap::kEmptyStringRootIndex); |
| 6079 __ Branch(&runtime, ne, t1, Operand(t0)); |
| 6080 __ lw(t1, FieldMemOperand(v0, ConsString::kFirstOffset)); |
| 6081 // Update instance type. |
| 6082 __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset)); |
| 6083 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset)); |
| 6084 __ jmp(&underlying_unpacked); |
6145 | 6085 |
6146 // v0: result string | 6086 __ bind(&sliced_string); |
6147 // a2: result string length | 6087 // Sliced string. Fetch parent and correct start index by offset. |
6148 // a3: from index (untagged smi) | 6088 __ lw(t1, FieldMemOperand(v0, SlicedString::kOffsetOffset)); |
6149 // t1: first character of substring to copy | 6089 __ sra(t1, t1, 1); |
6150 // t3: (a.k.a. from): from offset (smi) | 6090 __ Addu(a3, a3, t1); |
| 6091 __ lw(t1, FieldMemOperand(v0, SlicedString::kParentOffset)); |
| 6092 // Update instance type. |
| 6093 __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset)); |
| 6094 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset)); |
| 6095 __ jmp(&underlying_unpacked); |
| 6096 |
| 6097 __ bind(&seq_or_external_string); |
| 6098 // Sequential or external string. Just move string to the expected register. |
| 6099 __ mov(t1, v0); |
| 6100 |
| 6101 __ bind(&underlying_unpacked); |
| 6102 |
| 6103 if (FLAG_string_slices) { |
| 6104 Label copy_routine; |
| 6105 // t1: underlying subject string |
| 6106 // a1: instance type of underlying subject string |
| 6107 // a2: length |
| 6108 // a3: adjusted start index (untagged) |
| 6109 // Short slice. Copy instead of slicing. |
| 6110 __ Branch(©_routine, lt, a2, Operand(SlicedString::kMinLength)); |
| 6111 // Allocate new sliced string. At this point we do not reload the instance |
| 6112 // type including the string encoding because we simply rely on the info |
| 6113 // provided by the original string. It does not matter if the original |
| 6114 // string's encoding is wrong because we always have to recheck encoding of |
| 6115 // the newly created string's parent anyways due to externalized strings. |
| 6116 Label two_byte_slice, set_slice_header; |
| 6117 STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); |
| 6118 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 6119 __ And(t0, a1, Operand(kStringEncodingMask)); |
| 6120 __ Branch(&two_byte_slice, eq, t0, Operand(zero_reg)); |
| 6121 __ AllocateAsciiSlicedString(v0, a2, t2, t3, &runtime); |
| 6122 __ jmp(&set_slice_header); |
| 6123 __ bind(&two_byte_slice); |
| 6124 __ AllocateTwoByteSlicedString(v0, a2, t2, t3, &runtime); |
| 6125 __ bind(&set_slice_header); |
| 6126 __ sll(a3, a3, 1); |
| 6127 __ sw(a3, FieldMemOperand(v0, SlicedString::kOffsetOffset)); |
| 6128 __ sw(t1, FieldMemOperand(v0, SlicedString::kParentOffset)); |
| 6129 __ jmp(&return_v0); |
| 6130 |
| 6131 __ bind(©_routine); |
| 6132 } |
| 6133 |
| 6134 // t1: underlying subject string |
| 6135 // a1: instance type of underlying subject string |
| 6136 // a2: length |
| 6137 // a3: adjusted start index (untagged) |
| 6138 Label two_byte_sequential, sequential_string, allocate_result; |
| 6139 STATIC_ASSERT(kExternalStringTag != 0); |
| 6140 STATIC_ASSERT(kSeqStringTag == 0); |
| 6141 __ And(t0, a1, Operand(kExternalStringTag)); |
| 6142 __ Branch(&sequential_string, eq, t0, Operand(zero_reg)); |
| 6143 |
| 6144 // Handle external string. |
| 6145 // Rule out short external strings. |
| 6146 STATIC_CHECK(kShortExternalStringTag != 0); |
| 6147 __ And(t0, a1, Operand(kShortExternalStringTag)); |
| 6148 __ Branch(&runtime, ne, t0, Operand(zero_reg)); |
| 6149 __ lw(t1, FieldMemOperand(t1, ExternalString::kResourceDataOffset)); |
| 6150 // t1 already points to the first character of underlying string. |
| 6151 __ jmp(&allocate_result); |
| 6152 |
| 6153 __ bind(&sequential_string); |
| 6154 // Locate first character of underlying subject string. |
| 6155 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqAsciiString::kHeaderSize); |
| 6156 __ Addu(t1, t1, Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 6157 |
| 6158 __ bind(&allocate_result); |
| 6159 // Sequential acii string. Allocate the result. |
| 6160 STATIC_ASSERT((kAsciiStringTag & kStringEncodingMask) != 0); |
| 6161 __ And(t0, a1, Operand(kStringEncodingMask)); |
| 6162 __ Branch(&two_byte_sequential, eq, t0, Operand(zero_reg)); |
| 6163 |
| 6164 // Allocate and copy the resulting ascii string. |
| 6165 __ AllocateAsciiString(v0, a2, t0, t2, t3, &runtime); |
| 6166 |
| 6167 // Locate first character of substring to copy. |
| 6168 __ Addu(t1, t1, a3); |
| 6169 |
6151 // Locate first character of result. | 6170 // Locate first character of result. |
6152 __ Addu(a1, v0, Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); | 6171 __ Addu(a1, v0, Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
6153 | 6172 |
6154 // v0: result string | 6173 // v0: result string |
6155 // a1: first character of result string | 6174 // a1: first character of result string |
6156 // a2: result string length | 6175 // a2: result string length |
6157 // t1: first character of substring to copy | 6176 // t1: first character of substring to copy |
6158 STATIC_ASSERT((SeqAsciiString::kHeaderSize & kObjectAlignmentMask) == 0); | 6177 STATIC_ASSERT((SeqAsciiString::kHeaderSize & kObjectAlignmentMask) == 0); |
6159 StringHelper::GenerateCopyCharactersLong( | 6178 StringHelper::GenerateCopyCharactersLong( |
6160 masm, a1, t1, a2, a3, t0, t2, t3, t4, COPY_ASCII | DEST_ALWAYS_ALIGNED); | 6179 masm, a1, t1, a2, a3, t0, t2, t3, t4, COPY_ASCII | DEST_ALWAYS_ALIGNED); |
6161 __ jmp(&return_v0); | 6180 __ jmp(&return_v0); |
6162 | 6181 |
6163 __ bind(&non_ascii_flat); | 6182 // Allocate and copy the resulting two-byte string. |
6164 // a2: result string length | 6183 __ bind(&two_byte_sequential); |
6165 // t1: string | 6184 __ AllocateTwoByteString(v0, a2, t0, t2, t3, &runtime); |
6166 // t3: (a.k.a. from): from offset (smi) | |
6167 // Check for flat two byte string. | |
6168 | 6185 |
6169 // Locate 'from' character of string. | 6186 // Locate first character of substring to copy. |
6170 __ Addu(t1, v0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); | |
6171 // As "from" is a smi it is 2 times the value which matches the size of a two | |
6172 // byte character. | |
6173 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0); | 6187 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0); |
6174 __ Addu(t1, t1, Operand(from)); | 6188 __ sll(t0, a3, 1); |
6175 | 6189 __ Addu(t1, t1, t0); |
6176 // Allocate the result. | |
6177 __ AllocateTwoByteString(v0, a2, a1, a3, t0, &sub_string_runtime); | |
6178 | |
6179 // v0: result string | |
6180 // a2: result string length | |
6181 // t1: first character of substring to copy | |
6182 // Locate first character of result. | 6190 // Locate first character of result. |
6183 __ Addu(a1, v0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); | 6191 __ Addu(a1, v0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
6184 | 6192 |
6185 from = no_reg; | |
6186 | |
6187 // v0: result string. | 6193 // v0: result string. |
6188 // a1: first character of result. | 6194 // a1: first character of result. |
6189 // a2: result length. | 6195 // a2: result length. |
6190 // t1: first character of substring to copy. | 6196 // t1: first character of substring to copy. |
6191 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); | 6197 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
6192 StringHelper::GenerateCopyCharactersLong( | 6198 StringHelper::GenerateCopyCharactersLong( |
6193 masm, a1, t1, a2, a3, t0, t2, t3, t4, DEST_ALWAYS_ALIGNED); | 6199 masm, a1, t1, a2, a3, t0, t2, t3, t4, DEST_ALWAYS_ALIGNED); |
6194 __ jmp(&return_v0); | |
6195 | |
6196 if (FLAG_string_slices) { | |
6197 __ bind(&create_slice); | |
6198 // v0: original string | |
6199 // a1: instance type | |
6200 // a2: length | |
6201 // a3: from index (untagged smi) | |
6202 // t2 (a.k.a. to): to (smi) | |
6203 // t3 (a.k.a. from): from offset (smi) | |
6204 Label allocate_slice, sliced_string, seq_or_external_string; | |
6205 // If the string is not indirect, it can only be sequential or external. | |
6206 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); | |
6207 STATIC_ASSERT(kIsIndirectStringMask != 0); | |
6208 __ And(t4, a1, Operand(kIsIndirectStringMask)); | |
6209 // External string. Jump to runtime. | |
6210 __ Branch(&seq_or_external_string, eq, t4, Operand(zero_reg)); | |
6211 | |
6212 __ And(t4, a1, Operand(kSlicedNotConsMask)); | |
6213 __ Branch(&sliced_string, ne, t4, Operand(zero_reg)); | |
6214 // Cons string. Check whether it is flat, then fetch first part. | |
6215 __ lw(t1, FieldMemOperand(v0, ConsString::kSecondOffset)); | |
6216 __ LoadRoot(t5, Heap::kEmptyStringRootIndex); | |
6217 __ Branch(&sub_string_runtime, ne, t1, Operand(t5)); | |
6218 __ lw(t1, FieldMemOperand(v0, ConsString::kFirstOffset)); | |
6219 __ jmp(&allocate_slice); | |
6220 | |
6221 __ bind(&sliced_string); | |
6222 // Sliced string. Fetch parent and correct start index by offset. | |
6223 __ lw(t1, FieldMemOperand(v0, SlicedString::kOffsetOffset)); | |
6224 __ addu(t3, t3, t1); | |
6225 __ lw(t1, FieldMemOperand(v0, SlicedString::kParentOffset)); | |
6226 __ jmp(&allocate_slice); | |
6227 | |
6228 __ bind(&seq_or_external_string); | |
6229 // Sequential or external string. Just move string to the correct register. | |
6230 __ mov(t1, v0); | |
6231 | |
6232 __ bind(&allocate_slice); | |
6233 // a1: instance type of original string | |
6234 // a2: length | |
6235 // t1: underlying subject string | |
6236 // t3 (a.k.a. from): from offset (smi) | |
6237 // Allocate new sliced string. At this point we do not reload the instance | |
6238 // type including the string encoding because we simply rely on the info | |
6239 // provided by the original string. It does not matter if the original | |
6240 // string's encoding is wrong because we always have to recheck encoding of | |
6241 // the newly created string's parent anyways due to externalized strings. | |
6242 Label two_byte_slice, set_slice_header; | |
6243 STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); | |
6244 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); | |
6245 __ And(t4, a1, Operand(kStringEncodingMask)); | |
6246 __ Branch(&two_byte_slice, eq, t4, Operand(zero_reg)); | |
6247 __ AllocateAsciiSlicedString(v0, a2, a3, t0, &sub_string_runtime); | |
6248 __ jmp(&set_slice_header); | |
6249 __ bind(&two_byte_slice); | |
6250 __ AllocateTwoByteSlicedString(v0, a2, a3, t0, &sub_string_runtime); | |
6251 __ bind(&set_slice_header); | |
6252 __ sw(t3, FieldMemOperand(v0, SlicedString::kOffsetOffset)); | |
6253 __ sw(t1, FieldMemOperand(v0, SlicedString::kParentOffset)); | |
6254 } | |
6255 | 6200 |
6256 __ bind(&return_v0); | 6201 __ bind(&return_v0); |
| 6202 Counters* counters = masm->isolate()->counters(); |
6257 __ IncrementCounter(counters->sub_string_native(), 1, a3, t0); | 6203 __ IncrementCounter(counters->sub_string_native(), 1, a3, t0); |
6258 __ Addu(sp, sp, Operand(3 * kPointerSize)); | 6204 __ DropAndRet(3); |
6259 __ Ret(); | |
6260 | 6205 |
6261 // Just jump to runtime to create the sub string. | 6206 // Just jump to runtime to create the sub string. |
6262 __ bind(&sub_string_runtime); | 6207 __ bind(&runtime); |
6263 __ TailCallRuntime(Runtime::kSubString, 3, 1); | 6208 __ TailCallRuntime(Runtime::kSubString, 3, 1); |
6264 } | 6209 } |
6265 | 6210 |
6266 | 6211 |
6267 void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, | 6212 void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
6268 Register left, | 6213 Register left, |
6269 Register right, | 6214 Register right, |
6270 Register scratch1, | 6215 Register scratch1, |
6271 Register scratch2, | 6216 Register scratch2, |
6272 Register scratch3) { | 6217 Register scratch3) { |
(...skipping 1377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7650 __ Ret(USE_DELAY_SLOT); | 7595 __ Ret(USE_DELAY_SLOT); |
7651 __ mov(v0, a0); | 7596 __ mov(v0, a0); |
7652 } | 7597 } |
7653 | 7598 |
7654 | 7599 |
7655 #undef __ | 7600 #undef __ |
7656 | 7601 |
7657 } } // namespace v8::internal | 7602 } } // namespace v8::internal |
7658 | 7603 |
7659 #endif // V8_TARGET_ARCH_MIPS | 7604 #endif // V8_TARGET_ARCH_MIPS |
OLD | NEW |