OLD | NEW |
---|---|
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 #include "src/code-stub-assembler.h" | 5 #include "src/code-stub-assembler.h" |
6 #include "src/code-factory.h" | 6 #include "src/code-factory.h" |
7 #include "src/frames-inl.h" | 7 #include "src/frames-inl.h" |
8 #include "src/frames.h" | 8 #include "src/frames.h" |
9 #include "src/ic/handler-configuration.h" | 9 #include "src/ic/handler-configuration.h" |
10 #include "src/ic/stub-cache.h" | 10 #include "src/ic/stub-cache.h" |
(...skipping 2411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2422 MachineRepresentation::kWord16, result, | 2422 MachineRepresentation::kWord16, result, |
2423 IntPtrConstant(SeqTwoByteString::kHeaderSize - kHeapObjectTag), code); | 2423 IntPtrConstant(SeqTwoByteString::kHeaderSize - kHeapObjectTag), code); |
2424 var_result.Bind(result); | 2424 var_result.Bind(result); |
2425 Goto(&if_done); | 2425 Goto(&if_done); |
2426 } | 2426 } |
2427 | 2427 |
2428 Bind(&if_done); | 2428 Bind(&if_done); |
2429 return var_result.value(); | 2429 return var_result.value(); |
2430 } | 2430 } |
2431 | 2431 |
2432 Node* CodeStubAssembler::StringFromCodePointAt(Node* string, Node* length, | |
Benedikt Meurer
2016/09/22 03:48:23
I'd prefer to have a helper method StringFromCodeP
caitp
2016/09/22 13:26:21
The main reason I've put this in CodeStubAssembler
Benedikt Meurer
2016/09/23 03:46:24
I'd be fine with __ if it improves readability (an
caitp
2016/09/23 10:14:28
Acknowledged, but maybe that will be a cleanup fol
| |
2433 Node* index) { | |
2434 Label return_result(this); | |
2435 Variable var_result(this, MachineRepresentation::kTagged); | |
2436 var_result.Bind(UndefinedConstant()); | |
2437 | |
2438 Node* string_instance_type = LoadInstanceType(string); | |
2439 | |
2440 Label if_stringissequential(this), if_stringisexternal(this); | |
2441 Branch(Word32Equal(Word32And(string_instance_type, | |
2442 Int32Constant(kStringRepresentationMask)), | |
2443 Int32Constant(kSeqStringTag)), | |
2444 &if_stringissequential, &if_stringisexternal); | |
2445 | |
2446 Bind(&if_stringissequential); | |
2447 { | |
2448 Label if_stringisonebyte(this), if_stringistwobyte(this); | |
2449 Branch(Word32Equal(Word32And(string_instance_type, | |
2450 Int32Constant(kStringEncodingMask)), | |
2451 Int32Constant(kOneByteStringTag)), | |
2452 &if_stringisonebyte, &if_stringistwobyte); | |
2453 | |
2454 Bind(&if_stringisonebyte); | |
2455 { | |
2456 Node* ch = | |
2457 Load(MachineType::Uint8(), string, | |
2458 IntPtrAdd(index, IntPtrConstant(SeqOneByteString::kHeaderSize - | |
2459 kHeapObjectTag))); | |
2460 Node* result = AllocateSeqOneByteString(1); | |
2461 StoreNoWriteBarrier( | |
2462 MachineRepresentation::kWord8, result, | |
2463 IntPtrConstant(SeqOneByteString::kHeaderSize - kHeapObjectTag), ch); | |
2464 var_result.Bind(result); | |
2465 Goto(&return_result); | |
2466 } | |
2467 | |
2468 Bind(&if_stringistwobyte); | |
2469 { | |
2470 Node* lead = Load(MachineType::Uint16(), string, | |
2471 IntPtrAdd(WordShl(index, IntPtrConstant(1)), | |
2472 IntPtrConstant(SeqTwoByteString::kHeaderSize - | |
2473 kHeapObjectTag))); | |
2474 Node* next_pos = Int32Add(index, Int32Constant(1)); | |
2475 | |
2476 Label if_issinglecodeunit(this), if_isdoublecodeunit(this); | |
2477 GotoIf(Int32GreaterThanOrEqual(next_pos, length), &if_issinglecodeunit); | |
2478 GotoIf(Int32LessThan(lead, Int32Constant(0xD800)), &if_issinglecodeunit); | |
2479 BranchIf(Int32LessThan(lead, Int32Constant(0xDC00)), &if_isdoublecodeunit, | |
2480 &if_issinglecodeunit); | |
2481 | |
2482 Bind(&if_isdoublecodeunit); | |
2483 { | |
2484 Node* trail = | |
2485 Load(MachineType::Uint16(), string, | |
2486 IntPtrAdd(WordShl(next_pos, IntPtrConstant(1)), | |
2487 IntPtrConstant(SeqTwoByteString::kHeaderSize - | |
2488 kHeapObjectTag))); | |
2489 GotoIf(Int32LessThan(trail, Int32Constant(0xDC00)), | |
2490 &if_issinglecodeunit); | |
2491 GotoIf(Int32GreaterThan(trail, Int32Constant(0xDFFF)), | |
2492 &if_issinglecodeunit); | |
2493 | |
2494 Node* result = AllocateSeqTwoByteString(2); | |
2495 #if defined(V8_TARGET_LITTLE_ENDIAN) | |
2496 Node* ch = Word32Or(WordShl(trail, Int32Constant(16)), lead); | |
2497 #else | |
2498 Node* ch = Word32Or(WordShl(lead, Int32Constant(16)), trail); | |
2499 #endif | |
2500 StoreNoWriteBarrier( | |
2501 MachineRepresentation::kWord32, result, | |
2502 IntPtrConstant(SeqTwoByteString::kHeaderSize - kHeapObjectTag), ch); | |
2503 var_result.Bind(result); | |
2504 Goto(&return_result); | |
2505 } | |
2506 | |
2507 Bind(&if_issinglecodeunit); | |
2508 { | |
2509 Node* result = AllocateSeqTwoByteString(1); | |
2510 StoreNoWriteBarrier( | |
2511 MachineRepresentation::kWord16, result, | |
2512 IntPtrConstant(SeqOneByteString::kHeaderSize - kHeapObjectTag), | |
2513 lead); | |
2514 var_result.Bind(result); | |
2515 Goto(&return_result); | |
2516 } | |
2517 } | |
2518 } | |
2519 | |
2520 Bind(&if_stringisexternal); | |
2521 { | |
2522 Assert(Word32Equal(Word32And(string_instance_type, | |
2523 Int32Constant(kStringRepresentationMask)), | |
2524 Int32Constant(kExternalStringTag))); | |
2525 Label if_stringisshort(this), if_stringisnotshort(this); | |
2526 | |
2527 Branch(Word32Equal(Word32And(string_instance_type, | |
2528 Int32Constant(kShortExternalStringMask)), | |
2529 Int32Constant(0)), | |
2530 &if_stringisshort, &if_stringisnotshort); | |
2531 | |
2532 Bind(&if_stringisshort); | |
2533 { | |
2534 // Load the actual resource data from the {string}. | |
2535 Node* string_resource_data = LoadObjectField( | |
2536 string, ExternalString::kResourceDataOffset, MachineType::Pointer()); | |
2537 | |
2538 Label if_stringistwobyte(this), if_stringisonebyte(this); | |
2539 Branch(Word32Equal(Word32And(string_instance_type, | |
2540 Int32Constant(kStringEncodingMask)), | |
2541 Int32Constant(kTwoByteStringTag)), | |
2542 &if_stringistwobyte, &if_stringisonebyte); | |
2543 | |
2544 Bind(&if_stringisonebyte); | |
2545 { | |
2546 Node* ch = Load(MachineType::Uint8(), string_resource_data, index); | |
2547 Node* result = AllocateSeqOneByteString(1); | |
2548 StoreNoWriteBarrier( | |
2549 MachineRepresentation::kWord8, result, | |
2550 IntPtrConstant(SeqOneByteString::kHeaderSize - kHeapObjectTag), ch); | |
2551 var_result.Bind(result); | |
2552 Goto(&return_result); | |
2553 } | |
2554 | |
2555 Bind(&if_stringistwobyte); | |
2556 { | |
2557 Label if_issinglecodeunit(this), if_isdoublecodeunit(this); | |
2558 Node* lead = Load(MachineType::Uint16(), string_resource_data, | |
2559 WordShl(index, IntPtrConstant(1))); | |
2560 Node* next_pos = Int32Add(index, Int32Constant(1)); | |
2561 | |
2562 GotoIf(Int32GreaterThanOrEqual(next_pos, length), &if_issinglecodeunit); | |
2563 GotoIf(Int32LessThan(lead, Int32Constant(0xD800)), | |
2564 &if_issinglecodeunit); | |
2565 Branch(Int32LessThan(lead, Int32Constant(0xDC00)), &if_isdoublecodeunit, | |
2566 &if_issinglecodeunit); | |
2567 | |
2568 Bind(&if_isdoublecodeunit); | |
2569 { | |
2570 Node* trail = | |
2571 Load(MachineType::Uint16(), string, | |
2572 IntPtrAdd(WordShl(next_pos, IntPtrConstant(1)), | |
2573 IntPtrConstant(SeqTwoByteString::kHeaderSize - | |
2574 kHeapObjectTag))); | |
2575 GotoIf(Int32LessThan(trail, Int32Constant(0xDC00)), | |
2576 &if_issinglecodeunit); | |
2577 GotoIf(Int32GreaterThan(trail, Int32Constant(0xDFFF)), | |
2578 &if_issinglecodeunit); | |
2579 | |
2580 Node* result = AllocateSeqTwoByteString(2); | |
2581 #if defined(V8_TARGET_LITTLE_ENDIAN) | |
2582 Node* ch = Word32Or(WordShl(trail, Int32Constant(16)), lead); | |
2583 #else | |
2584 Node* ch = Word32Or(WordShl(lead, Int32Constant(16)), trail); | |
2585 #endif | |
2586 StoreNoWriteBarrier( | |
2587 MachineRepresentation::kWord32, result, | |
2588 IntPtrConstant(SeqTwoByteString::kHeaderSize - kHeapObjectTag), | |
2589 ch); | |
2590 var_result.Bind(result); | |
2591 Goto(&return_result); | |
2592 } | |
2593 | |
2594 Bind(&if_issinglecodeunit); | |
2595 { | |
2596 Node* result = AllocateSeqTwoByteString(1); | |
2597 StoreNoWriteBarrier( | |
2598 MachineRepresentation::kWord16, result, | |
2599 IntPtrConstant(SeqOneByteString::kHeaderSize - kHeapObjectTag), | |
2600 lead); | |
2601 var_result.Bind(result); | |
2602 Goto(&return_result); | |
2603 } | |
2604 } | |
2605 } | |
2606 | |
2607 Bind(&if_stringisnotshort); | |
2608 { | |
2609 Label if_issinglecodeunit(this), if_isdoublecodeunit(this); | |
2610 Node* lead = | |
2611 SmiToWord32(CallRuntime(Runtime::kExternalStringGetChar, | |
2612 NoContextConstant(), string, SmiTag(index))); | |
2613 Node* next_pos = Int32Add(index, Int32Constant(1)); | |
2614 | |
2615 GotoIf(Int32GreaterThanOrEqual(next_pos, length), &if_issinglecodeunit); | |
2616 GotoIf(Int32LessThan(lead, Int32Constant(0xD800)), &if_issinglecodeunit); | |
2617 Branch(Int32GreaterThan(lead, Int32Constant(0xDBFF)), | |
2618 &if_issinglecodeunit, &if_isdoublecodeunit); | |
2619 | |
2620 Bind(&if_isdoublecodeunit); | |
2621 { | |
2622 Node* trail = SmiToWord32(CallRuntime(Runtime::kExternalStringGetChar, | |
2623 NoContextConstant(), string, | |
2624 SmiTag(next_pos))); | |
2625 GotoIf(Int32LessThan(trail, Int32Constant(0xDC00)), | |
2626 &if_issinglecodeunit); | |
2627 GotoIf(Int32GreaterThan(trail, Int32Constant(0xDFFF)), | |
2628 &if_issinglecodeunit); | |
2629 Node* result = AllocateSeqTwoByteString(2); | |
2630 #if defined(V8_TARGET_LITTLE_ENDIAN) | |
2631 Node* ch = Word32Or(WordShl(trail, Int32Constant(16)), lead); | |
2632 #else | |
2633 Node* ch = Word32Or(WordShl(lead, Int32Constant(16)), trail); | |
2634 #endif | |
2635 StoreNoWriteBarrier( | |
2636 MachineRepresentation::kWord32, result, | |
2637 IntPtrConstant(SeqTwoByteString::kHeaderSize - kHeapObjectTag), ch); | |
2638 var_result.Bind(result); | |
2639 Goto(&return_result); | |
2640 } | |
2641 | |
2642 Bind(&if_issinglecodeunit); | |
2643 { | |
2644 Label if_isonebyte(this), if_istwobyte(this); | |
2645 Branch(Int32LessThan(lead, Int32Constant(0x100)), &if_isonebyte, | |
2646 &if_istwobyte); | |
2647 | |
2648 Bind(&if_isonebyte); | |
2649 { | |
2650 Node* result = AllocateSeqOneByteString(1); | |
2651 StoreNoWriteBarrier( | |
2652 MachineRepresentation::kWord8, result, | |
2653 IntPtrConstant(SeqOneByteString::kHeaderSize - kHeapObjectTag), | |
2654 lead); | |
2655 var_result.Bind(result); | |
2656 Goto(&return_result); | |
2657 } | |
2658 | |
2659 Bind(&if_istwobyte); | |
2660 { | |
2661 Node* result = AllocateSeqTwoByteString(1); | |
2662 StoreNoWriteBarrier( | |
2663 MachineRepresentation::kWord8, result, | |
2664 IntPtrConstant(SeqTwoByteString::kHeaderSize - kHeapObjectTag), | |
2665 lead); | |
2666 var_result.Bind(result); | |
2667 Goto(&return_result); | |
2668 } | |
2669 } | |
2670 } | |
2671 } | |
2672 | |
2673 Bind(&return_result); | |
2674 return var_result.value(); | |
2675 } | |
2676 | |
2432 Node* CodeStubAssembler::StringToNumber(Node* context, Node* input) { | 2677 Node* CodeStubAssembler::StringToNumber(Node* context, Node* input) { |
2433 Label runtime(this, Label::kDeferred); | 2678 Label runtime(this, Label::kDeferred); |
2434 Label end(this); | 2679 Label end(this); |
2435 | 2680 |
2436 Variable var_result(this, MachineRepresentation::kTagged); | 2681 Variable var_result(this, MachineRepresentation::kTagged); |
2437 | 2682 |
2438 // Check if string has a cached array index. | 2683 // Check if string has a cached array index. |
2439 Node* hash = LoadNameHashField(input); | 2684 Node* hash = LoadNameHashField(input); |
2440 Node* bit = | 2685 Node* bit = |
2441 Word32And(hash, Int32Constant(String::kContainsCachedArrayIndexMask)); | 2686 Word32And(hash, Int32Constant(String::kContainsCachedArrayIndexMask)); |
(...skipping 2732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5174 Heap::kTheHoleValueRootIndex); | 5419 Heap::kTheHoleValueRootIndex); |
5175 | 5420 |
5176 // Store the WeakCell in the feedback vector. | 5421 // Store the WeakCell in the feedback vector. |
5177 StoreFixedArrayElement(feedback_vector, slot, cell, UPDATE_WRITE_BARRIER, | 5422 StoreFixedArrayElement(feedback_vector, slot, cell, UPDATE_WRITE_BARRIER, |
5178 CodeStubAssembler::SMI_PARAMETERS); | 5423 CodeStubAssembler::SMI_PARAMETERS); |
5179 return cell; | 5424 return cell; |
5180 } | 5425 } |
5181 | 5426 |
5182 } // namespace internal | 5427 } // namespace internal |
5183 } // namespace v8 | 5428 } // namespace v8 |
OLD | NEW |