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

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

Issue 2365413002: Revert of [stubs] Port SubStringStub to TurboFan (Closed)
Patch Set: Created 4 years, 2 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 unified diff | Download patch
« no previous file with comments | « src/ia32/code-stubs-ia32.cc ('k') | src/mips64/code-stubs-mips64.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #if V8_TARGET_ARCH_MIPS 5 #if V8_TARGET_ARCH_MIPS
6 6
7 #include "src/code-stubs.h" 7 #include "src/code-stubs.h"
8 #include "src/api-arguments.h" 8 #include "src/api-arguments.h"
9 #include "src/base/bits.h" 9 #include "src/base/bits.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 2250 matching lines...) Expand 10 before | Expand all | Expand 10 after
2261 __ lbu(scratch, MemOperand(src)); 2261 __ lbu(scratch, MemOperand(src));
2262 __ Addu(src, src, Operand(1)); 2262 __ Addu(src, src, Operand(1));
2263 __ sb(scratch, MemOperand(dest)); 2263 __ sb(scratch, MemOperand(dest));
2264 __ Addu(dest, dest, Operand(1)); 2264 __ Addu(dest, dest, Operand(1));
2265 __ bind(&loop_entry); 2265 __ bind(&loop_entry);
2266 __ Branch(&loop, lt, dest, Operand(limit)); 2266 __ Branch(&loop, lt, dest, Operand(limit));
2267 2267
2268 __ bind(&done); 2268 __ bind(&done);
2269 } 2269 }
2270 2270
2271
2272 void SubStringStub::Generate(MacroAssembler* masm) {
2273 Label runtime;
2274 // Stack frame on entry.
2275 // ra: return address
2276 // sp[0]: to
2277 // sp[4]: from
2278 // sp[8]: string
2279
2280 // This stub is called from the native-call %_SubString(...), so
2281 // nothing can be assumed about the arguments. It is tested that:
2282 // "string" is a sequential string,
2283 // both "from" and "to" are smis, and
2284 // 0 <= from <= to <= string.length.
2285 // If any of these assumptions fail, we call the runtime system.
2286
2287 const int kToOffset = 0 * kPointerSize;
2288 const int kFromOffset = 1 * kPointerSize;
2289 const int kStringOffset = 2 * kPointerSize;
2290
2291 __ lw(a2, MemOperand(sp, kToOffset));
2292 __ lw(a3, MemOperand(sp, kFromOffset));
2293 STATIC_ASSERT(kFromOffset == kToOffset + 4);
2294 STATIC_ASSERT(kSmiTag == 0);
2295 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2296
2297 // Utilize delay slots. SmiUntag doesn't emit a jump, everything else is
2298 // safe in this case.
2299 __ UntagAndJumpIfNotSmi(a2, a2, &runtime);
2300 __ UntagAndJumpIfNotSmi(a3, a3, &runtime);
2301 // Both a2 and a3 are untagged integers.
2302
2303 __ Branch(&runtime, lt, a3, Operand(zero_reg)); // From < 0.
2304
2305 __ Branch(&runtime, gt, a3, Operand(a2)); // Fail if from > to.
2306 __ Subu(a2, a2, a3);
2307
2308 // Make sure first argument is a string.
2309 __ lw(v0, MemOperand(sp, kStringOffset));
2310 __ JumpIfSmi(v0, &runtime);
2311 __ lw(a1, FieldMemOperand(v0, HeapObject::kMapOffset));
2312 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
2313 __ And(t0, a1, Operand(kIsNotStringMask));
2314
2315 __ Branch(&runtime, ne, t0, Operand(zero_reg));
2316
2317 Label single_char;
2318 __ Branch(&single_char, eq, a2, Operand(1));
2319
2320 // Short-cut for the case of trivial substring.
2321 Label return_v0;
2322 // v0: original string
2323 // a2: result string length
2324 __ lw(t0, FieldMemOperand(v0, String::kLengthOffset));
2325 __ sra(t0, t0, 1);
2326 // Return original string.
2327 __ Branch(&return_v0, eq, a2, Operand(t0));
2328 // Longer than original string's length or negative: unsafe arguments.
2329 __ Branch(&runtime, hi, a2, Operand(t0));
2330 // Shorter than original string's length: an actual substring.
2331
2332 // Deal with different string types: update the index if necessary
2333 // and put the underlying string into t1.
2334 // v0: original string
2335 // a1: instance type
2336 // a2: length
2337 // a3: from index (untagged)
2338 Label underlying_unpacked, sliced_string, seq_or_external_string;
2339 // If the string is not indirect, it can only be sequential or external.
2340 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
2341 STATIC_ASSERT(kIsIndirectStringMask != 0);
2342 __ And(t0, a1, Operand(kIsIndirectStringMask));
2343 __ Branch(USE_DELAY_SLOT, &seq_or_external_string, eq, t0, Operand(zero_reg));
2344 // t0 is used as a scratch register and can be overwritten in either case.
2345 __ And(t0, a1, Operand(kSlicedNotConsMask));
2346 __ Branch(&sliced_string, ne, t0, Operand(zero_reg));
2347 // Cons string. Check whether it is flat, then fetch first part.
2348 __ lw(t1, FieldMemOperand(v0, ConsString::kSecondOffset));
2349 __ LoadRoot(t0, Heap::kempty_stringRootIndex);
2350 __ Branch(&runtime, ne, t1, Operand(t0));
2351 __ lw(t1, FieldMemOperand(v0, ConsString::kFirstOffset));
2352 // Update instance type.
2353 __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset));
2354 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
2355 __ jmp(&underlying_unpacked);
2356
2357 __ bind(&sliced_string);
2358 // Sliced string. Fetch parent and correct start index by offset.
2359 __ lw(t1, FieldMemOperand(v0, SlicedString::kParentOffset));
2360 __ lw(t0, FieldMemOperand(v0, SlicedString::kOffsetOffset));
2361 __ sra(t0, t0, 1); // Add offset to index.
2362 __ Addu(a3, a3, t0);
2363 // Update instance type.
2364 __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset));
2365 __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset));
2366 __ jmp(&underlying_unpacked);
2367
2368 __ bind(&seq_or_external_string);
2369 // Sequential or external string. Just move string to the expected register.
2370 __ mov(t1, v0);
2371
2372 __ bind(&underlying_unpacked);
2373
2374 if (FLAG_string_slices) {
2375 Label copy_routine;
2376 // t1: underlying subject string
2377 // a1: instance type of underlying subject string
2378 // a2: length
2379 // a3: adjusted start index (untagged)
2380 // Short slice. Copy instead of slicing.
2381 __ Branch(&copy_routine, lt, a2, Operand(SlicedString::kMinLength));
2382 // Allocate new sliced string. At this point we do not reload the instance
2383 // type including the string encoding because we simply rely on the info
2384 // provided by the original string. It does not matter if the original
2385 // string's encoding is wrong because we always have to recheck encoding of
2386 // the newly created string's parent anyways due to externalized strings.
2387 Label two_byte_slice, set_slice_header;
2388 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
2389 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
2390 __ And(t0, a1, Operand(kStringEncodingMask));
2391 __ Branch(&two_byte_slice, eq, t0, Operand(zero_reg));
2392 __ AllocateOneByteSlicedString(v0, a2, t2, t3, &runtime);
2393 __ jmp(&set_slice_header);
2394 __ bind(&two_byte_slice);
2395 __ AllocateTwoByteSlicedString(v0, a2, t2, t3, &runtime);
2396 __ bind(&set_slice_header);
2397 __ sll(a3, a3, 1);
2398 __ sw(t1, FieldMemOperand(v0, SlicedString::kParentOffset));
2399 __ sw(a3, FieldMemOperand(v0, SlicedString::kOffsetOffset));
2400 __ jmp(&return_v0);
2401
2402 __ bind(&copy_routine);
2403 }
2404
2405 // t1: underlying subject string
2406 // a1: instance type of underlying subject string
2407 // a2: length
2408 // a3: adjusted start index (untagged)
2409 Label two_byte_sequential, sequential_string, allocate_result;
2410 STATIC_ASSERT(kExternalStringTag != 0);
2411 STATIC_ASSERT(kSeqStringTag == 0);
2412 __ And(t0, a1, Operand(kExternalStringTag));
2413 __ Branch(&sequential_string, eq, t0, Operand(zero_reg));
2414
2415 // Handle external string.
2416 // Rule out short external strings.
2417 STATIC_ASSERT(kShortExternalStringTag != 0);
2418 __ And(t0, a1, Operand(kShortExternalStringTag));
2419 __ Branch(&runtime, ne, t0, Operand(zero_reg));
2420 __ lw(t1, FieldMemOperand(t1, ExternalString::kResourceDataOffset));
2421 // t1 already points to the first character of underlying string.
2422 __ jmp(&allocate_result);
2423
2424 __ bind(&sequential_string);
2425 // Locate first character of underlying subject string.
2426 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2427 __ Addu(t1, t1, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
2428
2429 __ bind(&allocate_result);
2430 // Sequential acii string. Allocate the result.
2431 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
2432 __ And(t0, a1, Operand(kStringEncodingMask));
2433 __ Branch(&two_byte_sequential, eq, t0, Operand(zero_reg));
2434
2435 // Allocate and copy the resulting ASCII string.
2436 __ AllocateOneByteString(v0, a2, t0, t2, t3, &runtime);
2437
2438 // Locate first character of substring to copy.
2439 __ Addu(t1, t1, a3);
2440
2441 // Locate first character of result.
2442 __ Addu(a1, v0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
2443
2444 // v0: result string
2445 // a1: first character of result string
2446 // a2: result string length
2447 // t1: first character of substring to copy
2448 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
2449 StringHelper::GenerateCopyCharacters(
2450 masm, a1, t1, a2, a3, String::ONE_BYTE_ENCODING);
2451 __ jmp(&return_v0);
2452
2453 // Allocate and copy the resulting two-byte string.
2454 __ bind(&two_byte_sequential);
2455 __ AllocateTwoByteString(v0, a2, t0, t2, t3, &runtime);
2456
2457 // Locate first character of substring to copy.
2458 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
2459 __ Lsa(t1, t1, a3, 1);
2460 // Locate first character of result.
2461 __ Addu(a1, v0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
2462
2463 // v0: result string.
2464 // a1: first character of result.
2465 // a2: result length.
2466 // t1: first character of substring to copy.
2467 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
2468 StringHelper::GenerateCopyCharacters(
2469 masm, a1, t1, a2, a3, String::TWO_BYTE_ENCODING);
2470
2471 __ bind(&return_v0);
2472 Counters* counters = isolate()->counters();
2473 __ IncrementCounter(counters->sub_string_native(), 1, a3, t0);
2474 __ DropAndRet(3);
2475
2476 // Just jump to runtime to create the sub string.
2477 __ bind(&runtime);
2478 __ TailCallRuntime(Runtime::kSubString);
2479
2480 __ bind(&single_char);
2481 // v0: original string
2482 // a1: instance type
2483 // a2: length
2484 // a3: from index (untagged)
2485 __ SmiTag(a3, a3);
2486 StringCharAtGenerator generator(v0, a3, a2, v0, &runtime, &runtime, &runtime,
2487 RECEIVER_IS_STRING);
2488 generator.GenerateFast(masm);
2489 __ DropAndRet(3);
2490 generator.SkipSlow(masm, &runtime);
2491 }
2492
2493
2271 void ToStringStub::Generate(MacroAssembler* masm) { 2494 void ToStringStub::Generate(MacroAssembler* masm) {
2272 // The ToString stub takes on argument in a0. 2495 // The ToString stub takes on argument in a0.
2273 Label is_number; 2496 Label is_number;
2274 __ JumpIfSmi(a0, &is_number); 2497 __ JumpIfSmi(a0, &is_number);
2275 2498
2276 Label not_string; 2499 Label not_string;
2277 __ GetObjectType(a0, a1, a1); 2500 __ GetObjectType(a0, a1, a1);
2278 // a0: receiver 2501 // a0: receiver
2279 // a1: receiver instance type 2502 // a1: receiver instance type
2280 __ Branch(&not_string, ge, a1, Operand(FIRST_NONSTRING_TYPE)); 2503 __ Branch(&not_string, ge, a1, Operand(FIRST_NONSTRING_TYPE));
(...skipping 2860 matching lines...) Expand 10 before | Expand all | Expand 10 after
5141 kStackUnwindSpace, kInvalidStackOffset, 5364 kStackUnwindSpace, kInvalidStackOffset,
5142 return_value_operand, NULL); 5365 return_value_operand, NULL);
5143 } 5366 }
5144 5367
5145 #undef __ 5368 #undef __
5146 5369
5147 } // namespace internal 5370 } // namespace internal
5148 } // namespace v8 5371 } // namespace v8
5149 5372
5150 #endif // V8_TARGET_ARCH_MIPS 5373 #endif // V8_TARGET_ARCH_MIPS
OLDNEW
« no previous file with comments | « src/ia32/code-stubs-ia32.cc ('k') | src/mips64/code-stubs-mips64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698