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

Side by Side Diff: src/ia32/code-stubs-ia32.cc

Issue 8889012: Avoid bailing out to runtime for short substrings. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/string-external-cached.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 6081 matching lines...) Expand 10 before | Expand all | Expand 10 after
6092 __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index. 6092 __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index.
6093 __ JumpIfNotSmi(edx, &runtime); 6093 __ JumpIfNotSmi(edx, &runtime);
6094 __ sub(ecx, edx); 6094 __ sub(ecx, edx);
6095 __ cmp(ecx, FieldOperand(eax, String::kLengthOffset)); 6095 __ cmp(ecx, FieldOperand(eax, String::kLengthOffset));
6096 Label return_eax; 6096 Label return_eax;
6097 __ j(equal, &return_eax); 6097 __ j(equal, &return_eax);
6098 // Special handling of sub-strings of length 1 and 2. One character strings 6098 // Special handling of sub-strings of length 1 and 2. One character strings
6099 // are handled in the runtime system (looked up in the single character 6099 // are handled in the runtime system (looked up in the single character
6100 // cache). Two character strings are looked for in the symbol cache. 6100 // cache). Two character strings are looked for in the symbol cache.
6101 __ SmiUntag(ecx); // Result length is no longer smi. 6101 __ SmiUntag(ecx); // Result length is no longer smi.
6102 __ cmp(ecx, 2); 6102 __ cmp(ecx, 2);
rossberg 2011/12/08 15:36:32 Nit: could avoid the SmiUntag here and SmiTag late
6103 __ j(greater, &result_longer_than_two); 6103 __ j(greater, &result_longer_than_two);
6104 __ j(less, &runtime); 6104 __ j(less, &runtime);
6105 6105
6106 // Sub string of length 2 requested. 6106 // Sub string of length 2 requested.
6107 // eax: string 6107 // eax: string
6108 // ebx: instance type 6108 // ebx: instance type
6109 // ecx: sub string length (value is 2) 6109 // ecx: sub string length (value is 2)
6110 // edx: from index (smi) 6110 // edx: from index (smi)
6111 __ JumpIfInstanceTypeIsNotSequentialAscii(ebx, ebx, &runtime); 6111 __ JumpIfInstanceTypeIsNotSequentialAscii(ebx, ebx, &runtime);
6112 6112
6113 // Get the two characters forming the sub string. 6113 // Get the two characters forming the sub string.
6114 __ SmiUntag(edx); // From index is no longer smi. 6114 __ SmiUntag(edx); // From index is no longer smi.
6115 __ movzx_b(ebx, FieldOperand(eax, edx, times_1, SeqAsciiString::kHeaderSize)); 6115 __ movzx_b(ebx, FieldOperand(eax, edx, times_1, SeqAsciiString::kHeaderSize));
6116 __ movzx_b(ecx, 6116 __ movzx_b(ecx,
6117 FieldOperand(eax, edx, times_1, SeqAsciiString::kHeaderSize + 1)); 6117 FieldOperand(eax, edx, times_1, SeqAsciiString::kHeaderSize + 1));
6118 6118
6119 // Try to lookup two character string in symbol table. 6119 // Try to lookup two character string in symbol table.
6120 Label make_two_character_string; 6120 Label make_two_character_string;
6121 StringHelper::GenerateTwoCharacterSymbolTableProbe( 6121 StringHelper::GenerateTwoCharacterSymbolTableProbe(
6122 masm, ebx, ecx, eax, edx, edi, 6122 masm, ebx, ecx, eax, edx, edi,
6123 &make_two_character_string, &make_two_character_string); 6123 &make_two_character_string, &make_two_character_string);
6124 __ ret(3 * kPointerSize); 6124 __ ret(3 * kPointerSize);
6125 6125
6126 __ bind(&make_two_character_string); 6126 __ bind(&make_two_character_string);
6127 // Setup registers for allocating the two character string. 6127 // Setup registers for allocating the two character string.
6128 __ mov(eax, Operand(esp, 3 * kPointerSize)); 6128 __ mov(eax, Operand(esp, 3 * kPointerSize));
6129 __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); 6129 __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset));
6130 __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); 6130 __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset));
6131 __ Set(ecx, Immediate(2)); 6131 __ Set(ecx, Immediate(2));
6132 __ mov(edx, Operand(esp, 2 * kPointerSize)); // Load index.
6133
6134 __ bind(&result_longer_than_two);
6135 // eax: string
6136 // ebx: instance type
6137 // ecx: sub string length
6138 // edx: from index (smi)
6139 // Deal with different string types: update the index if necessary
6140 // and put the underlying string into edi.
6141 Label underlying_unpacked, sliced_string, seq_or_external_string;
6142 // If the string is not indirect, it can only be sequential or external.
6143 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
6144 STATIC_ASSERT(kIsIndirectStringMask != 0);
6145 __ test(ebx, Immediate(kIsIndirectStringMask));
6146 __ j(zero, &seq_or_external_string, Label::kNear);
6147
6148 Factory* factory = masm->isolate()->factory();
6149 __ test(ebx, Immediate(kSlicedNotConsMask));
6150 __ j(not_zero, &sliced_string, Label::kNear);
6151 // Cons string. Check whether it is flat, then fetch first part.
rossberg 2011/12/08 15:36:32 Nit: Maybe add comment about the flat cons invaria
6152 __ cmp(FieldOperand(eax, ConsString::kSecondOffset),
6153 factory->empty_string());
6154 __ j(not_equal, &runtime);
6155 __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset));
6156 // Update instance type.
6157 __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset));
6158 __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset));
6159 __ jmp(&underlying_unpacked, Label::kNear);
6160
6161 __ bind(&sliced_string);
6162 // Sliced string. Fetch parent and adjust start index by offset.
6163 __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset));
6164 __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset));
6165 // Update instance type.
6166 __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset));
6167 __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset));
6168 __ jmp(&underlying_unpacked, Label::kNear);
6169
6170 __ bind(&seq_or_external_string);
6171 // Sequential or external string. Just move string to the correct register.
6172 __ mov(edi, eax);
6173
6174 __ bind(&underlying_unpacked);
6132 6175
6133 if (FLAG_string_slices) { 6176 if (FLAG_string_slices) {
6134 Label copy_routine; 6177 Label copy_routine;
6135 // If coming from the make_two_character_string path, the string 6178 // edi: underlying subject string
6136 // is too short to be sliced anyways. 6179 // ebx: instance type of original subject string
6137 STATIC_ASSERT(2 < SlicedString::kMinLength); 6180 // edx: adjusted start index (smi)
6138 __ jmp(&copy_routine); 6181 // ecx: length
6139 __ bind(&result_longer_than_two);
6140
6141 // eax: string
6142 // ebx: instance type
6143 // ecx: sub string length
6144 // edx: from index (smi)
6145 Label allocate_slice, sliced_string, seq_or_external_string;
6146 __ cmp(ecx, SlicedString::kMinLength); 6182 __ cmp(ecx, SlicedString::kMinLength);
6147 // Short slice. Copy instead of slicing. 6183 // Short slice. Copy instead of slicing.
6148 __ j(less, &copy_routine); 6184 __ j(less, &copy_routine);
6149 // If the string is not indirect, it can only be sequential or external.
6150 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
6151 STATIC_ASSERT(kIsIndirectStringMask != 0);
6152 __ test(ebx, Immediate(kIsIndirectStringMask));
6153 __ j(zero, &seq_or_external_string, Label::kNear);
6154
6155 Factory* factory = masm->isolate()->factory();
6156 __ test(ebx, Immediate(kSlicedNotConsMask));
6157 __ j(not_zero, &sliced_string, Label::kNear);
6158 // Cons string. Check whether it is flat, then fetch first part.
6159 __ cmp(FieldOperand(eax, ConsString::kSecondOffset),
6160 factory->empty_string());
6161 __ j(not_equal, &runtime);
6162 __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset));
6163 __ jmp(&allocate_slice, Label::kNear);
6164
6165 __ bind(&sliced_string);
6166 // Sliced string. Fetch parent and correct start index by offset.
6167 __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset));
6168 __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset));
6169 __ jmp(&allocate_slice, Label::kNear);
6170
6171 __ bind(&seq_or_external_string);
6172 // Sequential or external string. Just move string to the correct register.
6173 __ mov(edi, eax);
6174
6175 __ bind(&allocate_slice);
6176 // edi: underlying subject string
6177 // ebx: instance type of original subject string
6178 // edx: offset
6179 // ecx: length
6180 // Allocate new sliced string. At this point we do not reload the instance 6185 // Allocate new sliced string. At this point we do not reload the instance
6181 // type including the string encoding because we simply rely on the info 6186 // type including the string encoding because we simply rely on the info
6182 // provided by the original string. It does not matter if the original 6187 // provided by the original string. It does not matter if the original
6183 // string's encoding is wrong because we always have to recheck encoding of 6188 // string's encoding is wrong because we always have to recheck encoding of
6184 // the newly created string's parent anyways due to externalized strings. 6189 // the newly created string's parent anyways due to externalized strings.
6185 Label two_byte_slice, set_slice_header; 6190 Label two_byte_slice, set_slice_header;
6186 STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); 6191 STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0);
6187 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); 6192 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
6188 __ test(ebx, Immediate(kStringEncodingMask)); 6193 __ test(ebx, Immediate(kStringEncodingMask));
6189 __ j(zero, &two_byte_slice, Label::kNear); 6194 __ j(zero, &two_byte_slice, Label::kNear);
6190 __ AllocateAsciiSlicedString(eax, ebx, no_reg, &runtime); 6195 __ AllocateAsciiSlicedString(eax, ebx, no_reg, &runtime);
6191 __ jmp(&set_slice_header, Label::kNear); 6196 __ jmp(&set_slice_header, Label::kNear);
6192 __ bind(&two_byte_slice); 6197 __ bind(&two_byte_slice);
6193 __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime); 6198 __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime);
6194 __ bind(&set_slice_header); 6199 __ bind(&set_slice_header);
6195 __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx); 6200 __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx);
6196 __ SmiTag(ecx); 6201 __ SmiTag(ecx);
6197 __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx); 6202 __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx);
6198 __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi); 6203 __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi);
6199 __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset), 6204 __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset),
6200 Immediate(String::kEmptyHashField)); 6205 Immediate(String::kEmptyHashField));
6201 __ jmp(&return_eax); 6206 __ jmp(&return_eax);
6202 6207
6203 __ bind(&copy_routine); 6208 __ bind(&copy_routine);
6204 } else {
6205 __ bind(&result_longer_than_two);
6206 } 6209 }
6207 6210
6208 // eax: string 6211 // edi: underlying subject string
6209 // ebx: instance type 6212 // ebx: instance type of original subject string
6210 // ecx: result string length 6213 // edx: adjusted start index (smi)
6211 // Check for flat ascii string 6214 // ecx: length
6212 Label non_ascii_flat; 6215 // The subject string can only be external or sequential string of either
6213 __ JumpIfInstanceTypeIsNotSequentialAscii(ebx, ebx, &non_ascii_flat); 6216 // encoding at this point.
6217 Label two_byte_sequential, runtime_drop_two, sequential_string;
6218 STATIC_ASSERT(kExternalStringTag != 0);
6219 STATIC_ASSERT(kSeqStringTag == 0);
6220 __ test_b(ebx, kExternalStringTag);
6221 __ j(zero, &sequential_string);
6214 6222
6215 // Allocate the result. 6223 // Handle external string.
6216 __ AllocateAsciiString(eax, ecx, ebx, edx, edi, &runtime); 6224 Label ascii_external, done;
6225 // Rule out short external strings.
6226 STATIC_CHECK(kShortExternalStringTag != 0);
6227 __ test_b(ebx, kShortExternalStringMask);
6228 __ j(not_zero, &runtime);
6229 __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset));
6230 // Move the pointer so that offset-wise, it looks like a sequential string.
6231 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqAsciiString::kHeaderSize);
6232 __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
6233
6234 __ bind(&sequential_string);
6235 // Stash away (adjusted) index and (underlying) string.
6236 __ push(edx);
6237 __ push(edi);
6238 STATIC_ASSERT((kAsciiStringTag & kStringEncodingMask) != 0);
6239 __ test_b(ebx, kStringEncodingMask);
6240 __ j(zero, &two_byte_sequential);
6241
6242 // Sequential ascii string. Allocate the result.
6243 __ AllocateAsciiString(eax, ecx, ebx, edx, edi, &runtime_drop_two);
6217 6244
6218 // eax: result string 6245 // eax: result string
6219 // ecx: result string length 6246 // ecx: result string length
6220 __ mov(edx, esi); // esi used by following code. 6247 __ mov(edx, esi); // esi used by following code.
6221 // Locate first character of result. 6248 // Locate first character of result.
6222 __ mov(edi, eax); 6249 __ mov(edi, eax);
6223 __ add(edi, Immediate(SeqAsciiString::kHeaderSize - kHeapObjectTag)); 6250 __ add(edi, Immediate(SeqAsciiString::kHeaderSize - kHeapObjectTag));
6224 // Load string argument and locate character of sub string start. 6251 // Load string argument and locate character of sub string start.
6225 __ mov(esi, Operand(esp, 3 * kPointerSize)); 6252 __ pop(esi);
6226 __ add(esi, Immediate(SeqAsciiString::kHeaderSize - kHeapObjectTag)); 6253 __ pop(ebx);
6227 __ mov(ebx, Operand(esp, 2 * kPointerSize)); // from
6228 __ SmiUntag(ebx); 6254 __ SmiUntag(ebx);
6229 __ add(esi, ebx); 6255 __ lea(esi, FieldOperand(esi, ebx, times_1, SeqAsciiString::kHeaderSize));
6230 6256
6231 // eax: result string 6257 // eax: result string
6232 // ecx: result length 6258 // ecx: result length
6233 // edx: original value of esi 6259 // edx: original value of esi
6234 // edi: first character of result 6260 // edi: first character of result
6235 // esi: character of sub string start 6261 // esi: character of sub string start
6236 StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true); 6262 StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true);
6237 __ mov(esi, edx); // Restore esi. 6263 __ mov(esi, edx); // Restore esi.
6238 Counters* counters = masm->isolate()->counters(); 6264 Counters* counters = masm->isolate()->counters();
6239 __ IncrementCounter(counters->sub_string_native(), 1); 6265 __ IncrementCounter(counters->sub_string_native(), 1);
6240 __ ret(3 * kPointerSize); 6266 __ ret(3 * kPointerSize);
6241 6267
6242 __ bind(&non_ascii_flat); 6268 __ bind(&two_byte_sequential);
6243 // eax: string 6269 // Sequential two-byte string. Allocate the result.
6244 // ebx: instance type & kStringRepresentationMask | kStringEncodingMask 6270 __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two);
6245 // ecx: result string length
6246 // Check for flat two byte string
6247 __ cmp(ebx, kSeqStringTag | kTwoByteStringTag);
6248 __ j(not_equal, &runtime);
6249
6250 // Allocate the result.
6251 __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime);
6252 6271
6253 // eax: result string 6272 // eax: result string
6254 // ecx: result string length 6273 // ecx: result string length
6255 __ mov(edx, esi); // esi used by following code. 6274 __ mov(edx, esi); // esi used by following code.
6256 // Locate first character of result. 6275 // Locate first character of result.
6257 __ mov(edi, eax); 6276 __ mov(edi, eax);
6258 __ add(edi, 6277 __ add(edi,
6259 Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); 6278 Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
6260 // Load string argument and locate character of sub string start. 6279 // Load string argument and locate character of sub string start.
6261 __ mov(esi, Operand(esp, 3 * kPointerSize)); 6280 __ pop(esi);
6262 __ add(esi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); 6281 __ pop(ebx);
6263 __ mov(ebx, Operand(esp, 2 * kPointerSize)); // from
6264 // As from is a smi it is 2 times the value which matches the size of a two 6282 // As from is a smi it is 2 times the value which matches the size of a two
6265 // byte character. 6283 // byte character.
6266 STATIC_ASSERT(kSmiTag == 0); 6284 STATIC_ASSERT(kSmiTag == 0);
6267 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); 6285 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
6268 __ add(esi, ebx); 6286 __ lea(esi, FieldOperand(esi, ebx, times_1, SeqTwoByteString::kHeaderSize));
6269 6287
6270 // eax: result string 6288 // eax: result string
6271 // ecx: result length 6289 // ecx: result length
6272 // edx: original value of esi 6290 // edx: original value of esi
6273 // edi: first character of result 6291 // edi: first character of result
6274 // esi: character of sub string start 6292 // esi: character of sub string start
6275 StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false); 6293 StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false);
6276 __ mov(esi, edx); // Restore esi. 6294 __ mov(esi, edx); // Restore esi.
6277 6295
6278 __ bind(&return_eax); 6296 __ bind(&return_eax);
6279 __ IncrementCounter(counters->sub_string_native(), 1); 6297 __ IncrementCounter(counters->sub_string_native(), 1);
6280 __ ret(3 * kPointerSize); 6298 __ ret(3 * kPointerSize);
6281 6299
6300 // Drop pushed values on the stack before tail call.
6301 __ bind(&runtime_drop_two);
6302 __ Drop(2);
6303
6282 // Just jump to runtime to create the sub string. 6304 // Just jump to runtime to create the sub string.
6283 __ bind(&runtime); 6305 __ bind(&runtime);
6284 __ TailCallRuntime(Runtime::kSubString, 3, 1); 6306 __ TailCallRuntime(Runtime::kSubString, 3, 1);
6285 } 6307 }
6286 6308
6287 6309
6288 void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, 6310 void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm,
6289 Register left, 6311 Register left,
6290 Register right, 6312 Register right,
6291 Register scratch1, 6313 Register scratch1,
(...skipping 981 matching lines...) Expand 10 before | Expand all | Expand 10 after
7273 false); 7295 false);
7274 __ pop(edx); 7296 __ pop(edx);
7275 __ ret(0); 7297 __ ret(0);
7276 } 7298 }
7277 7299
7278 #undef __ 7300 #undef __
7279 7301
7280 } } // namespace v8::internal 7302 } } // namespace v8::internal
7281 7303
7282 #endif // V8_TARGET_ARCH_IA32 7304 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/string-external-cached.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698