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

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

Issue 2355793003: [stubs] Port SubStringStub to TurboFan (Closed)
Patch Set: Address comments 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/mips64/code-stubs-mips64.cc ('k') | src/s390/code-stubs-s390.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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_PPC 5 #if V8_TARGET_ARCH_PPC
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 2189 matching lines...) Expand 10 before | Expand all | Expand 10 after
2200 __ bind(&byte_loop); 2200 __ bind(&byte_loop);
2201 __ lbz(scratch, MemOperand(src)); 2201 __ lbz(scratch, MemOperand(src));
2202 __ addi(src, src, Operand(1)); 2202 __ addi(src, src, Operand(1));
2203 __ stb(scratch, MemOperand(dest)); 2203 __ stb(scratch, MemOperand(dest));
2204 __ addi(dest, dest, Operand(1)); 2204 __ addi(dest, dest, Operand(1));
2205 __ bdnz(&byte_loop); 2205 __ bdnz(&byte_loop);
2206 2206
2207 __ bind(&done); 2207 __ bind(&done);
2208 } 2208 }
2209 2209
2210
2211 void SubStringStub::Generate(MacroAssembler* masm) {
2212 Label runtime;
2213
2214 // Stack frame on entry.
2215 // lr: return address
2216 // sp[0]: to
2217 // sp[4]: from
2218 // sp[8]: string
2219
2220 // This stub is called from the native-call %_SubString(...), so
2221 // nothing can be assumed about the arguments. It is tested that:
2222 // "string" is a sequential string,
2223 // both "from" and "to" are smis, and
2224 // 0 <= from <= to <= string.length.
2225 // If any of these assumptions fail, we call the runtime system.
2226
2227 const int kToOffset = 0 * kPointerSize;
2228 const int kFromOffset = 1 * kPointerSize;
2229 const int kStringOffset = 2 * kPointerSize;
2230
2231 __ LoadP(r5, MemOperand(sp, kToOffset));
2232 __ LoadP(r6, MemOperand(sp, kFromOffset));
2233
2234 // If either to or from had the smi tag bit set, then fail to generic runtime
2235 __ JumpIfNotSmi(r5, &runtime);
2236 __ JumpIfNotSmi(r6, &runtime);
2237 __ SmiUntag(r5);
2238 __ SmiUntag(r6, SetRC);
2239 // Both r5 and r6 are untagged integers.
2240
2241 // We want to bailout to runtime here if From is negative.
2242 __ blt(&runtime, cr0); // From < 0.
2243
2244 __ cmpl(r6, r5);
2245 __ bgt(&runtime); // Fail if from > to.
2246 __ sub(r5, r5, r6);
2247
2248 // Make sure first argument is a string.
2249 __ LoadP(r3, MemOperand(sp, kStringOffset));
2250 __ JumpIfSmi(r3, &runtime);
2251 Condition is_string = masm->IsObjectStringType(r3, r4);
2252 __ b(NegateCondition(is_string), &runtime, cr0);
2253
2254 Label single_char;
2255 __ cmpi(r5, Operand(1));
2256 __ b(eq, &single_char);
2257
2258 // Short-cut for the case of trivial substring.
2259 Label return_r3;
2260 // r3: original string
2261 // r5: result string length
2262 __ LoadP(r7, FieldMemOperand(r3, String::kLengthOffset));
2263 __ SmiUntag(r0, r7);
2264 __ cmpl(r5, r0);
2265 // Return original string.
2266 __ beq(&return_r3);
2267 // Longer than original string's length or negative: unsafe arguments.
2268 __ bgt(&runtime);
2269 // Shorter than original string's length: an actual substring.
2270
2271 // Deal with different string types: update the index if necessary
2272 // and put the underlying string into r8.
2273 // r3: original string
2274 // r4: instance type
2275 // r5: length
2276 // r6: from index (untagged)
2277 Label underlying_unpacked, sliced_string, seq_or_external_string;
2278 // If the string is not indirect, it can only be sequential or external.
2279 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
2280 STATIC_ASSERT(kIsIndirectStringMask != 0);
2281 __ andi(r0, r4, Operand(kIsIndirectStringMask));
2282 __ beq(&seq_or_external_string, cr0);
2283
2284 __ andi(r0, r4, Operand(kSlicedNotConsMask));
2285 __ bne(&sliced_string, cr0);
2286 // Cons string. Check whether it is flat, then fetch first part.
2287 __ LoadP(r8, FieldMemOperand(r3, ConsString::kSecondOffset));
2288 __ CompareRoot(r8, Heap::kempty_stringRootIndex);
2289 __ bne(&runtime);
2290 __ LoadP(r8, FieldMemOperand(r3, ConsString::kFirstOffset));
2291 // Update instance type.
2292 __ LoadP(r4, FieldMemOperand(r8, HeapObject::kMapOffset));
2293 __ lbz(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset));
2294 __ b(&underlying_unpacked);
2295
2296 __ bind(&sliced_string);
2297 // Sliced string. Fetch parent and correct start index by offset.
2298 __ LoadP(r8, FieldMemOperand(r3, SlicedString::kParentOffset));
2299 __ LoadP(r7, FieldMemOperand(r3, SlicedString::kOffsetOffset));
2300 __ SmiUntag(r4, r7);
2301 __ add(r6, r6, r4); // Add offset to index.
2302 // Update instance type.
2303 __ LoadP(r4, FieldMemOperand(r8, HeapObject::kMapOffset));
2304 __ lbz(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset));
2305 __ b(&underlying_unpacked);
2306
2307 __ bind(&seq_or_external_string);
2308 // Sequential or external string. Just move string to the expected register.
2309 __ mr(r8, r3);
2310
2311 __ bind(&underlying_unpacked);
2312
2313 if (FLAG_string_slices) {
2314 Label copy_routine;
2315 // r8: underlying subject string
2316 // r4: instance type of underlying subject string
2317 // r5: length
2318 // r6: adjusted start index (untagged)
2319 __ cmpi(r5, Operand(SlicedString::kMinLength));
2320 // Short slice. Copy instead of slicing.
2321 __ blt(&copy_routine);
2322 // Allocate new sliced string. At this point we do not reload the instance
2323 // type including the string encoding because we simply rely on the info
2324 // provided by the original string. It does not matter if the original
2325 // string's encoding is wrong because we always have to recheck encoding of
2326 // the newly created string's parent anyways due to externalized strings.
2327 Label two_byte_slice, set_slice_header;
2328 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
2329 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
2330 __ andi(r0, r4, Operand(kStringEncodingMask));
2331 __ beq(&two_byte_slice, cr0);
2332 __ AllocateOneByteSlicedString(r3, r5, r9, r10, &runtime);
2333 __ b(&set_slice_header);
2334 __ bind(&two_byte_slice);
2335 __ AllocateTwoByteSlicedString(r3, r5, r9, r10, &runtime);
2336 __ bind(&set_slice_header);
2337 __ SmiTag(r6);
2338 __ StoreP(r8, FieldMemOperand(r3, SlicedString::kParentOffset), r0);
2339 __ StoreP(r6, FieldMemOperand(r3, SlicedString::kOffsetOffset), r0);
2340 __ b(&return_r3);
2341
2342 __ bind(&copy_routine);
2343 }
2344
2345 // r8: underlying subject string
2346 // r4: instance type of underlying subject string
2347 // r5: length
2348 // r6: adjusted start index (untagged)
2349 Label two_byte_sequential, sequential_string, allocate_result;
2350 STATIC_ASSERT(kExternalStringTag != 0);
2351 STATIC_ASSERT(kSeqStringTag == 0);
2352 __ andi(r0, r4, Operand(kExternalStringTag));
2353 __ beq(&sequential_string, cr0);
2354
2355 // Handle external string.
2356 // Rule out short external strings.
2357 STATIC_ASSERT(kShortExternalStringTag != 0);
2358 __ andi(r0, r4, Operand(kShortExternalStringTag));
2359 __ bne(&runtime, cr0);
2360 __ LoadP(r8, FieldMemOperand(r8, ExternalString::kResourceDataOffset));
2361 // r8 already points to the first character of underlying string.
2362 __ b(&allocate_result);
2363
2364 __ bind(&sequential_string);
2365 // Locate first character of underlying subject string.
2366 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2367 __ addi(r8, r8, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
2368
2369 __ bind(&allocate_result);
2370 // Sequential acii string. Allocate the result.
2371 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
2372 __ andi(r0, r4, Operand(kStringEncodingMask));
2373 __ beq(&two_byte_sequential, cr0);
2374
2375 // Allocate and copy the resulting one-byte string.
2376 __ AllocateOneByteString(r3, r5, r7, r9, r10, &runtime);
2377
2378 // Locate first character of substring to copy.
2379 __ add(r8, r8, r6);
2380 // Locate first character of result.
2381 __ addi(r4, r3, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
2382
2383 // r3: result string
2384 // r4: first character of result string
2385 // r5: result string length
2386 // r8: first character of substring to copy
2387 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
2388 StringHelper::GenerateCopyCharacters(masm, r4, r8, r5, r6,
2389 String::ONE_BYTE_ENCODING);
2390 __ b(&return_r3);
2391
2392 // Allocate and copy the resulting two-byte string.
2393 __ bind(&two_byte_sequential);
2394 __ AllocateTwoByteString(r3, r5, r7, r9, r10, &runtime);
2395
2396 // Locate first character of substring to copy.
2397 __ ShiftLeftImm(r4, r6, Operand(1));
2398 __ add(r8, r8, r4);
2399 // Locate first character of result.
2400 __ addi(r4, r3, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
2401
2402 // r3: result string.
2403 // r4: first character of result.
2404 // r5: result length.
2405 // r8: first character of substring to copy.
2406 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
2407 StringHelper::GenerateCopyCharacters(masm, r4, r8, r5, r6,
2408 String::TWO_BYTE_ENCODING);
2409
2410 __ bind(&return_r3);
2411 Counters* counters = isolate()->counters();
2412 __ IncrementCounter(counters->sub_string_native(), 1, r6, r7);
2413 __ Drop(3);
2414 __ Ret();
2415
2416 // Just jump to runtime to create the sub string.
2417 __ bind(&runtime);
2418 __ TailCallRuntime(Runtime::kSubString);
2419
2420 __ bind(&single_char);
2421 // r3: original string
2422 // r4: instance type
2423 // r5: length
2424 // r6: from index (untagged)
2425 __ SmiTag(r6, r6);
2426 StringCharAtGenerator generator(r3, r6, r5, r3, &runtime, &runtime, &runtime,
2427 RECEIVER_IS_STRING);
2428 generator.GenerateFast(masm);
2429 __ Drop(3);
2430 __ Ret();
2431 generator.SkipSlow(masm, &runtime);
2432 }
2433
2434 void ToStringStub::Generate(MacroAssembler* masm) { 2210 void ToStringStub::Generate(MacroAssembler* masm) {
2435 // The ToString stub takes one argument in r3. 2211 // The ToString stub takes one argument in r3.
2436 Label is_number; 2212 Label is_number;
2437 __ JumpIfSmi(r3, &is_number); 2213 __ JumpIfSmi(r3, &is_number);
2438 2214
2439 __ CompareObjectType(r3, r4, r4, FIRST_NONSTRING_TYPE); 2215 __ CompareObjectType(r3, r4, r4, FIRST_NONSTRING_TYPE);
2440 // r3: receiver 2216 // r3: receiver
2441 // r4: receiver instance type 2217 // r4: receiver instance type
2442 __ Ret(lt); 2218 __ Ret(lt);
2443 2219
(...skipping 2994 matching lines...) Expand 10 before | Expand all | Expand 10 after
5438 fp, (PropertyCallbackArguments::kReturnValueOffset + 3) * kPointerSize); 5214 fp, (PropertyCallbackArguments::kReturnValueOffset + 3) * kPointerSize);
5439 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, 5215 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5440 kStackUnwindSpace, NULL, return_value_operand, NULL); 5216 kStackUnwindSpace, NULL, return_value_operand, NULL);
5441 } 5217 }
5442 5218
5443 #undef __ 5219 #undef __
5444 } // namespace internal 5220 } // namespace internal
5445 } // namespace v8 5221 } // namespace v8
5446 5222
5447 #endif // V8_TARGET_ARCH_PPC 5223 #endif // V8_TARGET_ARCH_PPC
OLDNEW
« no previous file with comments | « src/mips64/code-stubs-mips64.cc ('k') | src/s390/code-stubs-s390.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698